Skip to content

Commit 1a5d0c0

Browse files
committed
Add CommandSelectionRoutingTest to verify command availability logic
1 parent 638f804 commit 1a5d0c0

1 file changed

Lines changed: 102 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) 2014-2026 Stream.io Inc. All rights reserved.
3+
*
4+
* Licensed under the Stream License;
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://github.com/GetStream/stream-chat-android/blob/main/LICENSE
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.getstream.chat.android.compose.ui.messages.composer.internal
18+
19+
import android.content.Context
20+
import androidx.test.core.app.ApplicationProvider
21+
import androidx.test.ext.junit.runners.AndroidJUnit4
22+
import io.getstream.chat.android.models.Command
23+
import io.getstream.chat.android.randomMessage
24+
import io.getstream.chat.android.ui.common.state.messages.Edit
25+
import io.getstream.chat.android.ui.common.state.messages.Reply
26+
import org.junit.Assert.assertEquals
27+
import org.junit.Assert.assertNull
28+
import org.junit.Before
29+
import org.junit.Test
30+
import org.junit.runner.RunWith
31+
import org.robolectric.annotation.Config
32+
33+
@RunWith(AndroidJUnit4::class)
34+
@Config(sdk = [33])
35+
internal class CommandSelectionRoutingTest {
36+
37+
private val giphy = Command("giphy", "Search GIFs", "[text]", "fun_set")
38+
private val mute = Command("mute", "Mute user", "[@username]", "moderation_set")
39+
40+
private lateinit var context: Context
41+
42+
@Before
43+
fun setUp() {
44+
context = ApplicationProvider.getApplicationContext()
45+
}
46+
47+
@Test
48+
fun `Available command invokes onAvailable`() {
49+
var received: Command? = null
50+
51+
routeCommandSelection(
52+
command = giphy,
53+
action = null,
54+
context = context,
55+
onAvailable = { received = it },
56+
)
57+
58+
assertEquals(giphy, received)
59+
}
60+
61+
@Test
62+
fun `Unavailable command in reply mode does not invoke onAvailable`() {
63+
var received: Command? = null
64+
65+
routeCommandSelection(
66+
command = mute,
67+
action = Reply(randomMessage()),
68+
context = context,
69+
onAvailable = { received = it },
70+
)
71+
72+
assertNull(received)
73+
}
74+
75+
@Test
76+
fun `Unavailable command in edit mode does not invoke onAvailable`() {
77+
var received: Command? = null
78+
79+
routeCommandSelection(
80+
command = giphy,
81+
action = Edit(randomMessage()),
82+
context = context,
83+
onAvailable = { received = it },
84+
)
85+
86+
assertNull(received)
87+
}
88+
89+
@Test
90+
fun `Non-moderation command in reply mode invokes onAvailable`() {
91+
var received: Command? = null
92+
93+
routeCommandSelection(
94+
command = giphy,
95+
action = Reply(randomMessage()),
96+
context = context,
97+
onAvailable = { received = it },
98+
)
99+
100+
assertEquals(giphy, received)
101+
}
102+
}

0 commit comments

Comments
 (0)