Skip to content

Commit e8450f3

Browse files
committed
tests: add Android Compose tests for SettingSwitchItem functionality
1 parent 14945c3 commit e8450f3

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.kabiri.android.usbterminal.ui.setting
2+
3+
import androidx.activity.ComponentActivity
4+
import androidx.compose.foundation.layout.fillMaxSize
5+
import androidx.compose.ui.Modifier
6+
import androidx.compose.ui.test.assertIsDisplayed
7+
import androidx.compose.ui.test.assertIsOff
8+
import androidx.compose.ui.test.assertIsOn
9+
import androidx.compose.ui.test.hasAnySibling
10+
import androidx.compose.ui.test.hasText
11+
import androidx.compose.ui.test.isToggleable
12+
import androidx.compose.ui.test.junit4.createAndroidComposeRule
13+
import androidx.compose.ui.test.onNodeWithText
14+
import androidx.test.ext.junit.runners.AndroidJUnit4
15+
import org.junit.Rule
16+
import org.junit.Test
17+
import org.junit.runner.RunWith
18+
import org.kabiri.android.usbterminal.R
19+
import org.kabiri.android.usbterminal.ui.theme.UsbTerminalTheme
20+
21+
@RunWith(AndroidJUnit4::class)
22+
class SettingSwitchItemAndroidTest {
23+
@get:Rule
24+
val composeRule = createAndroidComposeRule<ComponentActivity>()
25+
26+
private fun showContet(enabled: Boolean = true) {
27+
composeRule.setContent {
28+
UsbTerminalTheme {
29+
SettingSwitchItem(
30+
enabled = enabled,
31+
onToggle = {},
32+
modifier = Modifier.fillMaxSize(),
33+
)
34+
}
35+
}
36+
}
37+
38+
@Test
39+
fun autoScrollSwitch_displaysLabel() {
40+
// arrange
41+
val context = composeRule.activity
42+
43+
// act
44+
showContet()
45+
46+
// assert
47+
composeRule
48+
.onNodeWithText(context.getString(R.string.settings_label_auto_scroll))
49+
.assertIsDisplayed()
50+
}
51+
52+
@Test
53+
fun autoScrollSwitch_isOn_whenEnabledTrue() {
54+
// arrange
55+
val context = composeRule.activity
56+
57+
// act
58+
showContet(enabled = true)
59+
60+
// assert
61+
composeRule
62+
.onNode(
63+
hasAnySibling(
64+
hasText(context.getString(R.string.settings_label_auto_scroll)),
65+
).and(isToggleable()),
66+
).assertIsOn()
67+
}
68+
69+
@Test
70+
fun autoScrollSwitch_isOff_whenEnabledFalse() {
71+
// arrange
72+
val context = composeRule.activity
73+
74+
// act
75+
showContet(enabled = false)
76+
77+
// assert
78+
composeRule
79+
.onNode(
80+
hasAnySibling(
81+
hasText(context.getString(R.string.settings_label_auto_scroll)),
82+
).and(isToggleable()),
83+
).assertIsOff()
84+
}
85+
}

0 commit comments

Comments
 (0)