diff options
| author | Jonatan Rhodin <jonatan.rhodin@mullvad.net> | 2023-05-16 10:32:33 +0200 |
|---|---|---|
| committer | Albin <albin@mullvad.net> | 2023-06-13 17:10:34 +0200 |
| commit | 2547e9cf8b180d5d2af3b1d73b9c2f88041d05b9 (patch) | |
| tree | 6754512c8df7f3d4c40ccf72b94e05ca021649c9 /android/app/src/androidTest | |
| parent | 64ae1f81ad328e7e179eea9e49b3dbf96e910dce (diff) | |
| download | mullvadvpn-2547e9cf8b180d5d2af3b1d73b9c2f88041d05b9.tar.xz mullvadvpn-2547e9cf8b180d5d2af3b1d73b9c2f88041d05b9.zip | |
Migrate select location fragment to compose
Diffstat (limited to 'android/app/src/androidTest')
| -rw-r--r-- | android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt | 141 |
1 files changed, 141 insertions, 0 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 new file mode 100644 index 0000000000..1dc87cddff --- /dev/null +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/SelectLocationScreenTest.kt @@ -0,0 +1,141 @@ +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 io.mockk.MockKAnnotations +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.RelayEndpointData +import net.mullvad.mullvadvpn.model.RelayListCity +import net.mullvad.mullvadvpn.model.RelayListCountry +import net.mullvad.mullvadvpn.model.WireguardRelayEndpointData +import net.mullvad.mullvadvpn.relaylist.RelayList +import org.junit.Before +import org.junit.Rule +import org.junit.Test + +class SelectLocationScreenTest { + @get:Rule val composeTestRule = createComposeRule() + + @Before + fun setup() { + MockKAnnotations.init(this) + } + + @Test + fun testDefaultState() { + // Arrange + composeTestRule.setContent { + SelectLocationScreen( + uiState = SelectLocationUiState.Loading, + uiCloseAction = MutableSharedFlow() + ) + } + + // 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() + } + } + + @Test + fun testShowRelayListState() { + // Arrange + composeTestRule.setContent { + SelectLocationScreen( + uiState = + SelectLocationUiState.ShowData( + countries = DUMMY_RELAY_LIST.countries, + selectedRelay = null + ), + uiCloseAction = MutableSharedFlow() + ) + } + + // 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() + onNodeWithText("Relay Country 2").assertExists() + onNodeWithText("Relay City 2").assertDoesNotExist() + onNodeWithText("Relay host 2").assertDoesNotExist() + } + } + + @Test + fun testShowRelayListStateSelected() { + // Arrange + composeTestRule.setContent { + AppTheme { + SelectLocationScreen( + uiState = + SelectLocationUiState.ShowData( + countries = + DUMMY_RELAY_LIST.countries.apply { + this[0].expanded = true + this[0].cities[0].expanded = true + }, + selectedRelay = DUMMY_RELAY_LIST.countries[0].cities[0].relays[0] + ), + uiCloseAction = MutableSharedFlow() + ) + } + } + + // 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() + onNodeWithText("Relay Country 2").assertExists() + onNodeWithText("Relay City 2").assertDoesNotExist() + onNodeWithText("Relay host 2").assertDoesNotExist() + } + } + + companion object { + private val DUMMY_RELAY_1 = + net.mullvad.mullvadvpn.model.Relay( + "Relay host 1", + true, + RelayEndpointData.Wireguard(WireguardRelayEndpointData) + ) + private val DUMMY_RELAY_2 = + net.mullvad.mullvadvpn.model.Relay( + "Relay host 2", + true, + RelayEndpointData.Wireguard(WireguardRelayEndpointData) + ) + private val DUMMY_RELAY_CITY_1 = + RelayListCity("Relay City 1", "RCi1", arrayListOf(DUMMY_RELAY_1)) + private val DUMMY_RELAY_CITY_2 = + RelayListCity("Relay City 2", "RCi2", arrayListOf(DUMMY_RELAY_2)) + private val DUMMY_RELAY_COUNTRY_1 = + RelayListCountry("Relay Country 1", "RCo1", arrayListOf(DUMMY_RELAY_CITY_1)) + private val DUMMY_RELAY_COUNTRY_2 = + RelayListCountry("Relay Country 2", "RCo2", arrayListOf(DUMMY_RELAY_CITY_2)) + + private val DUMMY_RELAY_LIST = + RelayList( + net.mullvad.mullvadvpn.model.RelayList( + arrayListOf(DUMMY_RELAY_COUNTRY_1, DUMMY_RELAY_COUNTRY_2) + ) + ) + } +} |
