Skip to content

Commit b4a47f7

Browse files
committed
Review
1 parent b602f70 commit b4a47f7

2 files changed

Lines changed: 49 additions & 13 deletions

File tree

stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/feature/messages/composer/MessageComposerControllerTest.kt

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import io.getstream.chat.android.models.SyncStatus
3939
import io.getstream.chat.android.models.User
4040
import io.getstream.chat.android.randomAttachment
4141
import io.getstream.chat.android.randomMessage
42+
import io.getstream.chat.android.randomString
4243
import io.getstream.chat.android.randomUser
4344
import io.getstream.chat.android.test.MockRetrofitCall
4445
import io.getstream.chat.android.test.TestCoroutineExtension
@@ -903,7 +904,7 @@ internal class MessageComposerControllerTest {
903904
@Test
904905
fun `Given edit mode When selectCommand called Then activeCommand is not set and event is emitted`() = runTest {
905906
// Given
906-
val command = Command("giphy", "Search GIFs", "[text]", "fun_set")
907+
val command = Command(name = randomString(), description = randomString(), args = randomString(), set = "fun_set")
907908
val editedMessage = randomMessage(cid = CID)
908909
val editAction = Edit(editedMessage)
909910
val controller = Fixture()
@@ -935,7 +936,12 @@ internal class MessageComposerControllerTest {
935936
fun `Given reply mode When selectCommand called with moderation command Then command is not set and event is emitted`() =
936937
runTest {
937938
// Given
938-
val muteCommand = Command("mute", "Mute user", "[@username]", "moderation_set")
939+
val muteCommand = Command(
940+
name = randomString(),
941+
description = randomString(),
942+
args = randomString(),
943+
set = "moderation_set",
944+
)
939945
val repliedMessage = randomMessage(cid = CID)
940946
val replyAction = Reply(repliedMessage)
941947
val controller = Fixture()
@@ -965,7 +971,12 @@ internal class MessageComposerControllerTest {
965971
@Test
966972
fun `Given reply mode When selectCommand then clearActiveCommand called Then reply action is preserved`() = runTest {
967973
// Given
968-
val giphyCommand = Command("giphy", "Search GIFs", "[text]", "fun_set")
974+
val giphyCommand = Command(
975+
name = randomString(),
976+
description = randomString(),
977+
args = randomString(),
978+
set = "fun_set",
979+
)
969980
val repliedMessage = randomMessage(cid = CID)
970981
val replyAction = Reply(repliedMessage)
971982
val controller = Fixture()
@@ -987,7 +998,7 @@ internal class MessageComposerControllerTest {
987998
controller.clearActiveCommand()
988999
advanceUntilIdle()
9891000

990-
// Then: reply action survives the enter/cancel round trip
1001+
// Then
9911002
assertEquals(replyAction, controller.state.value.action)
9921003
assertNull(controller.state.value.activeCommand)
9931004
}
@@ -1021,7 +1032,7 @@ internal class MessageComposerControllerTest {
10211032
@Test
10221033
fun `Given edit mode When user types slash Then suggestions stay empty and event is emitted`() = runTest {
10231034
// Given
1024-
val command = Command("giphy", "Search GIFs", "[text]", "fun_set")
1035+
val command = Command(name = randomString(), description = randomString(), args = randomString(), set = "fun_set")
10251036
val editedMessage = randomMessage(cid = CID, text = "")
10261037
val editAction = Edit(editedMessage)
10271038
val controller = Fixture()
@@ -1050,9 +1061,19 @@ internal class MessageComposerControllerTest {
10501061

10511062
@Test
10521063
fun `Given slash typed When action becomes Reply Then suggestions re-sort by availability`() = runTest {
1053-
// Given: moderation command listed first, fun command second (default server order)
1054-
val muteCommand = Command("mute", "Mute user", "[@username]", "moderation_set")
1055-
val giphyCommand = Command("giphy", "Search GIFs", "[text]", "fun_set")
1064+
// Given
1065+
val muteCommand = Command(
1066+
name = randomString(),
1067+
description = randomString(),
1068+
args = randomString(),
1069+
set = "moderation_set",
1070+
)
1071+
val giphyCommand = Command(
1072+
name = randomString(),
1073+
description = randomString(),
1074+
args = randomString(),
1075+
set = "fun_set",
1076+
)
10561077
val repliedMessage = randomMessage(cid = CID)
10571078
val controller = Fixture()
10581079
.givenConfig(MessageComposerController.Config(activeCommandEnabled = true))
@@ -1066,14 +1087,13 @@ internal class MessageComposerControllerTest {
10661087
.get()
10671088
controller.setMessageInput("/")
10681089
advanceUntilIdle()
1069-
// Sanity: with no action, server order is preserved.
10701090
assertEquals(listOf(muteCommand, giphyCommand), controller.state.value.commandSuggestions)
10711091

10721092
// When
10731093
controller.performMessageAction(Reply(repliedMessage))
10741094
advanceUntilIdle()
10751095

1076-
// Then: available (giphy) first, unavailable (mute) last
1096+
// Then
10771097
assertEquals(listOf(giphyCommand, muteCommand), controller.state.value.commandSuggestions)
10781098
}
10791099

stream-chat-android-ui-common/src/test/kotlin/io/getstream/chat/android/ui/common/state/messages/composer/CommandAvailabilityTest.kt

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package io.getstream.chat.android.ui.common.state.messages.composer
1818

1919
import io.getstream.chat.android.models.Command
2020
import io.getstream.chat.android.randomMessage
21+
import io.getstream.chat.android.randomString
2122
import io.getstream.chat.android.ui.common.state.messages.Edit
2223
import io.getstream.chat.android.ui.common.state.messages.Reply
2324
import org.junit.jupiter.api.Assertions.assertFalse
@@ -26,9 +27,24 @@ import org.junit.jupiter.api.Test
2627

2728
internal class CommandAvailabilityTest {
2829

29-
private val giphy = Command("giphy", "Search GIFs", "[text]", "fun_set")
30-
private val mute = Command("mute", "Mute user", "[@username]", "moderation_set")
31-
private val custom = Command("bot", "Custom bot", "", "bot_set")
30+
private val giphy = Command(
31+
name = randomString(),
32+
description = randomString(),
33+
args = randomString(),
34+
set = "fun_set",
35+
)
36+
private val mute = Command(
37+
name = randomString(),
38+
description = randomString(),
39+
args = randomString(),
40+
set = "moderation_set",
41+
)
42+
private val custom = Command(
43+
name = randomString(),
44+
description = randomString(),
45+
args = randomString(),
46+
set = randomString(),
47+
)
3248

3349
@Test
3450
fun `No active action makes every command available`() {

0 commit comments

Comments
 (0)