From fea0ea1dfe744cda07f413019674cb4e4254feb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?David=20G=C3=B6ransson?= Date: Thu, 25 Jul 2024 10:30:03 +0200 Subject: [PATCH] Fix select location screen test --- .../screen/CustomListLocationsScreenTest.kt | 12 +- .../screen/SelectLocationScreenTest.kt | 125 +++++------------- .../compose/state/SelectLocationUiState.kt | 10 +- 3 files changed, 44 insertions(+), 103 deletions(-) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt index 4f4db0a529b6..e7e490c09a08 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/CustomListLocationsScreenTest.kt @@ -80,8 +80,7 @@ class CustomListLocationsScreenTest { CustomListLocationsScreen( state = CustomListLocationsUiState.Content.Data( - availableLocations = DUMMY_RELAY_COUNTRIES, - selectedLocations = emptySet(), + locations = emptyList(), searchTerm = "" ), ) @@ -107,8 +106,7 @@ class CustomListLocationsScreenTest { state = CustomListLocationsUiState.Content.Data( newList = false, - availableLocations = DUMMY_RELAY_COUNTRIES, - selectedLocations = setOf(selectedCountry) + locations = emptyList() ), onRelaySelectionClick = mockedOnRelaySelectionClicked ) @@ -131,7 +129,7 @@ class CustomListLocationsScreenTest { state = CustomListLocationsUiState.Content.Data( newList = false, - availableLocations = DUMMY_RELAY_COUNTRIES, + locations = emptyList(), ), onSearchTermInput = mockedSearchTermInput ) @@ -197,7 +195,7 @@ class CustomListLocationsScreenTest { state = CustomListLocationsUiState.Content.Data( newList = false, - availableLocations = DUMMY_RELAY_COUNTRIES, + locations = emptyList(), saveEnabled = true, ), onSaveClick = mockOnSaveClick @@ -221,7 +219,7 @@ class CustomListLocationsScreenTest { state = CustomListLocationsUiState.Content.Data( newList = false, - availableLocations = DUMMY_RELAY_COUNTRIES, + locations = emptyList(), saveEnabled = false, ), onSaveClick = mockOnSaveClick diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt index 4fcee479d612..4f3bac57e266 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt @@ -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 @@ -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 = "" ), ) } @@ -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 { @@ -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 ) @@ -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 ) @@ -170,7 +127,7 @@ class SelectLocationScreenTest { } @Test - fun givenNoCustomListsAndSearchIsTermIsEmptyShouldShowCustomListsEmptyText() = + fun customListFooterShouldShowEmptyTextWhenNoCustomList() = composeExtension.use { // Arrange val mockSearchString = "" @@ -178,13 +135,10 @@ class SelectLocationScreenTest { 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 ), ) } @@ -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 ), ) } @@ -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 ) @@ -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 ) @@ -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 ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt index 878661d82c53..5d6b683116e0 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/state/SelectLocationUiState.kt @@ -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 @@ -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