test: align infrared UI instrumentation coverage

This commit is contained in:
2026-08-26 21:24:20 +08:00
parent d8d9eb4f28
commit cd4a5ea04c
2 changed files with 11 additions and 35 deletions
@@ -8,6 +8,7 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import com.flagship.abox.manager.domain.DeviceName import com.flagship.abox.manager.domain.DeviceName
import com.flagship.abox.manager.infrared.remote.ui.InfraredRemoteScreen import com.flagship.abox.manager.infrared.remote.ui.InfraredRemoteScreen
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -3,17 +3,13 @@ package com.flagship.abox.manager.infrared.ui
import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithTag import androidx.compose.ui.test.onNodeWithTag
import androidx.compose.ui.test.performClick import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performTextInput import androidx.compose.ui.test.performTextInput
import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.junit.runners.AndroidJUnit4
import com.flagship.abox.manager.domain.DeviceName import com.flagship.abox.manager.domain.DeviceName
import com.flagship.abox.manager.domain.ProviderProfileId import com.flagship.abox.manager.domain.ProviderProfileId
import com.flagship.abox.manager.domain.ProviderType import com.flagship.abox.manager.domain.ProviderType
import com.flagship.abox.manager.domain.infrared.InfraredKeyId
import com.flagship.abox.manager.domain.infrared.InfraredKeyStatus
import com.flagship.abox.manager.domain.infrared.SavedInfraredKey
import org.junit.Assert.assertEquals import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.junit.runner.RunWith import org.junit.runner.RunWith
@@ -25,53 +21,32 @@ class InfraredControlScreenTest {
val composeTestRule = createComposeRule() val composeTestRule = createComposeRule()
@Test @Test
fun rendersControlScreenAndTriggersKeyOperations() { fun rendersDeviceConfigurationAndAcceptsDeviceNameInput() {
val testKey = SavedInfraredKey(
id = InfraredKeyId("k1"),
profileId = ProviderProfileId("profile1"),
deviceName = DeviceName("ir-1"),
displayName = "Power",
sdkKey = "1",
status = InfraredKeyStatus.READY,
lastErrorCode = null,
lastErrorDetail = null,
createdAtEpochMillis = 100L,
updatedAtEpochMillis = 100L,
)
val state = InfraredControlUiState( val state = InfraredControlUiState(
profileId = ProviderProfileId("profile1"), profileId = ProviderProfileId("profile1"),
providerType = ProviderType.LOCAL_EXPERIENCE, providerType = ProviderType.LOCAL_EXPERIENCE,
savedDeviceName = DeviceName("ir-1"), savedDeviceName = DeviceName("ir-1"),
keys = listOf(testKey),
loading = false, loading = false,
) )
var sendClicked = false var changedName: String? = null
var deleteClicked = false
composeTestRule.setContent { composeTestRule.setContent {
InfraredControlScreen( InfraredControlScreen(
state = state, state = state,
onBack = {}, onBack = {},
onSessionInvalid = {}, onSessionInvalid = {},
onDeviceNameChanged = {}, onDeviceNameChanged = { changedName = it },
onSaveDeviceName = {}, onSaveDeviceName = {},
onLearn = { _, _ -> },
onRetry = {},
onSend = { sendClicked = true },
onRename = { _, _ -> },
onDelete = { deleteClicked = true },
onMessageShown = {}, onMessageShown = {},
nextSlot = 2,
) )
} }
composeTestRule.onNodeWithTag("infrared_key_k1").assertIsDisplayed() composeTestRule.onNodeWithText("运行环境与连接信息").assertIsDisplayed()
composeTestRule.onNodeWithTag("infrared_send_k1").assertIsDisplayed().performClick() composeTestRule.onNodeWithTag("infrared_device_name_input")
assertTrue(sendClicked) .assertIsDisplayed()
.performTextInput("-updated")
composeTestRule.onNodeWithTag("infrared_delete_btn_k1").assertIsDisplayed().performClick() composeTestRule.waitForIdle()
composeTestRule.onNodeWithTag("infrared_delete_confirm").assertIsDisplayed().performClick() assertEquals("-updated", changedName)
assertTrue(deleteClicked)
} }
} }