Skip to content

Commit

Permalink
[CI] Add QuoteReply E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple committed Jan 23, 2025
1 parent 3268d8d commit 99aa180
Show file tree
Hide file tree
Showing 11 changed files with 916 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,21 @@ class UserRobot {
return this
}

fun waitForMessageListToLoad(): UserRobot {
MessageListPage.Composer.inputField.wait()
return this
}

fun openChannel(channelCellIndex: Int = 0): UserRobot {
ChannelListPage.ChannelList.channels.wait().findObjects()[channelCellIndex].click()
return this
}

fun openContextMenu(messageCellIndex: Int = 0): UserRobot {
MessageList.messages.waitToAppear(withIndex = messageCellIndex).longPress()
MessageList.messages.waitToAppear()
val messages = MessageList.messages.findObjects()
val message = if (messages.size < messageCellIndex + 1) messages.last() else messages[messageCellIndex]
message.longPress()
return this
}

Expand Down Expand Up @@ -204,27 +212,27 @@ class UserRobot {
}

fun scrollChannelListDown(times: Int = 3): UserRobot {
device.swipeUp(times)
device.swipeUp(times = times)
return this
}

fun scrollChannelListUp(times: Int = 3): UserRobot {
device.swipeDown(times)
device.swipeDown(times = times)
return this
}

fun scrollMessageListDown(times: Int = 3): UserRobot {
scrollChannelListDown(times) // Reusing the channel list scroll
scrollChannelListDown(times = times) // Reusing the channel list scroll
return this
}

fun scrollMessageListUp(times: Int = 3): UserRobot {
scrollChannelListUp(times) // Reusing the channel list scroll
scrollChannelListUp(times = times) // Reusing the channel list scroll
return this
}

fun swipeMessage(messageCellIndex: Int = 0): UserRobot {
MessageList.messages.waitToAppear(withIndex = messageCellIndex).swipe(Direction.RIGHT, 50F)
MessageList.messages.waitToAppear(withIndex = messageCellIndex).swipe(Direction.RIGHT, 0.5f)
return this
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.getstream.chat.android.compose.robots

import android.annotation.SuppressLint
import androidx.test.uiautomator.By
import io.getstream.chat.android.compose.R
import io.getstream.chat.android.compose.pages.MessageListPage
Expand Down Expand Up @@ -128,6 +129,17 @@ fun UserRobot.assertDeletedMessage(text: String, hard: Boolean = false): UserRob
return this
}

fun UserRobot.assertQuotedMessage(text: String, quote: String = "", isDisplayed: Boolean = true): UserRobot {
if (isDisplayed) {
assertEquals(quote, Message.quotedMessage.waitToAppear().text)
assertTrue(Message.quotedMessageAvatar.isDisplayed())
} else {
assertFalse(Message.quotedMessage.waitToDisappear().isDisplayed())
}
assertMessage(text, isDisplayed = isDisplayed)
return this
}

fun UserRobot.assertMessageSizeChangesAfterEditing(linesCountShouldBeIncreased: Boolean): UserRobot {
val cellHeight = MessageListPage.MessageList.messages.waitToAppear(withIndex = 0).height
val messageText = Message.text.findObject().text
Expand Down Expand Up @@ -313,7 +325,10 @@ fun UserRobot.assertSystemMessage(text: String, isDisplayed: Boolean = true): Us
}

fun UserRobot.assertInvalidCommandMessage(text: String, isDisplayed: Boolean = true): UserRobot {
assertSystemMessage("Sorry, command $text doesn't exist. Try posting your message without the starting /")
assertSystemMessage(
text = "Sorry, command $text doesn't exist. Try posting your message without the starting /",
isDisplayed = isDisplayed,
)
return this
}

Expand All @@ -325,3 +340,38 @@ fun UserRobot.assertReaction(type: ReactionType, isDisplayed: Boolean): UserRobo
}
return this
}

@SuppressLint("ResourceType")
fun UserRobot.assertThreadReplyLabel(replies: Int, inThread: Boolean = false): UserRobot {
if (inThread) {
val expectedResult = appContext.resources.getQuantityString(
R.plurals.stream_compose_message_list_thread_separator,
replies,
replies,
)
assertEquals(
expectedResult,
ThreadPage.ThreadList.repliesCountLabel.waitToAppear().waitForText(expectedResult).text,
)
} else {
val expectedResult = if (replies == 1) {
appContext.getString(R.string.stream_compose_message_list_thread_footnote_thread_reply)
} else {
appContext.getString(R.string.stream_compose_message_list_thread_footnote_thread_replies, replies)
}
assertEquals(expectedResult, Message.threadRepliesLabel.waitToAppear().text)
}
return this
}

fun UserRobot.assertThreadReplyLabelAvatars(count: Int): UserRobot {
Message.threadParticipantAvatar.waitToAppear()
assertEquals(count, Message.threadParticipantAvatar.findObjects().size)
return this
}

fun UserRobot.assertMessages(text: String, count: Int): UserRobot {
val actualCount = Message.text.findObjects().count { it.text == text }
assertEquals(count, actualCount)
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,53 @@ class MessageListTests : StreamTestCase() {
}
}

@AllureId("6784")
@Ignore("https://linear.app/stream/issue/AND-273")
@Test
fun test_threadIsNotLocked_afterParentMessageDeletedByUser() {
step("GIVEN user opens the channel") {
backendRobot.generateChannels(channelsCount = 1, messagesCount = 1)
userRobot.login().openChannel()
}
step("AND participant adds a message in thread") {
participantRobot.sendMessageInThread(sampleText)
}
step("WHEN user deletes a parent message") {
userRobot.deleteMessage()
}
step("THEN thread is not locked") {
userRobot
.openThread(usingContextMenu = false)
.assertMessage(sampleText)
}
}

@AllureId("6785")
@Ignore("https://linear.app/stream/issue/AND-273")
@Test
fun test_threadIsNotLocked_afterParentMessageDeletedByParticipant() {
step("GIVEN user opens the channel") {
userRobot.login().openChannel()
}
step("AND participant sends a message") {
participantRobot.sendMessage(sampleText)
}
step("AND user sends a message in thread") {
userRobot
.openThread()
.sendMessage(sampleText)
.tapOnBackButton()
}
step("WHEN participant deletes a parent message") {
participantRobot.deleteMessage()
}
step("THEN thread is not locked") {
userRobot
.openThread(usingContextMenu = false)
.assertMessage(sampleText)
}
}

// MARK: - Message grouping

@AllureId("5803")
Expand Down
Loading

0 comments on commit 99aa180

Please sign in to comment.