diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt index a154344f2673..cf3380e97a42 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/location/SelectLocationScreenTest.kt @@ -64,7 +64,7 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( state = - SelectLocationUiState( + SelectLocationUiState.Data( // searchTerm = "", filterChips = emptyList(), multihopEnabled = false, @@ -96,7 +96,7 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( state = - SelectLocationUiState( + SelectLocationUiState.Data( filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, @@ -124,7 +124,7 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( state = - SelectLocationUiState( + SelectLocationUiState.Data( filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, @@ -156,7 +156,7 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( state = - SelectLocationUiState( + SelectLocationUiState.Data( // searchTerm = "", filterChips = emptyList(), multihopEnabled = false, @@ -189,7 +189,7 @@ class SelectLocationScreenTest { setContentWithTheme { SelectLocationScreen( state = - SelectLocationUiState( + SelectLocationUiState.Data( filterChips = emptyList(), multihopEnabled = false, relayListType = RelayListType.EXIT, 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 ef21eac13945..77a5e948ebe1 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 @@ -34,6 +34,7 @@ import net.mullvad.mullvadvpn.relaylist.descendants import net.mullvad.mullvadvpn.repository.CustomListsRepository import net.mullvad.mullvadvpn.repository.RelayListFilterRepository import net.mullvad.mullvadvpn.repository.RelayListRepository +import net.mullvad.mullvadvpn.repository.SettingsRepository import net.mullvad.mullvadvpn.repository.WireguardConstraintsRepository import net.mullvad.mullvadvpn.usecase.FilterChip import net.mullvad.mullvadvpn.usecase.FilterChipUseCase @@ -53,6 +54,7 @@ class SelectLocationViewModelTest { private val mockCustomListsRepository: CustomListsRepository = mockk() private val mockWireguardConstraintsRepository: WireguardConstraintsRepository = mockk() private val mockFilterChipUseCase: FilterChipUseCase = mockk() + private val mocksSettingsRepository: SettingsRepository = mockk() private lateinit var viewModel: SelectLocationViewModel @@ -67,6 +69,7 @@ class SelectLocationViewModelTest { every { mockWireguardConstraintsRepository.wireguardConstraints } returns wireguardConstraints every { mockFilterChipUseCase(any()) } returns filterChips + every { mocksSettingsRepository.settingsUpdates } returns MutableStateFlow(null) mockkStatic(RELAY_LIST_EXTENSIONS) mockkStatic(RELAY_ITEM_EXTENSIONS) @@ -79,6 +82,7 @@ class SelectLocationViewModelTest { customListsRepository = mockCustomListsRepository, filterChipUseCase = mockFilterChipUseCase, wireguardConstraintsRepository = mockWireguardConstraintsRepository, + settingsRepository = mocksSettingsRepository, ) } @@ -90,14 +94,7 @@ class SelectLocationViewModelTest { @Test fun `initial state should be correct`() = runTest { - Assertions.assertEquals( - SelectLocationUiState( - filterChips = emptyList(), - multihopEnabled = false, - relayListType = RelayListType.EXIT, - ), - viewModel.uiState.value, - ) + Assertions.assertEquals(SelectLocationUiState.Loading, viewModel.uiState.value) } @Test @@ -134,11 +131,15 @@ class SelectLocationViewModelTest { awaitItem() // Default value viewModel.selectRelayList(RelayListType.ENTRY) // Assert relay list type is entry - assertEquals(RelayListType.ENTRY, awaitItem().relayListType) + val firstState = awaitItem() + assertIs(firstState) + assertEquals(RelayListType.ENTRY, firstState.relayListType) // Select entry viewModel.selectRelay(mockRelayItem) - // Await an empty item - assertEquals(RelayListType.EXIT, awaitItem().relayListType) + // Assert relay list type is exit + val secondState = awaitItem() + assertIs(secondState) + assertEquals(RelayListType.EXIT, secondState.relayListType) coVerify { mockWireguardConstraintsRepository.setEntryLocation(relayItemId) } } }