@@ -9,17 +9,18 @@ import androidx.compose.ui.test.SemanticsMatcher
99import androidx.compose.ui.test.assertIsDisplayed
1010import androidx.compose.ui.test.hasContentDescription
1111import androidx.compose.ui.test.hasSetTextAction
12+ import androidx.compose.ui.test.hasTestTag
1213import androidx.compose.ui.test.hasText
1314import androidx.compose.ui.test.hasTextExactly
1415import androidx.compose.ui.test.junit4.ComposeContentTestRule
1516import androidx.compose.ui.test.junit4.createAndroidComposeRule
17+ import androidx.compose.ui.test.onNodeWithContentDescription
1618import androidx.compose.ui.test.onNodeWithText
1719import androidx.compose.ui.test.performClick
1820import androidx.compose.ui.test.performTextClearance
1921import androidx.compose.ui.test.performTextInput
2022import androidx.test.core.app.ApplicationProvider
2123import androidx.test.rule.GrantPermissionRule
22- import org.junit.Ignore
2324import org.junit.Rule
2425import org.junit.Test
2526import kotlin.time.Duration
@@ -38,7 +39,6 @@ class SmokeTestUiTest {
3839 @get:Rule
3940 val composeTestRule = createAndroidComposeRule<MainActivity >()
4041
41- @Ignore(" Working on a smoke test, doesn't pass yet" )
4242 @Test
4343 fun smokeTest () {
4444 composeTestRule.apply {
@@ -65,19 +65,68 @@ class SmokeTestUiTest {
6565 setPinFields(" 313373" , " 313373" )
6666 onNodeWithText(str(R .string.pin_creation_button)).performClick()
6767
68- waitForText( R .string.pin_creating_vault)
68+ waitForTextSimple(str( R .string.pin_creating_vault) )
6969
70- composeTestRule.waitUntil(
71- timeoutMillis = 30 .seconds.inWholeMilliseconds
72- ) {
73- composeTestRule
74- .onAllNodes(hasRole(Role .Button ) and hasContentDescription(str(R .string.camera_shutter_button_desc)))
75- .fetchSemanticsNodes().isNotEmpty()
76- }
70+ waitForButton(str(R .string.camera_shutter_button_desc))
7771
7872 onNode(
7973 hasRole(Role .Button ) and hasContentDescription(str(R .string.camera_shutter_button_desc))
80- ).assertExists()
74+ ).performClick()
75+
76+ waitForContentDescriptionSimple(str(R .string.camera_more_options_content_description))
77+
78+ onNode(
79+ hasRole(Role .Button ) and hasContentDescription(str(R .string.camera_more_options_content_description))
80+ ).performClick()
81+
82+ waitForTestTagSimple(" flash-switch" )
83+ onNode(
84+ hasRole(Role .Switch ) and hasTestTag(" flash-switch" )
85+ ).performClick()
86+
87+ onNode(
88+ hasRole(Role .Button ) and hasContentDescription(str(R .string.camera_close_controls_content_description))
89+ ).performClick()
90+ }
91+ }
92+
93+ private fun waitForButton (contentDescription : String ) {
94+ composeTestRule.waitUntil(
95+ timeoutMillis = 5 .seconds.inWholeMilliseconds
96+ ) {
97+ composeTestRule
98+ .onAllNodes(hasRole(Role .Button ) and hasContentDescription(contentDescription))
99+ .fetchSemanticsNodes().isNotEmpty()
100+ }
101+ }
102+
103+ private fun waitForTextSimple (text : String ) {
104+ composeTestRule.waitUntil(
105+ timeoutMillis = 5 .seconds.inWholeMilliseconds
106+ ) {
107+ composeTestRule
108+ .onAllNodes(hasText(text))
109+ .fetchSemanticsNodes().isNotEmpty()
110+ }
111+ }
112+
113+ private fun waitForContentDescriptionSimple (contentDescription : String ) {
114+ composeTestRule.waitUntil(
115+ timeoutMillis = 5 .seconds.inWholeMilliseconds
116+ ) {
117+ composeTestRule
118+ .onAllNodes(hasContentDescription(contentDescription))
119+ .fetchSemanticsNodes().isNotEmpty()
120+ }
121+ }
122+
123+ private fun waitForTestTagSimple (testTag : String ) {
124+ composeTestRule.waitUntil(
125+ timeoutMillis = 5 .seconds.inWholeMilliseconds
126+ ) {
127+ composeTestRule
128+ .onAllNodes(hasTestTag(testTag))
129+ .fetchSemanticsNodes().isNotEmpty()
81130 }
82131 }
83132
@@ -103,8 +152,11 @@ class SmokeTestUiTest {
103152 return application.resources
104153 }
105154
106- private fun ComposeContentTestRule.waitForText (@StringRes text : Int , timeout : Duration = 10.seconds) {
107- waitForText(str(text), timeout)
155+ private fun ComposeContentTestRule.waitForText (
156+ @StringRes text : Int ,
157+ timeout : Duration = 10.seconds
158+ ) {
159+ this @waitForText.waitForText(str(text), timeout)
108160 }
109161
110162 fun ComposeContentTestRule.waitForText (
@@ -123,6 +175,22 @@ class SmokeTestUiTest {
123175 .assertIsDisplayed()
124176 }
125177
178+ fun ComposeContentTestRule.waitForContentDescription (
179+ text : String ,
180+ timeout : Duration = 10.seconds,
181+ useUnmergedTree : Boolean = true,
182+ substring : Boolean = true
183+ ) {
184+ waitUntil(timeout.inWholeMilliseconds) {
185+ onAllNodes(
186+ hasText(text, substring = substring),
187+ useUnmergedTree = useUnmergedTree
188+ ).fetchSemanticsNodes().isNotEmpty()
189+ }
190+ onNodeWithContentDescription(text, substring = substring)
191+ .assertIsDisplayed()
192+ }
193+
126194 private fun ComposeContentTestRule.setTextField (value : String , placeholder : Int ) {
127195 onNode(
128196 hasSetTextAction() and hasTextExactly(
0 commit comments