@@ -4,6 +4,7 @@ import android.content.ClipboardManager
44import android.content.Context
55import androidx.activity.ComponentActivity
66import androidx.compose.runtime.mutableStateListOf
7+ import androidx.compose.ui.Modifier
78import androidx.compose.ui.platform.testTag
89import androidx.compose.ui.test.assertIsDisplayed
910import androidx.compose.ui.test.junit4.createAndroidComposeRule
@@ -91,9 +92,7 @@ class TerminalOutputAndroidTest {
9192 TerminalOutput (
9293 logs = logs,
9394 autoScroll = false ,
94- modifier =
95- androidx.compose.ui.Modifier
96- .testTag(" terminal" ),
95+ modifier = Modifier .testTag(" terminal" ),
9796 )
9897 }
9998 }
@@ -115,8 +114,7 @@ class TerminalOutputAndroidTest {
115114 logs = logs,
116115 autoScroll = false ,
117116 modifier =
118- androidx.compose.ui.Modifier
119- .testTag(" terminal" ),
117+ Modifier .testTag(" terminal" ),
120118 )
121119 }
122120 }
@@ -134,4 +132,52 @@ class TerminalOutputAndroidTest {
134132 ?.toString()
135133 assertThat(copied).isEqualTo(" " )
136134 }
135+
136+ @Test
137+ fun terminalOutput_autoScrollTrue_withEmptyList_isStable () {
138+ // arrange
139+ val logs = mutableStateListOf<OutputText >()
140+
141+ // act
142+ composeRule.setContent {
143+ UsbTerminalTheme {
144+ TerminalOutput (
145+ logs = logs,
146+ autoScroll = true ,
147+ modifier = Modifier .testTag(" terminal" ),
148+ )
149+ }
150+ }
151+
152+ // assert: composable exists even with empty logs and autoScroll enabled
153+ composeRule.onNodeWithTag(" terminal" ).assertExists().assertIsDisplayed()
154+ }
155+
156+ @Test
157+ fun terminalOutput_noAutoScroll_append_rendersNewItem () {
158+ // arrange
159+ val logs =
160+ mutableStateListOf(
161+ OutputText (" Initial" , OutputText .OutputType .TYPE_NORMAL ),
162+ )
163+
164+ composeRule.setContent {
165+ UsbTerminalTheme {
166+ TerminalOutput (
167+ logs = logs,
168+ autoScroll = false ,
169+ modifier = Modifier .testTag(" terminal" ),
170+ )
171+ }
172+ }
173+
174+ // act: append a new line while autoScroll is disabled
175+ composeRule.runOnUiThread {
176+ logs.add(OutputText (" Next" , OutputText .OutputType .TYPE_NORMAL ))
177+ }
178+ composeRule.waitForIdle()
179+
180+ // assert: new item is rendered (if condition path with autoScroll=false evaluated)
181+ composeRule.onNodeWithText(" Next" ).assertIsDisplayed()
182+ }
137183}
0 commit comments