Skip to content

Commit

Permalink
Fix select location screen test
Browse files Browse the repository at this point in the history
  • Loading branch information
Rawa committed Jul 25, 2024
1 parent 0c76106 commit fea0ea1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ class CustomListLocationsScreenTest {
CustomListLocationsScreen(
state =
CustomListLocationsUiState.Content.Data(
availableLocations = DUMMY_RELAY_COUNTRIES,
selectedLocations = emptySet(),
locations = emptyList(),
searchTerm = ""
),
)
Expand All @@ -107,8 +106,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
selectedLocations = setOf(selectedCountry)
locations = emptyList()
),
onRelaySelectionClick = mockedOnRelaySelectionClicked
)
Expand All @@ -131,7 +129,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
locations = emptyList(),
),
onSearchTermInput = mockedSearchTermInput
)
Expand Down Expand Up @@ -197,7 +195,7 @@ class CustomListLocationsScreenTest {
state =
CustomListLocationsUiState.Content.Data(
newList = false,
availableLocations = DUMMY_RELAY_COUNTRIES,
locations = emptyList(),
saveEnabled = true,
),
onSaveClick = mockOnSaveClick
Expand All @@ -221,7 +219,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 @@ -50,8 +50,8 @@ sealed interface RelayListItem {

data class CustomListItem(
val item: RelayItem.CustomList,
override val isSelected: Boolean,
override val expanded: Boolean,
override val isSelected: Boolean = false,
override val expanded: Boolean = false,
) : SelectableItem {
override val key = item.id
override val depth: Int = 0
Expand Down Expand Up @@ -83,9 +83,9 @@ sealed interface RelayListItem {

data class GeoLocationItem(
val item: RelayItem.Location,
override val isSelected: Boolean,
override val depth: Int,
override val expanded: Boolean,
override val isSelected: Boolean = false,
override val depth: Int = 0,
override val expanded: Boolean = false,
) : SelectableItem {
override val key = item.id
override val contentType = RelayListItemContentType.LOCATION_ITEM
Expand Down

0 comments on commit fea0ea1

Please sign in to comment.