Skip to content

Commit 77017b5

Browse files
committed
Use waitForText for remaining text asserts and throttle its poll loop.
1 parent 1499c58 commit 77017b5

2 files changed

Lines changed: 12 additions & 19 deletions

File tree

  • stream-chat-android-compose-sample/src/androidTestE2eDebug/kotlin/io/getstream/chat/android/compose/robots
  • stream-chat-android-e2e-test/src/main/kotlin/io/getstream/chat/android/e2e/test/uiautomator

stream-chat-android-compose-sample/src/androidTestE2eDebug/kotlin/io/getstream/chat/android/compose/robots/UserRobotMessageListAsserts.kt

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,8 @@ fun UserRobot.assertMessageFailedIcon(isDisplayed: Boolean): UserRobot {
119119

120120
fun UserRobot.assertEditedMessage(text: String): UserRobot {
121121
assertMessage(text)
122-
assertEquals(
123-
appContext.getString(R.string.stream_compose_message_list_footnote_edited),
124-
Message.editedLabel.waitToAppear().text,
125-
)
122+
val expectedLabel = appContext.getString(R.string.stream_compose_message_list_footnote_edited)
123+
assertEquals(expectedLabel, Message.editedLabel.waitForText(expectedLabel))
126124
return this
127125
}
128126

@@ -237,8 +235,7 @@ fun UserRobot.assertMentionWasApplied(): UserRobot {
237235
}
238236

239237
fun UserRobot.assertComposerText(expectedText: String): UserRobot {
240-
val actualText = Composer.inputField.waitToAppear().text
241-
assertEquals(expectedText, actualText)
238+
assertEquals(expectedText, Composer.inputField.waitForText(expectedText))
242239
return this
243240
}
244241

@@ -268,27 +265,20 @@ fun UserRobot.assertThreadReplyLabelOnParentMessage(): UserRobot {
268265
1,
269266
1,
270267
)
271-
assertEquals(
272-
expectedResult,
273-
Message.threadRepliesLabel.waitToAppear().text,
274-
)
268+
assertEquals(expectedResult, Message.threadRepliesLabel.waitForText(expectedResult))
275269
assertTrue(Message.threadParticipantAvatar.isDisplayed())
276270
return this
277271
}
278272

279273
fun UserRobot.assertAlsoInTheChannelLabelInChannel(): UserRobot {
280-
assertEquals(
281-
appContext.getString(R.string.stream_compose_replied_to_thread),
282-
Message.messageHeaderLabel.waitToAppear().text,
283-
)
274+
val expectedLabel = appContext.getString(R.string.stream_compose_replied_to_thread)
275+
assertEquals(expectedLabel, Message.messageHeaderLabel.waitForText(expectedLabel))
284276
return this
285277
}
286278

287279
fun UserRobot.assertAlsoInTheChannelLabelInThread(): UserRobot {
288-
assertEquals(
289-
appContext.getString(R.string.stream_compose_also_sent_to_channel),
290-
Message.messageHeaderLabel.waitToAppear().text,
291-
)
280+
val expectedLabel = appContext.getString(R.string.stream_compose_also_sent_to_channel)
281+
assertEquals(expectedLabel, Message.messageHeaderLabel.waitForText(expectedLabel))
292282
return this
293283
}
294284

@@ -360,7 +350,7 @@ fun UserRobot.assertThreadReplyLabel(replies: Int, inThread: Boolean = false): U
360350
replies,
361351
replies,
362352
)
363-
assertEquals(expectedResult, Message.threadRepliesLabel.waitToAppear().text)
353+
assertEquals(expectedResult, Message.threadRepliesLabel.waitForText(expectedResult))
364354
}
365355
return this
366356
}

stream-chat-android-e2e-test/src/main/kotlin/io/getstream/chat/android/e2e/test/uiautomator/Wait.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,13 @@ public fun BySelector.waitForText(
8888
val matches = if (mustBeEqual) actual == expectedText else actual.contains(expectedText)
8989
if (matches) return actual
9090
}
91+
Thread.sleep(POLL_INTERVAL_MILLIS)
9192
}
9293
return lastText
9394
}
9495

96+
private const val POLL_INTERVAL_MILLIS = 50L
97+
9598
// Call [device] directly — [findObject] lies about nullability and NPEs when the selector hasn't
9699
// matched yet, which is the normal case during polling.
97100
private fun BySelector.currentTextOrNull(): String? = try {

0 commit comments

Comments
 (0)