From 5955a084c4664efdf7cf061bba5d55f0a1036ccd Mon Sep 17 00:00:00 2001 From: Jonatan Rhodin Date: Fri, 20 Dec 2024 13:15:10 +0100 Subject: [PATCH] Add tests for always showing selected providers --- .../compose/screen/FilterScreenTest.kt | 19 +++++++++++++++ .../usecase/FilterChipUseCaseTest.kt | 23 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/FilterScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/FilterScreenTest.kt index 85a23a75f68d..4b80ea0e3c2b 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/FilterScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/FilterScreenTest.kt @@ -137,6 +137,25 @@ class FilterScreenTest { verify { mockClickListener() } } + @Test + fun ensureSelectedProviderIsShowEvenThoughItIsNotInAllProviders() = + composeExtension.use { + // Arrange + initScreen( + state = + RelayFilterUiState( + providerToOwnerships = DUMMY_RELAY_ALL_PROVIDERS, + selectedOwnership = null, + selectedProviders = listOf(ProviderId("1RemovedProvider")), + ) + ) + + // Act + onNodeWithText("Providers").performClick() + // Asset + onNodeWithText("1RemovedProvider (removed)").assertExists() + } + companion object { private val DUMMY_RELAY_ALL_PROVIDERS = mapOf( diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCaseTest.kt index 98836ace5381..bd1a759b77e1 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/FilterChipUseCaseTest.kt @@ -184,4 +184,27 @@ class FilterChipUseCaseTest { filterChipUseCase(RelayListType.EXIT).test { assertLists(emptyList(), awaitItem()) } } + + @Test + fun `ensure that a selected provider that is not in the provider list is still counted`() = + runTest { + // Arrange + val expectedProviders = Providers(providers = setOf(ProviderId("1"))) + val expectedOwnership = Ownership.MullvadOwned + selectedProviders.value = Constraint.Only(expectedProviders) + selectedOwnership.value = Constraint.Only(expectedOwnership) + providerToOwnerships.value = + mapOf( + ProviderId("2") to setOf(Ownership.MullvadOwned), + ProviderId("3") to setOf(Ownership.Rented), + ) + + // Act, Assert + filterChipUseCase(RelayListType.EXIT).test { + assertLists( + listOf(FilterChip.Ownership(expectedOwnership), FilterChip.Provider(1)), + awaitItem(), + ) + } + } }