Skip to content

Commit 9bdf285

Browse files
committed
feat: Add test tag for Enter Password dialog
- Add a `testTag` to the `EnterPasswordDialog` to improve testability. - Update `SettingPasswordTestCase` to use the new `dialogWindow` selector based on the test tag, replacing the previous retry mechanism. - Add a `dialogWindow` property to the `EnterPasswordDialog` test screen class.
1 parent 177da2b commit 9bdf285

File tree

3 files changed

+13
-8
lines changed

3 files changed

+13
-8
lines changed

ui/shared/src/commonMain/kotlin/com/softartdev/notedelight/ui/dialog/security/EnterPasswordDialog.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import androidx.compose.runtime.getValue
1616
import androidx.compose.ui.Modifier
1717
import androidx.compose.ui.autofill.AutofillManager
1818
import androidx.compose.ui.platform.LocalAutofillManager
19+
import androidx.compose.ui.platform.testTag
1920
import androidx.compose.ui.text.input.ImeAction
2021
import androidx.compose.ui.unit.dp
2122
import com.softartdev.notedelight.presentation.settings.security.enter.EnterAction
@@ -32,6 +33,8 @@ import notedelight.ui.shared.generated.resources.yes
3233
import org.jetbrains.compose.resources.stringResource
3334
import org.jetbrains.compose.ui.tooling.preview.Preview
3435

36+
const val ENTER_PASSWORD_DIALOG_TAG = "ENTER_PASSWORD_DIALOG_TAG"
37+
3538
@Composable
3639
fun EnterPasswordDialog(enterViewModel: EnterViewModel) {
3740
val result: EnterResult by enterViewModel.stateFlow.collectAsState()
@@ -47,6 +50,7 @@ fun ShowEnterPasswordDialog(
4750
result: EnterResult,
4851
onAction: (action: EnterAction) -> Unit = {}
4952
) = AlertDialog(
53+
modifier = Modifier.testTag(ENTER_PASSWORD_DIALOG_TAG),
5054
title = { Text(text = stringResource(Res.string.enter_password_dialog_title)) },
5155
text = {
5256
Column {

ui/test/src/commonMain/kotlin/com/softartdev/notedelight/ui/cases/SettingPasswordTestCase.kt

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,13 @@ class SettingPasswordTestCase(
136136
.performClick()
137137
enterPasswordDialog {
138138
logger.i { "EnterPasswordDialog: Disabling encryption with various inputs" }
139-
retryUntilDisplayed(
140-
description = "Enter Password Field",
141-
action = encryptionSwitchSNI::performClick,
142-
sni = enterPasswordSNI
143-
)
144-
logger.i { "EnterPasswordDialog: enterPasswordSNI is shown" }
139+
composeUiTest.waitUntilDisplayed("dialogWindow", blockSNI = ::dialogWindow)
140+
logger.i { "EnterPasswordDialog: dialogWindow is displayed" }
145141
enterLabelSNI.assertIsDisplayed()
146142
logger.i { "EnterPasswordDialog: enterLabelSNI is displayed" }
147-
enterVisibilitySNI.assertIsDisplayed()
148-
.performClick()
143+
composeUiTest.waitUntilDisplayed("enterVisibility", blockSNI = ::enterVisibilitySNI)
144+
logger.i { "EnterPasswordDialog: enterVisibilitySNI is displayed" }
145+
enterVisibilitySNI.performClick()
149146

150147
yesDialogButtonSNI.performClick()
151148
composeUiTest.waitAssert("enter label has empty pass text") {

ui/test/src/commonMain/kotlin/com/softartdev/notedelight/ui/screen/dialog/EnterPasswordDialog.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ package com.softartdev.notedelight.ui.screen.dialog
33
import androidx.compose.ui.test.SemanticsNodeInteraction
44
import androidx.compose.ui.test.onNodeWithTag
55
import com.softartdev.notedelight.ui.descTagTriple
6+
import com.softartdev.notedelight.ui.dialog.security.ENTER_PASSWORD_DIALOG_TAG
67
import notedelight.ui.shared.generated.resources.Res
78
import notedelight.ui.shared.generated.resources.enter_password
89
import kotlin.jvm.JvmInline
910

1011
@JvmInline
1112
value class EnterPasswordDialog(val commonDialog: CommonDialog) : CommonDialog by commonDialog {
1213

14+
val dialogWindow: SemanticsNodeInteraction
15+
get() = nodeProvider.onNodeWithTag(ENTER_PASSWORD_DIALOG_TAG, useUnmergedTree = true)
16+
1317
val enterPasswordSNI: SemanticsNodeInteraction
1418
get() = nodeProvider.onNodeWithTag(enterFieldTag, useUnmergedTree = true)
1519

0 commit comments

Comments
 (0)