@@ -4,9 +4,11 @@ import android.content.ClipboardManager
44import android.content.Context
55import androidx.activity.ComponentActivity
66import androidx.compose.runtime.mutableStateListOf
7+ import androidx.compose.ui.platform.testTag
78import androidx.compose.ui.test.assertIsDisplayed
89import androidx.compose.ui.test.junit4.createAndroidComposeRule
910import androidx.compose.ui.test.longClick
11+ import androidx.compose.ui.test.onNodeWithTag
1012import androidx.compose.ui.test.onNodeWithText
1113import androidx.compose.ui.test.performTouchInput
1214import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -74,4 +76,62 @@ class TerminalOutputAndroidTest {
7476 ?.toString()
7577 assertThat(copied).isEqualTo(" A\n B" )
7678 }
79+
80+ @Test
81+ fun terminalOutput_appliesModifierTag () {
82+ // arrange
83+ val logs =
84+ mutableStateListOf(
85+ OutputText (" Tagged line" , OutputText .OutputType .TYPE_NORMAL ),
86+ )
87+
88+ // act
89+ composeRule.setContent {
90+ UsbTerminalTheme {
91+ TerminalOutput (
92+ logs = logs,
93+ autoScroll = false ,
94+ modifier =
95+ androidx.compose.ui.Modifier
96+ .testTag(" terminal" ),
97+ )
98+ }
99+ }
100+
101+ // assert: the tagged node exists and is visible, and the text is displayed
102+ composeRule.onNodeWithTag(" terminal" ).assertExists().assertIsDisplayed()
103+ composeRule.onNodeWithText(" Tagged line" ).assertIsDisplayed()
104+ }
105+
106+ @Test
107+ fun terminalOutput_handlesEmptyLogs_andLongPressCopiesEmpty () {
108+ // arrange
109+ val context = composeRule.activity
110+ val logs = mutableStateListOf<OutputText >()
111+
112+ composeRule.setContent {
113+ UsbTerminalTheme {
114+ TerminalOutput (
115+ logs = logs,
116+ autoScroll = false ,
117+ modifier =
118+ androidx.compose.ui.Modifier
119+ .testTag(" terminal" ),
120+ )
121+ }
122+ }
123+
124+ // act: long-press the list itself
125+ composeRule.onNodeWithTag(" terminal" ).performTouchInput { longClick() }
126+ composeRule.waitForIdle()
127+
128+ // assert: clipboard should contain empty string
129+ val clipboard = context.getSystemService(Context .CLIPBOARD_SERVICE ) as ClipboardManager
130+ val copied =
131+ clipboard.primaryClip
132+ ?.getItemAt(0 )
133+ ?.coerceToText(context)
134+ ?.toString()
135+ assertThat(copied).isEqualTo(" " )
136+ }
77137}
0 commit comments