diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-06-01 10:11:10 +0200 |
|---|---|---|
| committer | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-07-12 14:32:30 +0200 |
| commit | 4fc7e95a2a26a1f8d221959a417a5b3832b46ede (patch) | |
| tree | 2ed1a6ab96bd607329ede46c5bfe96fc7ba9bf08 /android/app/src/androidTest | |
| parent | 7ffe7307ca2a969193d0eec4853248d5cdaa4fa7 (diff) | |
| download | mullvadvpn-4fc7e95a2a26a1f8d221959a417a5b3832b46ede.tar.xz mullvadvpn-4fc7e95a2a26a1f8d221959a417a5b3832b46ede.zip | |
Add search bar to select location screen
- Filter countries, cities and relays based on search string
- Remove collapsable toolbar and replace with search bar
- Improve expand behavior for relay location cells
- Remove cirular dependency for relays
Diffstat (limited to 'android/app/src/androidTest')
| -rw-r--r-- | android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt | 82 |
1 files changed, 60 insertions, 22 deletions
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 e67e08249e..1bf4d5edbe 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 @@ -3,18 +3,22 @@ package net.mullvad.mullvadvpn.compose.screen import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText +import androidx.compose.ui.test.performTextInput import io.mockk.MockKAnnotations +import io.mockk.mockk +import io.mockk.verify import kotlinx.coroutines.flow.MutableSharedFlow import net.mullvad.mullvadvpn.compose.state.SelectLocationUiState import net.mullvad.mullvadvpn.compose.test.CIRCULAR_PROGRESS_INDICATOR import net.mullvad.mullvadvpn.compose.theme.AppTheme import net.mullvad.mullvadvpn.model.PortRange import net.mullvad.mullvadvpn.model.RelayEndpointData +import net.mullvad.mullvadvpn.model.RelayList import net.mullvad.mullvadvpn.model.RelayListCity import net.mullvad.mullvadvpn.model.RelayListCountry import net.mullvad.mullvadvpn.model.WireguardEndpointData import net.mullvad.mullvadvpn.model.WireguardRelayEndpointData -import net.mullvad.mullvadvpn.relaylist.RelayList +import net.mullvad.mullvadvpn.relaylist.toRelayCountries import org.junit.Before import org.junit.Rule import org.junit.Test @@ -38,13 +42,7 @@ class SelectLocationScreenTest { } // Assert - composeTestRule.apply { - onNodeWithText( - "While connected, your real location is masked with a private and secure location in the selected region." - ) - .assertExists() - onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists() - } + composeTestRule.apply { onNodeWithTag(CIRCULAR_PROGRESS_INDICATOR).assertExists() } } @Test @@ -54,7 +52,7 @@ class SelectLocationScreenTest { SelectLocationScreen( uiState = SelectLocationUiState.ShowData( - countries = DUMMY_RELAY_LIST.countries, + countries = DUMMY_RELAY_COUNTRIES, selectedRelay = null ), uiCloseAction = MutableSharedFlow() @@ -63,10 +61,6 @@ class SelectLocationScreenTest { // Assert composeTestRule.apply { - onNodeWithText( - "While connected, your real location is masked with a private and secure location in the selected region." - ) - .assertExists() onNodeWithText("Relay Country 1").assertExists() onNodeWithText("Relay City 1").assertDoesNotExist() onNodeWithText("Relay host 1").assertDoesNotExist() @@ -85,11 +79,11 @@ class SelectLocationScreenTest { uiState = SelectLocationUiState.ShowData( countries = - DUMMY_RELAY_LIST.countries.apply { + DUMMY_RELAY_COUNTRIES.apply { this[0].expanded = true this[0].cities[0].expanded = true }, - selectedRelay = DUMMY_RELAY_LIST.countries[0].cities[0].relays[0] + selectedRelay = DUMMY_RELAY_COUNTRIES[0].cities[0].relays[0] ), uiCloseAction = MutableSharedFlow() ) @@ -98,10 +92,6 @@ class SelectLocationScreenTest { // Assert composeTestRule.apply { - onNodeWithText( - "While connected, your real location is masked with a private and secure location in the selected region." - ) - .assertExists() onNodeWithText("Relay Country 1").assertExists() onNodeWithText("Relay City 1").assertExists() onNodeWithText("Relay host 1").assertExists() @@ -111,6 +101,55 @@ class SelectLocationScreenTest { } } + @Test + fun testSearchInput() { + // Arrange + val mockedSearchTermInput: (String) -> Unit = mockk(relaxed = true) + composeTestRule.setContent { + AppTheme { + SelectLocationScreen( + uiState = + SelectLocationUiState.ShowData( + countries = emptyList(), + selectedRelay = null + ), + uiCloseAction = MutableSharedFlow(), + onSearchTermInput = mockedSearchTermInput + ) + } + } + val mockSearchString = "SEARCH" + + // Act + composeTestRule.apply { onNodeWithText("Search for...").performTextInput(mockSearchString) } + + // Assert + verify { mockedSearchTermInput.invoke(mockSearchString) } + } + + @Test + fun testSearchTermNotFound() { + // Arrange + val mockedSearchTermInput: (String) -> Unit = mockk(relaxed = true) + val mockSearchString = "SEARCH" + composeTestRule.setContent { + AppTheme { + SelectLocationScreen( + uiState = + SelectLocationUiState.NoSearchResultFound(searchTerm = mockSearchString), + uiCloseAction = MutableSharedFlow(), + onSearchTermInput = mockedSearchTermInput + ) + } + } + + // Assert + composeTestRule.apply { + onNodeWithText("No result for $mockSearchString.", substring = true).assertExists() + onNodeWithText("Try a different search", substring = true).assertExists() + } + } + companion object { private val DUMMY_RELAY_1 = net.mullvad.mullvadvpn.model.Relay( @@ -137,12 +176,11 @@ class SelectLocationScreenTest { private val DUMMY_WIREGUARD_ENDPOINT_DATA = WireguardEndpointData(DUMMY_WIREGUARD_PORT_RANGES) - private val DUMMY_RELAY_LIST = + private val DUMMY_RELAY_COUNTRIES = RelayList( - net.mullvad.mullvadvpn.model.RelayList( arrayListOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2), DUMMY_WIREGUARD_ENDPOINT_DATA ) - ) + .toRelayCountries() } } |
