diff options
| author | saber safavi <saber.safavi@codic.se> | 2023-05-15 14:07:08 +0200 |
|---|---|---|
| committer | saber safavi <saber.safavi@codic.se> | 2023-05-15 16:52:28 +0200 |
| commit | 26b857acd0701c741687e76f4f0b2a352e607c08 (patch) | |
| tree | 9d128bd932df0a405081da8064bd74afbd47e96f /android | |
| parent | 8c8996d0b2ebd924cde273130dc7c89c8f9eefe9 (diff) | |
| download | mullvadvpn-26b857acd0701c741687e76f4f0b2a352e607c08.tar.xz mullvadvpn-26b857acd0701c741687e76f4f0b2a352e607c08.zip | |
Add test tag to AdvancedSettingScreen
Add scroll during test to make last item of lazy list visible.
This can be use for all the tests whom need to be scroll, click, pinch and etc .
Diffstat (limited to 'android')
3 files changed, 45 insertions, 24 deletions
diff --git a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingsScreenTest.kt b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingsScreenTest.kt index 340b903886..970e877b80 100644 --- a/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingsScreenTest.kt +++ b/android/app/src/androidTest/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingsScreenTest.kt @@ -3,10 +3,13 @@ package net.mullvad.mullvadvpn.compose.screen import androidx.compose.material.ExperimentalMaterialApi import androidx.compose.ui.test.assertIsEnabled import androidx.compose.ui.test.assertIsNotEnabled +import androidx.compose.ui.test.hasTestTag import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithContentDescription +import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithText import androidx.compose.ui.test.performClick +import androidx.compose.ui.test.performScrollToNode import androidx.compose.ui.test.performTextInput import io.mockk.MockKAnnotations import io.mockk.mockk @@ -15,6 +18,8 @@ import io.mockk.verifyAll import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.asSharedFlow import net.mullvad.mullvadvpn.compose.state.AdvancedSettingsUiState +import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG +import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_TEST_TAG import net.mullvad.mullvadvpn.viewmodel.CustomDnsItem import net.mullvad.mullvadvpn.viewmodel.StagedDns import org.junit.Before @@ -249,13 +254,15 @@ class AdvancedSettingsScreenTest { listOf( CustomDnsItem(address = DUMMY_DNS_ADDRESS, false), CustomDnsItem(address = DUMMY_DNS_ADDRESS_2, false), - CustomDnsItem(address = DUMMY_DNS_ADDRESS_3, false), - ), + CustomDnsItem(address = DUMMY_DNS_ADDRESS_3, false) + ) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) } - + composeTestRule + .onNodeWithTag(LAZY_LIST_TEST_TAG) + .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Assert composeTestRule.apply { onNodeWithText(DUMMY_DNS_ADDRESS).assertExists() @@ -274,12 +281,14 @@ class AdvancedSettingsScreenTest { uiState = AdvancedSettingsUiState.DefaultUiState( isCustomDnsEnabled = false, - customDnsItems = listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, false)), + customDnsItems = listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, false)) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) } - + composeTestRule + .onNodeWithTag(LAZY_LIST_TEST_TAG) + .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Assert composeTestRule.onNodeWithText(DUMMY_DNS_ADDRESS).assertDoesNotExist() composeTestRule.onNodeWithText("Add a server").assertDoesNotExist() @@ -296,7 +305,7 @@ class AdvancedSettingsScreenTest { isCustomDnsEnabled = true, isAllowLanEnabled = true, customDnsItems = - listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = true)), + listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = true)) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -317,7 +326,7 @@ class AdvancedSettingsScreenTest { isCustomDnsEnabled = true, isAllowLanEnabled = false, customDnsItems = - listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = false)), + listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = false)) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -338,7 +347,7 @@ class AdvancedSettingsScreenTest { isCustomDnsEnabled = true, isAllowLanEnabled = true, customDnsItems = - listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = false)), + listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = false)) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -359,7 +368,7 @@ class AdvancedSettingsScreenTest { isCustomDnsEnabled = true, isAllowLanEnabled = false, customDnsItems = - listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = true)), + listOf(CustomDnsItem(address = DUMMY_DNS_ADDRESS, isLocal = true)) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -383,6 +392,9 @@ class AdvancedSettingsScreenTest { toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) } + composeTestRule + .onNodeWithTag(LAZY_LIST_TEST_TAG) + .performScrollToNode(hasTestTag(LAZY_LIST_LAST_ITEM_TEST_TAG)) // Act composeTestRule.onNodeWithText("Add a server").performClick() @@ -401,7 +413,7 @@ class AdvancedSettingsScreenTest { AdvancedSettingsUiState.DnsDialogUiState( stagedDns = StagedDns.NewDns( - item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), + item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false) ), ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() @@ -423,8 +435,8 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.EditDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), - index = 0, - ), + index = 0 + ) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -445,9 +457,9 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = true), - validationResult = StagedDns.ValidationResult.Success, + validationResult = StagedDns.ValidationResult.Success ), - isAllowLanEnabled = false, + isAllowLanEnabled = false ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -468,9 +480,9 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = true), - validationResult = StagedDns.ValidationResult.Success, + validationResult = StagedDns.ValidationResult.Success ), - isAllowLanEnabled = true, + isAllowLanEnabled = true ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -491,9 +503,9 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), - validationResult = StagedDns.ValidationResult.Success, + validationResult = StagedDns.ValidationResult.Success ), - isAllowLanEnabled = true, + isAllowLanEnabled = true ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -514,9 +526,9 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), - validationResult = StagedDns.ValidationResult.Success, + validationResult = StagedDns.ValidationResult.Success ), - isAllowLanEnabled = false, + isAllowLanEnabled = false ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -537,8 +549,8 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), - validationResult = StagedDns.ValidationResult.InvalidAddress, - ), + validationResult = StagedDns.ValidationResult.InvalidAddress + ) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) @@ -559,8 +571,8 @@ class AdvancedSettingsScreenTest { stagedDns = StagedDns.NewDns( item = CustomDnsItem(DUMMY_DNS_ADDRESS, isLocal = false), - validationResult = StagedDns.ValidationResult.DuplicateAddress, - ), + validationResult = StagedDns.ValidationResult.DuplicateAddress + ) ), toastMessagesSharedFlow = MutableSharedFlow<String>().asSharedFlow() ) diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingScreen.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingScreen.kt index fc9bd30be0..56aedb69ca 100644 --- a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingScreen.kt +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/screen/AdvancedSettingScreen.kt @@ -28,6 +28,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalLifecycleOwner +import androidx.compose.ui.platform.testTag import androidx.compose.ui.res.dimensionResource import androidx.compose.ui.res.stringResource import androidx.compose.ui.tooling.preview.Preview @@ -64,6 +65,8 @@ import net.mullvad.mullvadvpn.compose.dialog.MtuDialog import net.mullvad.mullvadvpn.compose.dialog.ObfuscationInfoDialog import net.mullvad.mullvadvpn.compose.extensions.itemWithDivider import net.mullvad.mullvadvpn.compose.state.AdvancedSettingsUiState +import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_LAST_ITEM_TEST_TAG +import net.mullvad.mullvadvpn.compose.test.LAZY_LIST_TEST_TAG import net.mullvad.mullvadvpn.compose.theme.MullvadBlue20 import net.mullvad.mullvadvpn.compose.theme.MullvadDarkBlue import net.mullvad.mullvadvpn.compose.theme.MullvadGreen @@ -240,6 +243,7 @@ fun AdvancedSettingScreen( LazyColumn( modifier = Modifier.drawVerticalScrollbar(lazyListState) + .testTag(LAZY_LIST_TEST_TAG) .fillMaxWidth() .wrapContentHeight() .animateContentSize(), @@ -451,6 +455,7 @@ fun AdvancedSettingScreen( isCellClickable = uiState.contentBlockersOptions.isAnyBlockerEnabled().not(), modifier = Modifier.background(MullvadDarkBlue) + .testTag(LAZY_LIST_LAST_ITEM_TEST_TAG) .padding( start = cellHorizontalSpacing, top = topPadding, diff --git a/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/test/ComposeTestTagConstants.kt b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/test/ComposeTestTagConstants.kt new file mode 100644 index 0000000000..55251eb3ea --- /dev/null +++ b/android/app/src/main/kotlin/net/mullvad/mullvadvpn/compose/test/ComposeTestTagConstants.kt @@ -0,0 +1,4 @@ +package net.mullvad.mullvadvpn.compose.test + +const val LAZY_LIST_TEST_TAG = "lazy_list_test_tag" +const val LAZY_LIST_LAST_ITEM_TEST_TAG = "lazy_list_last_item_test_tag" |
