diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-04-22 23:28:39 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2025-05-13 13:54:20 +0200 |
| commit | 365acf9b49139cbdc2afbda524f5fc4f863a726f (patch) | |
| tree | 6c4fa73c3fd7a7be6a9202aaf2216c78fc6ae9a0 /android/app/src/test | |
| parent | d36f215dd5170e50cb2c668fc9c42ae7ecaeac2c (diff) | |
| download | mullvadvpn-365acf9b49139cbdc2afbda524f5fc4f863a726f.tar.xz mullvadvpn-365acf9b49139cbdc2afbda524f5fc4f863a726f.zip | |
Remove the 2 character limit in search locations
Also fixes back behavior in custom list locations
Diffstat (limited to 'android/app/src/test')
5 files changed, 65 insertions, 63 deletions
diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt index 865b4ce471..edb4a9adfe 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/CustomListLocationsViewModelTest.kt @@ -13,6 +13,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListAction import net.mullvad.mullvadvpn.compose.communication.CustomListActionResultData import net.mullvad.mullvadvpn.compose.communication.LocationsChanged import net.mullvad.mullvadvpn.compose.screen.CustomListLocationsNavArgs +import net.mullvad.mullvadvpn.compose.state.CustomListLocationsData import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState import net.mullvad.mullvadvpn.compose.state.RelayLocationListItem import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule @@ -29,6 +30,7 @@ import net.mullvad.mullvadvpn.relaylist.withDescendants import net.mullvad.mullvadvpn.repository.RelayListRepository import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListRelayItemsUseCase +import net.mullvad.mullvadvpn.util.Lce import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -59,10 +61,14 @@ class CustomListLocationsViewModelTest { name = CustomListName.fromString("name"), locations = emptyList(), ) + relayListFlow.value = DUMMY_COUNTRIES val viewModel = createViewModel(customListId = customList.id, newList = newList) // Act, Assert - viewModel.uiState.test { assertEquals(newList, awaitItem().newList) } + viewModel.uiState.test { + val state = awaitItem() + assertEquals(newList, state.newList) + } } @Test @@ -80,7 +86,17 @@ class CustomListLocationsViewModelTest { } val customListId = CustomListId("id") val expectedState = - CustomListLocationsUiState.Content.Data(newList = true, locations = expectedList) + CustomListLocationsUiState( + newList = true, + Lce.Content( + CustomListLocationsData( + saveEnabled = false, + hasUnsavedChanges = false, + searchTerm = "", + locations = expectedList, + ) + ), + ) val viewModel = createViewModel(customListId, true) relayListFlow.value = DUMMY_COUNTRIES @@ -102,8 +118,8 @@ class CustomListLocationsViewModelTest { viewModel.uiState.test { // Check no selected val firstState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(firstState) - assertEquals(emptyList<RelayItem>(), firstState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(firstState.content) + assertEquals(emptyList<RelayItem>(), firstState.content.selectedLocations()) // Expand country viewModel.onExpand(DUMMY_COUNTRIES[0], true) awaitItem() @@ -114,8 +130,8 @@ class CustomListLocationsViewModelTest { viewModel.onRelaySelectionClick(DUMMY_COUNTRIES[0], true) // Check all items selected val secondState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(secondState) - assertLists(expectedSelection, secondState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(secondState.content) + assertLists(expectedSelection, secondState.content.selectedLocations()) } } @@ -133,21 +149,15 @@ class CustomListLocationsViewModelTest { // Act, Assert viewModel.uiState.test { - awaitItem() - // Expand country - viewModel.onExpand(DUMMY_COUNTRIES[0], true) - awaitItem() - // Expand city - viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true) // Check initial selected val firstState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(firstState) - assertEquals(initialSelectionIds, firstState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(firstState.content) + assertEquals(initialSelectionIds, firstState.content.selectedLocations()) viewModel.onRelaySelectionClick(DUMMY_COUNTRIES[0].cities[0].relays[0], false) // Check all items selected val secondState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(secondState) - assertEquals(expectedSelection, secondState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(secondState.content) + assertEquals(expectedSelection, secondState.content.selectedLocations()) } } @@ -166,21 +176,14 @@ class CustomListLocationsViewModelTest { // Act, Assert viewModel.uiState.test { - awaitItem() - // Expand country - viewModel.onExpand(DUMMY_COUNTRIES[0], true) - awaitItem() - // Expand city - viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true) - // Check initial selected val firstState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(firstState) - assertEquals(initialSelectionIds, firstState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(firstState.content) + assertEquals(initialSelectionIds, firstState.content.selectedLocations()) viewModel.onRelaySelectionClick(DUMMY_COUNTRIES[0], false) // Check all items selected val secondState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(secondState) - assertEquals(expectedSelection, secondState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(secondState.content) + assertEquals(expectedSelection, secondState.content.selectedLocations()) } } @@ -203,13 +206,13 @@ class CustomListLocationsViewModelTest { viewModel.onExpand(DUMMY_COUNTRIES[0].cities[0], true) // Check no selected val firstState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(firstState) - assertEquals(emptyList<RelayItem>(), firstState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(firstState.content) + assertEquals(emptyList<RelayItem>(), firstState.content.selectedLocations()) viewModel.onRelaySelectionClick(DUMMY_COUNTRIES[0].cities[0].relays[0], true) // Check all items selected val secondState = awaitItem() - assertIs<CustomListLocationsUiState.Content.Data>(secondState) - assertEquals(expectedSelection, secondState.selectedLocations()) + assertIs<Lce.Content<CustomListLocationsData>>(secondState.content) + assertEquals(expectedSelection, secondState.content.selectedLocations()) } } @@ -323,8 +326,8 @@ class CustomListLocationsViewModelTest { ) } - private fun CustomListLocationsUiState.Content.Data.selectedLocations() = - this.locations.filter { it.checked }.map { it.item.id } + private fun Lce.Content<CustomListLocationsData>.selectedLocations() = + this.value.locations.filter { it.checked }.map { it.item.id } private fun RelayItem.Location.toDepth() = when (this) { diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ManageDevicesViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ManageDevicesViewModelTest.kt index ac5446cc07..7f4c6fe690 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ManageDevicesViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/ManageDevicesViewModelTest.kt @@ -78,7 +78,7 @@ class ManageDevicesViewModelTest { @Test fun `initial state should be Loading followed by Content`() = runTest { // Initial state is Loading - assertIs<Lce.Loading>(viewModel.uiState.value) + assertIs<Lce.Loading<Unit>>(viewModel.uiState.value) viewModel.uiState.test { val contentState = awaitItem() diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt index f9c4cace6a..0166bafa98 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SearchLocationViewModelTest.kt @@ -29,6 +29,7 @@ import net.mullvad.mullvadvpn.usecase.SelectedLocationUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListsRelayItemUseCase import net.mullvad.mullvadvpn.usecase.customlists.FilterCustomListsRelayItemUseCase +import net.mullvad.mullvadvpn.util.Lce import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test @@ -96,20 +97,17 @@ class SearchLocationViewModelTest { // Act, Assert viewModel.uiState.test { // Wait for first data - assertIs<SearchLocationUiState.NoQuery>(awaitItem()) + awaitItem() // Update search string viewModel.onSearchInputUpdated(mockSearchString) - // We get some unnecessary emissions for now - awaitItem() - val actualState = awaitItem() - assertIs<SearchLocationUiState.Content>(actualState) + assertIs<Lce.Content<SearchLocationUiState>>(actualState) assertTrue( - actualState.relayListItems.filterIsInstance<RelayListItem.GeoLocationItem>().any { - it.item is RelayItem.Location.City && it.item.name == "Gothenburg" - } + actualState.value.relayListItems + .filterIsInstance<RelayListItem.GeoLocationItem>() + .any { it.item is RelayItem.Location.City && it.item.name == "Gothenburg" } ) } } @@ -123,20 +121,17 @@ class SearchLocationViewModelTest { // Act, Assert viewModel.uiState.test { // Wait for first data - assertIs<SearchLocationUiState.NoQuery>(awaitItem()) + awaitItem() // Update search string viewModel.onSearchInputUpdated(mockSearchString) - // We get some unnecessary emissions for now - awaitItem() - // Assert val actualState = awaitItem() - assertIs<SearchLocationUiState.Content>(actualState) + assertIs<Lce.Content<SearchLocationUiState>>(actualState) assertLists( listOf(RelayListItem.LocationsEmptyText(mockSearchString)), - actualState.relayListItems, + actualState.value.relayListItems, ) } } diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt index acdf3f5c95..46994ead49 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationListViewModelTest.kt @@ -23,6 +23,7 @@ import net.mullvad.mullvadvpn.usecase.FilteredRelayListUseCase import net.mullvad.mullvadvpn.usecase.SelectedLocationUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListsRelayItemUseCase import net.mullvad.mullvadvpn.usecase.customlists.FilterCustomListsRelayItemUseCase +import net.mullvad.mullvadvpn.util.Lce import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.BeforeEach @@ -70,7 +71,7 @@ class SelectLocationListViewModelTest { viewModel = createSelectLocationListViewModel(relayListType = RelayListType.ENTRY) // Assert - assertEquals(SelectLocationListUiState.Loading, viewModel.uiState.value) + assertEquals(Lce.Loading(Unit), viewModel.uiState.value) } @Test @@ -84,13 +85,13 @@ class SelectLocationListViewModelTest { // Act, Assert viewModel.uiState.test { val actualState = awaitItem() - assertIs<SelectLocationListUiState.Content>(actualState) + assertIs<Lce.Content<SelectLocationListUiState>>(actualState) assertLists( testCountries.map { it.id }, - actualState.relayListItems.mapNotNull { it.relayItemId() }, + actualState.value.relayListItems.mapNotNull { it.relayItemId() }, ) assertTrue( - actualState.relayListItems + actualState.value.relayListItems .filterIsInstance<RelayListItem.SelectableItem>() .first { it.relayItemId() == selectedId } .isSelected @@ -108,15 +109,15 @@ class SelectLocationListViewModelTest { // Act, Assert viewModel.uiState.test { val actualState = awaitItem() - assertIs<SelectLocationListUiState.Content>(actualState) + assertIs<Lce.Content<SelectLocationListUiState>>(actualState) assertLists( testCountries.map { it.id }, - actualState.relayListItems.mapNotNull { it.relayItemId() }, + actualState.value.relayListItems.mapNotNull { it.relayItemId() }, ) assertTrue( - actualState.relayListItems.filterIsInstance<RelayListItem.SelectableItem>().all { - !it.isSelected - } + actualState.value.relayListItems + .filterIsInstance<RelayListItem.SelectableItem>() + .all { !it.isSelected } ) } } @@ -139,6 +140,7 @@ class SelectLocationListViewModelTest { RelayListItem.CustomListHeader -> null RelayListItem.LocationHeader -> null is RelayListItem.LocationsEmptyText -> null + is RelayListItem.EmptyRelayList -> null is RelayListItem.CustomListEntryItem -> item.id is RelayListItem.CustomListItem -> item.id is RelayListItem.GeoLocationItem -> item.id diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt index c79d158f82..a7ecbe17f9 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/location/SelectLocationViewModelTest.kt @@ -38,8 +38,8 @@ import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository import net.mullvad.mullvadvpn.usecase.FilterChip import net.mullvad.mullvadvpn.usecase.FilterChipUseCase import net.mullvad.mullvadvpn.usecase.customlists.CustomListActionUseCase +import net.mullvad.mullvadvpn.util.Lc import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith @@ -59,6 +59,7 @@ class SelectLocationViewModelTest { private val selectedRelayItemFlow = MutableStateFlow<Constraint<RelayItemId>>(Constraint.Any) private val wireguardConstraints = MutableStateFlow<WireguardConstraints>(mockk(relaxed = true)) private val filterChips = MutableStateFlow<List<FilterChip>>(emptyList()) + private val relayList = MutableStateFlow<List<RelayItem.Location.Country>>(emptyList()) @BeforeEach fun setup() { @@ -67,6 +68,7 @@ class SelectLocationViewModelTest { every { mockWireguardConstraintsRepository.wireguardConstraints } returns wireguardConstraints every { mockFilterChipUseCase(any()) } returns filterChips + every { mockRelayListRepository.relayList } returns relayList mockkStatic(RELAY_LIST_EXTENSIONS) mockkStatic(RELAY_ITEM_EXTENSIONS) @@ -90,7 +92,7 @@ class SelectLocationViewModelTest { @Test fun `initial state should be correct`() = runTest { - Assertions.assertEquals(SelectLocationUiState.Loading, viewModel.uiState.value) + assertIs<Lc.Loading<Unit>>(viewModel.uiState.value) } @Test @@ -128,14 +130,14 @@ class SelectLocationViewModelTest { viewModel.selectRelayList(RelayListType.ENTRY) // Assert relay list type is entry val firstState = awaitItem() - assertIs<SelectLocationUiState.Data>(firstState) - assertEquals(RelayListType.ENTRY, firstState.relayListType) + assertIs<Lc.Content<SelectLocationUiState>>(firstState) + assertEquals(RelayListType.ENTRY, firstState.value.relayListType) // Select entry viewModel.selectRelay(mockRelayItem) // Assert relay list type is exit val secondState = awaitItem() - assertIs<SelectLocationUiState.Data>(secondState) - assertEquals(RelayListType.EXIT, secondState.relayListType) + assertIs<Lc.Content<SelectLocationUiState>>(secondState) + assertEquals(RelayListType.EXIT, secondState.value.relayListType) coVerify { mockWireguardConstraintsRepository.setEntryLocation(relayItemId) } } } |
