Skip to content

Commit

Permalink
Add allure ids, do refactoring, resolve some tiny issues
Browse files Browse the repository at this point in the history
  • Loading branch information
testableapple authored and JcMinarro committed Nov 12, 2024
1 parent 87333d0 commit 648383c
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class ChannelListPage {
val initialsAvatar = By.res("Stream_InitialsAvatar")
val name = By.res("Stream_ChannelName")
val messagePreview = By.res("Stream_MessagePreview")
val readStatus = By.res("Stream_ReadStatusIcon")
val readStatusIsRead = By.res("Stream_MessageReadStatus_isRead")
val readStatusIsPending = By.res("Stream_MessageReadStatus_isPending")
val readStatusIsSent = By.res("Stream_MessageReadStatus_isSent")
val readCount = By.res("Stream_MessageReadCount")
val unreadCountIndicator = By.res("Stream_UnreadCountIndicator")
val timestamp = By.res("Stream_Timestamp")
val typingIndicator = By.res("Stream_ChannelListTypingIndicator")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ package io.getstream.chat.android.compose.robots

import io.getstream.chat.android.compose.pages.ChannelListPage.ChannelList.Channel
import io.getstream.chat.android.compose.uiautomator.exists
import io.getstream.chat.android.compose.uiautomator.findObject
import io.getstream.chat.android.compose.uiautomator.wait
import io.getstream.chat.android.compose.uiautomator.waitToAppear
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue

fun UserRobot.assertChannelAvatar(): UserRobot {
Expand All @@ -33,3 +36,14 @@ fun UserRobot.assertMessageInChannelPreview(text: String, fromCurrentUser: Boole
assertTrue(Channel.timestamp.exists())
return this
}

fun UserRobot.assertMessageDeliveryStatus(shouldBeVisible: Boolean, shouldBeRead: Boolean = false) : UserRobot {
if (shouldBeVisible) {
val readStatus = if (shouldBeRead) Channel.readStatusIsRead else Channel.readStatusIsSent
assertTrue(readStatus.wait().exists())
} else {
assertFalse(Channel.readStatusIsRead.exists())
assertFalse(Channel.readStatusIsSent.exists())
}
return this
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
package io.getstream.chat.android.compose.tests

import io.getstream.chat.android.compose.robots.assertChannelAvatar
import io.getstream.chat.android.compose.robots.assertMessageDeliveryStatus
import io.getstream.chat.android.compose.robots.assertMessageInChannelPreview
import io.qameta.allure.kotlin.Allure.step
import io.qameta.allure.kotlin.AllureId
import org.junit.Test

class ChannelListTests : StreamTestCase() {

private val sampleText = "Test"

@AllureId("6343")
@Test
fun test_channelPreviewUpdates_whenParticipantSendsMessage() {
step("GIVEN user opens a channel") {
Expand All @@ -41,10 +44,12 @@ class ChannelListTests : StreamTestCase() {
step("THEN user observes the new message in preview") {
userRobot
.assertMessageInChannelPreview(sampleText, false)
.assertMessageDeliveryStatus(shouldBeVisible = false)
.assertChannelAvatar()
}
}

@AllureId("6344")
@Test
fun test_channelPreviewUpdates_whenUserSendsMessage() {
step("GIVEN user opens a channel") {
Expand All @@ -61,7 +66,14 @@ class ChannelListTests : StreamTestCase() {
step("THEN user observes the new message in preview") {
userRobot
.assertMessageInChannelPreview(sampleText, true)
.assertMessageDeliveryStatus(shouldBeVisible = true, shouldBeRead = false)
.assertChannelAvatar()
}
step("WHEN participant reads the message") {
participantRobot.readMessage()
}
step("THEN user observes the new message in preview") {
userRobot.assertMessageDeliveryStatus(shouldBeVisible = true, shouldBeRead = true)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ package io.getstream.chat.android.compose.tests
import io.getstream.chat.android.compose.robots.assertMessage
import io.getstream.chat.android.compose.robots.assertMessageAuthor
import io.qameta.allure.kotlin.Allure.step
import io.qameta.allure.kotlin.AllureId
import org.junit.Test

class MessageListTests : StreamTestCase() {

private val sampleText = "Test"

@AllureId("5661")
@Test
fun test_messageListUpdates_whenParticipantSendsMessage() {
step("GIVEN user opens a channel") {
Expand All @@ -42,6 +44,7 @@ class MessageListTests : StreamTestCase() {
}
}

@AllureId("5660")
@Test
fun test_messageListUpdates_whenUserSendsMessage() {
step("GIVEN user opens a channel") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package io.getstream.chat.android.compose.tests

import android.Manifest.permission
import android.Manifest.permission.POST_NOTIFICATIONS
import android.Manifest.permission.READ_MEDIA_IMAGES
import android.Manifest.permission.READ_MEDIA_VIDEO
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ private fun UserTypingIndicator(users: List<User>) {

/**
* Represents the default trailing content for the channel item. By default it shows
* the the information about the last message for the channel item, such as its read state,
* the information about the last message for the channel item, such as its read state,
* timestamp and how many unread messages the user has.
*
* @param channel The channel to show the info for.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ public fun MessageReadStatusIcon(
currentUser: User?,
modifier: Modifier = Modifier,
) {
val readStatues = channel.getReadStatuses(userToIgnore = currentUser)
val readCount = readStatues.count { it.time >= message.getCreatedAtOrThrow().time }
val readStatuses = channel.getReadStatuses(userToIgnore = currentUser)
val readCount = readStatuses.count { it.time >= message.getCreatedAtOrThrow().time }
val isMessageRead = readCount != 0

MessageReadStatusIcon(
message = message,
isMessageRead = isMessageRead,
modifier = modifier.testTag("Stream_ReadStatusIcon"),
readCount = readCount,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public fun sleep(timeOutMillis: Long = defaultTimeout) {
}

public fun BySelector.waitToAppear(timeOutMillis: Long = defaultTimeout): UiObject2 {
device.wait(Until.hasObject(this), timeOutMillis)
wait(timeOutMillis)
return findObject()
}

public fun BySelector.waitToAppear(withIndex: Int, timeOutMillis: Long = defaultTimeout): UiObject2 {
device.wait(Until.hasObject(this), timeOutMillis)
wait(timeOutMillis)
return findObjects()[withIndex]
}

Expand All @@ -39,6 +39,7 @@ public fun BySelector.wait(timeOutMillis: Long = defaultTimeout): BySelector {
return this
}

public fun BySelector.waitToDisappear(timeOutMillis: Long = defaultTimeout) {
public fun BySelector.waitToDisappear(timeOutMillis: Long = defaultTimeout): BySelector {
device.wait(Until.gone(this), timeOutMillis)
return this
}

0 comments on commit 648383c

Please sign in to comment.