Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChannelListPage {
companion object {
val userAvatar = By.res("Stream_UserAvatar")
val searchField = By.res("Stream_SearchInput")
val createChannelButton = "Stream_CreateChannelIcon"
val createChannelButton = By.res("Stream_CreateChannelIcon")
}
}

Expand All @@ -38,11 +38,18 @@ class ChannelListPage {
val channelList = By.res("Stream_ChannelList")
}

class SwipeActions {

companion object {
val mute = By.desc("Mute")
val more = By.desc("More")
}
}

class Channel {

companion object {
val avatar = By.res("Stream_ChannelAvatar")
val initialsAvatar = By.res("Stream_InitialsAvatar")
val name = By.res("Stream_ChannelName")
val messagePreview = By.res("Stream_MessagePreview")
val deliveryStatusIsRead = Message.deliveryStatusIsRead
Expand All @@ -59,4 +66,13 @@ class ChannelListPage {
}
}
}

class ChannelMenu {

companion object {
val viewInfo = By.res("Stream_ContextMenu_View info")
val leaveGroup = By.res("Stream_ContextMenu_Leave group")
val deleteGroup = By.res("Stream_ContextMenu_Delete Group")
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,10 @@ open class MessageListPage {
}
}

class MembersList {

companion object {
val members get() = By.res("Stream_MembersList")
}
}

class AttachmentPicker {

companion object {
val view get() = By.res("Stream_AttachmentsPicker")
val sendButton get() = By.res("Stream_AttachmentPickerSendButton")
val filesTab get() = By.res("Stream_AttachmentPickerFilesTab")
val mediaCaptureTab get() = By.res("Stream_AttachmentPickerMediaCaptureTab")
val pollsTab get() = By.res("Stream_AttachmentPickerPollsTab")
Expand All @@ -64,7 +56,7 @@ open class MessageListPage {
val sendButton get() = By.res("Stream_ComposerSendButton")
val cooldownIndicator get() = By.res("Stream_ComposerCooldownIndicator")
val saveButton get() = By.res("Stream_ComposerSaveButton")
val recordAudioButton get() = By.res("Stream_ComposerAudioRecordingButton")
val recordAudioButton get() = By.res("Stream_ComposerRecordAudioButton")
val commandSuggestionList get() = By.res("Stream_CommandSuggestionList")
val commandSuggestionListTitle get() = By.res("Stream_CommandSuggestionListTitle")
val userSuggestion get() = By.res("Stream_SuggestionItem")
Expand All @@ -89,14 +81,15 @@ open class MessageListPage {
class MessageList {

companion object {
val messageList get() = By.res("Stream_MessageList")
val messageList get() = By.res("Stream_Messages")
val messages get() = By.res("Stream_MessageCell")
val dateSeparator get() = By.res("Stream_MessageDateSeparator")
val unreadMessagesBadge get() = By.res("Stream_UnreadMessagesBadge")
val typingIndicator get() = By.res("Stream_MessageListTypingIndicator")
val scrollToBottomButton get() = By.res("Stream_ScrollToBottomButton")
val scrollToBottomButtonUnreadCount get() = By.res("Stream_ScrollToBottomButtonUnreadCount")
val systemMessage get() = By.res("Stream_SystemMessage")
val scrollToFirstUnreadButton get() = By.res("Stream_ScrollToFirstUnreadButton")
val scrollToFirstUnreadDismissIcon get() = By.res("Stream_ScrollToFirstUnreadButton_Dismiss")
}

class Message {
Expand All @@ -123,7 +116,6 @@ open class MessageListPage {
val fileImage get() = By.res("Stream_FileAttachmentImage")
val fileName get() = By.res("Stream_FileAttachmentName")
val fileSize get() = By.res("Stream_FileAttachmentSize")
val fileDownloadButton get() = By.res("Stream_FileAttachmentDownloadButton")
val columnWithMultipleFileAttachments get() = By.res("Stream_MultipleFileAttachmentsColumn")
val giphy get() = By.res("Stream_GiphyContent")
val linkPreviewImage get() = By.res("Stream_LinkAttachmentPreview")
Expand All @@ -135,6 +127,7 @@ open class MessageListPage {

companion object {
val reactions get() = By.res("Stream_MessageReaction")
val reactionAuthor get() = By.res("Stream_ReactionAuthor")

fun reaction(type: ReactionType): BySelector =
By.res("Stream_MessageReaction_${type.reaction}")
Expand Down Expand Up @@ -164,6 +157,7 @@ open class MessageListPage {
val unpin get() = By.res("Stream_ContextMenu_Unpin from this Chat")
val block get() = By.res("Stream_ContextMenu_Block user")
val delete get() = By.res("Stream_ContextMenu_Delete Message")
val showMoreReactions = By.desc("Show more reactions")
val ok = By.text("OK")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,24 @@ class UserRobot {
return this
}

fun copyMessage(messageCellIndex: Int = 0): UserRobot {
openContextMenu(messageCellIndex)
ContextMenu.copy.waitToAppear().click()
return this
}

fun pinMessage(messageCellIndex: Int = 0): UserRobot {
openContextMenu(messageCellIndex)
ContextMenu.pin.waitToAppear().click()
return this
}

fun unpinMessage(messageCellIndex: Int = 0): UserRobot {
openContextMenu(messageCellIndex)
ContextMenu.unpin.waitToAppear().click()
return this
}

fun clearComposer(): UserRobot {
Composer.inputField.waitToAppear().clear()
return this
Expand All @@ -200,6 +218,22 @@ class UserRobot {
return this
}

fun tapOnMessageReaction(): UserRobot {
Message.Reactions.reactions.waitToAppear().click()
return this
}

/**
* Adds or removes a reaction through the extended reactions picker sheet. Selecting a type
* the user has already reacted with removes that reaction.
*/
fun toggleReactionUsingExtendedPicker(type: ReactionType, messageCellIndex: Int = 0): UserRobot {
openContextMenu(messageCellIndex)
ContextMenu.showMoreReactions.waitToAppear().click()
ContextMenu.ReactionsView.reaction(type).waitToAppear().click()
return this
}

fun deleteReaction(type: ReactionType, usingContextMenu: Boolean = true, messageCellIndex: Int = 0): UserRobot {
if (usingContextMenu) {
addReaction(type, messageCellIndex)
Expand Down Expand Up @@ -254,6 +288,16 @@ class UserRobot {
return this
}

fun tapOnScrollToFirstUnreadButton(): UserRobot {
MessageList.scrollToFirstUnreadButton.waitToAppear().click()
return this
}

fun dismissUnreadIndicator(): UserRobot {
MessageList.scrollToFirstUnreadDismissIcon.waitToAppear().click()
return this
}

fun sendMessageInThread(
text: String,
alsoSendInChannel: Boolean = false,
Expand Down Expand Up @@ -310,6 +354,37 @@ class UserRobot {
return this
}

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

/** Swipes a channel item right to left to reveal the swipe actions behind it. */
fun swipeChannel(channelCellIndex: Int = 0): UserRobot {
val percent = 0.5f
val channel = ChannelListPage.ChannelList.channels.wait().findObjects()[channelCellIndex]
val rect = channel.visibleBounds
val startX = (rect.right - (rect.width() * 0.1)).toInt()
device.swipe(
startX, // startX
rect.centerY(), // startY
(startX - (rect.width() * percent)).toInt(), // endX
rect.centerY(), // endY
20, // steps
)
return this
}

fun tapOnMoreSwipeAction(): UserRobot {
ChannelListPage.ChannelList.SwipeActions.more.waitToAppear().click()
return this
}

fun tapOnViewChannelInfo(): UserRobot {
ChannelListPage.ChannelMenu.viewInfo.waitToAppear().click()
return this
}

fun swipeMessage(messageCellIndex: Int = 0): UserRobot {
val percent = 0.5f
val message = MessageList.messages.waitToAppearBottomUp(withIndex = messageCellIndex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,40 @@

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

import androidx.test.uiautomator.By
import io.getstream.chat.android.compose.pages.ChannelListPage.ChannelList.Channel
import io.getstream.chat.android.compose.pages.ChannelListPage.ChannelMenu
import io.getstream.chat.android.e2e.test.robots.ParticipantRobot
import io.getstream.chat.android.e2e.test.uiautomator.appContext
import io.getstream.chat.android.e2e.test.uiautomator.isDisplayed
import io.getstream.chat.android.e2e.test.uiautomator.waitDisplayed
import io.getstream.chat.android.e2e.test.uiautomator.waitForText
import io.getstream.chat.android.e2e.test.uiautomator.waitToDisappear
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import io.getstream.chat.android.ui.common.R as UiCommonR

fun UserRobot.assertChannelAvatar(): UserRobot {
assertTrue(Channel.avatar.isDisplayed())
return this
}

fun UserRobot.assertChannelActionsSheetForGroupChannel(): UserRobot {
assertTrue(ChannelMenu.viewInfo.waitDisplayed())
assertTrue(ChannelMenu.leaveGroup.isDisplayed())
assertTrue(ChannelMenu.deleteGroup.isDisplayed())
return this
}

fun UserRobot.assertGroupChannelInfoScreen(): UserRobot {
assertTrue(By.text(appContext.getString(UiCommonR.string.stream_ui_channel_info_group_title)).waitDisplayed())
assertTrue(
By.text(appContext.getString(UiCommonR.string.stream_ui_channel_info_option_pinned_messages)).isDisplayed(),
)
return this
}

fun UserRobot.assertMessageInChannelPreview(text: String, fromCurrentUser: Boolean? = null): UserRobot {
val expectedPreview = when (fromCurrentUser) {
true -> "You: $text"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.getstream.chat.android.compose.robots

import android.annotation.SuppressLint
import android.content.ClipboardManager
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
import io.getstream.chat.android.compose.R
Expand Down Expand Up @@ -314,6 +315,54 @@ fun UserRobot.assertAlsoInTheChannelLabelInThread(): UserRobot {
return this
}

fun UserRobot.assertUnreadSeparator(unreadCount: Int, isDisplayed: Boolean = true): UserRobot {
if (isDisplayed) {
val expectedText = appContext.resources.getQuantityString(
R.plurals.stream_compose_message_list_unread_separator,
unreadCount,
unreadCount,
)
assertEquals(expectedText, MessageListPage.MessageList.unreadMessagesBadge.waitForText(expectedText))
} else {
assertVisibility(MessageListPage.MessageList.unreadMessagesBadge, isDisplayed = false)
}
return this
}

fun UserRobot.assertScrollToFirstUnreadButton(unreadCount: Int? = null, isDisplayed: Boolean = true): UserRobot {
assertVisibility(MessageListPage.MessageList.scrollToFirstUnreadButton, isDisplayed)
if (isDisplayed && unreadCount != null) {
val expectedText = appContext.resources.getQuantityString(
R.plurals.stream_compose_scroll_to_first_unread_count,
unreadCount,
unreadCount,
)
assertTrue(By.text(expectedText).waitDisplayed())
}
return this
}

fun UserRobot.assertMessageCopied(text: String): UserRobot {
val clipboard = appContext.getSystemService(ClipboardManager::class.java)
assertEquals(text, clipboard.primaryClip?.getItemAt(0)?.text?.toString())
return this
}

/**
* Asserts the "Pinned by X" label above a message. [pinnedBy] is the name shown in the label;
* `null` expects the current user's label ("Pinned by You").
*/
fun UserRobot.assertMessagePinnedLabel(pinnedBy: String? = null, isDisplayed: Boolean = true): UserRobot {
val pinnedByName = pinnedBy ?: appContext.getString(R.string.stream_compose_message_list_you)
val expectedLabel = appContext.getString(R.string.stream_compose_pinned_to_channel_by, pinnedByName)
if (isDisplayed) {
assertEquals(expectedLabel, Message.messageHeaderLabel.waitForText(expectedLabel))
} else {
assertVisibility(Message.messageHeaderLabel.text(expectedLabel), isDisplayed = false)
}
return this
}

fun UserRobot.assertGiphyImage(isDisplayed: Boolean = true): UserRobot {
if (isDisplayed) {
assertTrue(Message.giphy.waitDisplayed())
Expand Down Expand Up @@ -354,6 +403,11 @@ fun UserRobot.assertReaction(type: ReactionType, isDisplayed: Boolean): UserRobo
return this
}

fun UserRobot.assertReactionAuthor(name: String): UserRobot {
assertTrue(Message.Reactions.reactionAuthor.hasDescendant(By.text(name)).waitDisplayed())
return this
Comment thread
coderabbitai[bot] marked this conversation as resolved.
}

@SuppressLint("ResourceType")
fun UserRobot.assertThreadReplyLabel(replies: Int, inThread: Boolean = false): UserRobot {
if (inThread) {
Expand Down
Loading
Loading