Skip to content

Commit

Permalink
Adapt tests to flat list uiState
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jul 25, 2024
1 parent 06b410a commit 0a3a549
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 181 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_COUNTRIES
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState
import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.SAVE_BUTTON_TEST_TAG
import net.mullvad.mullvadvpn.lib.model.RelayItem
Expand Down Expand Up @@ -80,20 +81,22 @@ class CustomListLocationsScreenTest {
CustomListLocationsScreen(
state =
CustomListLocationsUiState.Content.Data(
availableLocations = DUMMY_RELAY_COUNTRIES,
selectedLocations = emptySet(),
locations =
listOf(
RelayLocationListItem(DUMMY_RELAY_COUNTRIES[0], checked = true),
RelayLocationListItem(
DUMMY_RELAY_COUNTRIES[1],
checked = false
),
),
searchTerm = ""
),
)
}

// Assert
onNodeWithText("Relay Country 1").assertExists()
onNodeWithText("Relay City 1").assertDoesNotExist()
onNodeWithText("Relay host 1").assertDoesNotExist()
onNodeWithText("Relay Country 2").assertExists()
onNodeWithText("Relay City 2").assertDoesNotExist()
onNodeWithText("Relay host 2").assertDoesNotExist()
}

@Test
Expand All @@ -107,8 +110,8 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
selectedLocations = setOf(selectedCountry)
locations =
listOf(RelayLocationListItem(selectedCountry, checked = true))
),
onRelaySelectionClick = mockedOnRelaySelectionClicked
)
Expand All @@ -131,7 +134,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
locations = emptyList(),
),
onSearchTermInput = mockedSearchTermInput
)
Expand Down Expand Up @@ -197,7 +200,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
locations = emptyList(),
saveEnabled = true,
),
onSaveClick = mockOnSaveClick
Expand All @@ -221,7 +224,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
locations = emptyList(),
saveEnabled = false,
),
onSaveClick = mockOnSaveClick
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.createEdgeToEdgeComposeExtension
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_COUNTRIES
import net.mullvad.mullvadvpn.compose.data.DUMMY_RELAY_ITEM_CUSTOM_LISTS
import net.mullvad.mullvadvpn.compose.setContentWithTheme
import net.mullvad.mullvadvpn.compose.state.RelayListItem
import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState
import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR
import net.mullvad.mullvadvpn.compose.test.SELECT_LOCATION_CUSTOM_LIST_BOTTOM_SHEET_TEST_TAG
Expand Down Expand Up @@ -54,13 +55,13 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
searchTerm = "",
filterChips = emptyList(),
relayListItems =
DUMMY_RELAY_COUNTRIES.map {
RelayListItem.GeoLocationItem(item = it)
},
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = DUMMY_RELAY_COUNTRIES,
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
),
)
}
Expand All @@ -74,45 +75,6 @@ class SelectLocationScreenTest {
onNodeWithText("Relay host 2").assertDoesNotExist()
}

@Test
fun testShowRelayListStateSelected() =
composeExtension.use {
val updatedDummyList =
DUMMY_RELAY_COUNTRIES.let {
val cities = it[0].cities.toMutableList()
val city = cities.removeAt(0)
cities.add(0, city.copy(expanded = true))

val mutableRelayList = it.toMutableList()
mutableRelayList[0] = it[0].copy(expanded = true, cities = cities.toList())
mutableRelayList
}

// Arrange
setContentWithTheme {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = updatedDummyList,
selectedItem = updatedDummyList[0].cities[0].relays[0].id,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
),
)
}

// Assert
onNodeWithText("Relay Country 1").assertExists()
onNodeWithText("Relay City 1").assertExists()
onNodeWithText("Relay host 1").assertExists()
onNodeWithText("Relay Country 2").assertExists()
onNodeWithText("Relay City 2").assertDoesNotExist()
onNodeWithText("Relay host 2").assertDoesNotExist()
}

@Test
fun testSearchInput() =
composeExtension.use {
Expand All @@ -122,13 +84,10 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
searchTerm = "",
filterChips = emptyList(),
relayListItems = emptyList(),
customLists = emptyList()
),
onSearchTermInput = mockedSearchTermInput
)
Expand All @@ -152,13 +111,11 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
searchTerm = mockSearchString,
filterChips = emptyList(),
relayListItems =
listOf(RelayListItem.LocationsEmptyText(mockSearchString)),
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = mockSearchString
),
onSearchTermInput = mockedSearchTermInput
)
Expand All @@ -170,21 +127,18 @@ class SelectLocationScreenTest {
}

@Test
fun givenNoCustomListsAndSearchIsTermIsEmptyShouldShowCustomListsEmptyText() =
fun customListFooterShouldShowEmptyTextWhenNoCustomList() =
composeExtension.use {
// Arrange
val mockSearchString = ""
setContentWithTheme {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
searchTerm = mockSearchString,
filterChips = emptyList(),
relayListItems = listOf(RelayListItem.CustomListFooter(false)),
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = mockSearchString
),
)
}
Expand All @@ -202,13 +156,10 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
searchTerm = mockSearchString,
filterChips = emptyList(),
relayListItems = emptyList(),
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
filteredCustomLists = emptyList(),
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = mockSearchString
),
)
}
Expand All @@ -228,13 +179,10 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
filteredCustomLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
searchTerm = "",
filterChips = emptyList(),
relayListItems = listOf(RelayListItem.CustomListItem(customList)),
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS
),
onSelectRelay = mockedOnSelectRelay
)
Expand All @@ -257,13 +205,11 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
filteredCustomLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS,
countries = emptyList(),
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
searchTerm = "",
filterChips = emptyList(),
relayListItems =
listOf(RelayListItem.CustomListItem(item = customList)),
customLists = DUMMY_RELAY_ITEM_CUSTOM_LISTS
),
onSelectRelay = mockedOnSelectRelay
)
Expand All @@ -286,13 +232,10 @@ class SelectLocationScreenTest {
SelectLocationScreen(
state =
SelectLocationUiState.Content(
searchTerm = "",
filterChips = emptyList(),
relayListItems = listOf(RelayListItem.GeoLocationItem(relayItem)),
customLists = emptyList(),
filteredCustomLists = emptyList(),
countries = DUMMY_RELAY_COUNTRIES,
selectedItem = null,
selectedOwnership = null,
selectedProvidersCount = 0,
searchTerm = ""
),
onSelectRelay = mockedOnSelectRelay
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ class CustomListActionUseCaseTest {
RelayItem.Location.Country(
id = locationId,
name = locationName,
expanded = false,
cities = emptyList()
)
)
Expand Down Expand Up @@ -151,7 +150,7 @@ class CustomListActionUseCaseTest {
val action = CustomListAction.Delete(id = customListId)
val expectedResult =
Deleted(undo = action.not(name = name, locations = listOf(location))).right()
every { mockLocation.countryCode } returns location.countryCode
every { mockLocation.code } returns location.code
coEvery { mockCustomListsRepository.deleteCustomList(id = customListId) } returns
Unit.right()
coEvery { mockCustomListsRepository.getCustomListById(customListId) } returns
Expand Down
Loading

0 comments on commit 0a3a549

Please sign in to comment.