diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt index 1532328729ce..eb66c2d4f907 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/relaylist/RelayNameComparatorTest.kt @@ -2,6 +2,7 @@ package net.mullvad.mullvadvpn.relaylist import io.mockk.mockk import io.mockk.unmockkAll +import net.mullvad.mullvadvpn.model.Ownership import org.junit.jupiter.api.AfterEach import org.junit.jupiter.api.Assertions.assertTrue import org.junit.jupiter.api.Test @@ -21,6 +22,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay10 = RelayItem.Relay( @@ -28,6 +31,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay9 assertOrderBothDirection relay10 @@ -41,6 +46,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay9b = RelayItem.Relay( @@ -48,6 +55,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0) @@ -57,13 +66,41 @@ class RelayNameComparatorTest { @Test fun `comparator should be able to handle name of only numbers`() { val relay001 = - RelayItem.Relay(name = "001", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "001", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay1 = - RelayItem.Relay(name = "1", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "1", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay3 = - RelayItem.Relay(name = "3", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "3", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) val relay100 = - RelayItem.Relay(name = "100", location = mockk(), locationName = "mock", active = false) + RelayItem.Relay( + name = "100", + location = mockk(), + locationName = "mock", + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned + ) relay001 assertOrderBothDirection relay1 relay001 assertOrderBothDirection relay3 @@ -79,6 +116,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay9b = RelayItem.Relay( @@ -86,6 +125,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) assertTrue(RelayNameComparator.compare(relay9a, relay9b) == 0) @@ -100,6 +141,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay005 = RelayItem.Relay( @@ -107,6 +150,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay001 assertOrderBothDirection relay005 @@ -120,6 +165,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relayAr8 = RelayItem.Relay( @@ -127,6 +174,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relaySe5 = RelayItem.Relay( @@ -134,6 +183,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relaySe10 = RelayItem.Relay( @@ -141,6 +192,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relayAr2 assertOrderBothDirection relayAr8 @@ -155,7 +208,9 @@ class RelayNameComparatorTest { name = "se2-cloud", location = mockk(), locationName = "mock", - active = false + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay2w = RelayItem.Relay( @@ -163,6 +218,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay2c assertOrderBothDirection relay2w @@ -175,7 +232,9 @@ class RelayNameComparatorTest { name = "se22", location = mockk(), locationName = "mock", - active = false + active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) val relay22b = RelayItem.Relay( @@ -183,6 +242,8 @@ class RelayNameComparatorTest { location = mockk(), locationName = "mock", active = false, + providerName = "Provider", + ownership = Ownership.MullvadOwned ) relay22a assertOrderBothDirection relay22b diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt index fdcb4170f00f..1eadd0616016 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/usecase/CustomListActionUseCaseTest.kt @@ -71,7 +71,7 @@ class CustomListActionUseCaseTest { listOf(locationCode) ) } returns UpdateCustomListResult.Ok - coEvery { mockRelayListUseCase.relayList() } returns flowOf(mockLocations) + coEvery { mockRelayListUseCase.relatListAll() } returns flowOf(mockLocations) every { mockLocations.getRelayItemsByCodes(listOf(locationCode)) } returns mockLocations // Act 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 df10ba96c4e6..73cab810aa95 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 @@ -12,6 +12,7 @@ import net.mullvad.mullvadvpn.compose.communication.CustomListResult import net.mullvad.mullvadvpn.compose.state.CustomListLocationsUiState import net.mullvad.mullvadvpn.lib.common.test.TestCoroutineRule import net.mullvad.mullvadvpn.model.GeographicLocationConstraint +import net.mullvad.mullvadvpn.model.Ownership import net.mullvad.mullvadvpn.relaylist.RelayItem import net.mullvad.mullvadvpn.relaylist.descendants import net.mullvad.mullvadvpn.usecase.RelayListUseCase @@ -31,7 +32,7 @@ class CustomListLocationsViewModelTest { @BeforeEach fun setup() { - every { mockRelayListUseCase.relayList() } returns relayListFlow + every { mockRelayListUseCase.relatListAll() } returns relayListFlow every { mockRelayListUseCase.customLists() } returns customListFlow } @@ -283,7 +284,9 @@ class CustomListLocationsViewModelTest { "SE", "GBG", "gbg-1" - ) + ), + providerName = "Provider", + ownership = Ownership.MullvadOwned ) ) ) diff --git a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt index 41bff94ccd12..6522892ec2f6 100644 --- a/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt +++ b/android/app/src/test/kotlin/net/mullvad/mullvadvpn/viewmodel/SelectLocationViewModelTest.kt @@ -49,7 +49,7 @@ class SelectLocationViewModelTest { private val mockServiceConnectionManager: ServiceConnectionManager = mockk() private lateinit var viewModel: SelectLocationViewModel private val relayListWithSelectionFlow = - MutableStateFlow(RelayList(emptyList(), emptyList(), null)) + MutableStateFlow(RelayList(emptyList(), emptyList(), emptyList(), null)) private val mockRelayListUseCase: RelayListUseCase = mockk() private val mockCustomListActionUseCase: CustomListActionUseCase = mockk(relaxed = true) private val selectedOwnership = MutableStateFlow>(Constraint.Any()) @@ -93,10 +93,11 @@ class SelectLocationViewModelTest { fun `given relayListWithSelection emits update uiState should contain new update`() = runTest { // Arrange val mockCountries = listOf(mockk(), mockk()) - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val selectedItem: RelayItem = mockk() every { mockCountries.filterOnSearchTerm(any(), selectedItem) } returns mockCountries - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockCountries, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockCountries, mockCountries, selectedItem) // Act, Assert viewModel.uiState.test { @@ -111,12 +112,12 @@ class SelectLocationViewModelTest { fun `given relayListWithSelection emits update with no selections selectedItem should be null`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = listOf(mockk(), mockk()) val selectedItem: RelayItem? = null every { mockCountries.filterOnSearchTerm(any(), selectedItem) } returns mockCountries relayListWithSelectionFlow.value = - RelayList(mockCustomList, mockCountries, selectedItem) + RelayList(mockCustomList, mockCountries, mockCountries, selectedItem) // Act, Assert viewModel.uiState.test { @@ -155,7 +156,7 @@ class SelectLocationViewModelTest { @Test fun `on onSearchTermInput call uiState should emit with filtered countries`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = listOf(mockk(), mockk()) val selectedItem: RelayItem? = null val mockRelayList: List = mockk(relaxed = true) @@ -163,7 +164,8 @@ class SelectLocationViewModelTest { every { mockRelayList.filterOnSearchTerm(mockSearchString, selectedItem) } returns mockCountries every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockRelayList, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockRelayList, mockRelayList, selectedItem) // Act, Assert viewModel.uiState.test { @@ -184,7 +186,7 @@ class SelectLocationViewModelTest { @Test fun `when onSearchTermInput returns empty result uiState should return empty list`() = runTest { // Arrange - val mockCustomList = listOf(mockk()) + val mockCustomList = listOf(mockk(relaxed = true)) val mockCountries = emptyList() val selectedItem: RelayItem? = null val mockRelayList: List = mockk(relaxed = true) @@ -192,7 +194,8 @@ class SelectLocationViewModelTest { every { mockRelayList.filterOnSearchTerm(mockSearchString, selectedItem) } returns mockCountries every { mockCustomList.filterOnSearchTerm(mockSearchString) } returns mockCustomList - relayListWithSelectionFlow.value = RelayList(mockCustomList, mockRelayList, selectedItem) + relayListWithSelectionFlow.value = + RelayList(mockCustomList, mockRelayList, mockRelayList, selectedItem) // Act, Assert viewModel.uiState.test {