package com.craigvg.lichun_android.ui import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Bolt import androidx.compose.runtime.Composable import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText import com.craigvg.lichun_android.ui.components.headers.SheetHeaderView import com.craigvg.lichun_android.ui.components.stats.CozyStatBadge import com.craigvg.lichun_android.ui.theme.AppColors import kotlinx.coroutines.flow.MutableStateFlow import org.junit.Rule import org.junit.Test import org.junit.runner.RunWith import org.robolectric.RobolectricTestRunner import org.robolectric.annotation.Config import org.robolectric.annotation.GraphicsMode /** * Robolectric-backed Compose UI tests that run on the JVM (no device/emulator). * * These establish a UI-test foundation for the modernized Compose layer: * - rendering a stateless component (`SheetHeaderView`, `CozyStatBadge`) and * asserting key content, * - rendering a composable that observes a `StateFlow` and asserting it * recomposes when the flow emits — the core pattern for screen-level tests. */ @RunWith(RobolectricTestRunner::class) @GraphicsMode(GraphicsMode.Mode.NATIVE) @Config(manifest = Config.NONE) class ComponentRenderTest { @get:Rule val composeRule = createComposeRule() @Test fun `SheetHeaderView shows energy diamonds and money values`() { composeRule.setContent { SheetHeaderView(energy = 85, diamonds = 12, money = 420) } composeRule.onNodeWithText("85").assertIsDisplayed() composeRule.onNodeWithText("12").assertIsDisplayed() composeRule.onNodeWithText("420").assertIsDisplayed() } @Test fun `CozyStatBadge shows value and label`() { composeRule.setContent { CozyStatBadge( icon = Icons.Default.Bolt, label = "Energy", value = 73, color = AppColors.energy ) } composeRule.onNodeWithText("73").assertIsDisplayed() composeRule.onNodeWithText("Energy").assertIsDisplayed() } @Test fun `composable observing a StateFlow recomposes on emission`() { val moneyFlow = MutableStateFlow(100) composeRule.setContent { MoneyLabel(moneyFlow) } composeRule.onNodeWithText("100").assertIsDisplayed() // Emit a new value; the collected state should drive a recomposition. moneyFlow.value = 250 composeRule.onNodeWithText("250").assertIsDisplayed() } } @Composable private fun MoneyLabel(flow: MutableStateFlow) { val money by flow.collectAsState() SheetHeaderView(energy = 0, diamonds = 0, money = money) }