Modern Apps git

← Modern-Apps.git

library/ui: add tests for slice 2/3 (game/dialog/Material/Form/Settings)

Commit
190cc9646600a7133021afa521f05a29418000d6
Author
Vayun Mathur <[email protected]>
When
2026-11-06 18:47 UTC (29 days ago)
Parents
bff3998
Slice coverage ~14% -> 88.9% (merged, instructions 16055/18067 over the
23 slice classes: game/, dialog/, Material*, Form*, Settings*,
DynamicTheme). 12 test files, ~110 tests: Robolectric Compose (game chrome
+ interactions, date/time pickers incl. min/max delivery paths,
Material wrapper sweeps + explicit-args + state factories, form/settings
components incl. shared-element and expand branches) + JVM unit
(darkColorScheme, DateSelection).
Untestable remainder: the two single-emit dispatch lambdas
(DatePickerDialogKt$DatePickerDialog$deliver$1,
TimePickerDialogContent$2$1$1$1) sit at 75% — only their SharedFlow
buffer-suspension paths are uncovered, unreachable with capacity 64; and
dialog onDismissRequest lambdas (need a real back-press/outside-tap).
Bugs fixed: none.

(cherry picked from commit f6dee6b5d7447fe17b28c86dc42fa70b513a1758)

Diff

library/ui/src/test/java/com/vayunmathur/library/ui/Slice2ColorSchemeTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2ColorSchemeTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2ColorSchemeTest.ktnew file mode 100644index 0000000000..b4fb48c862--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2ColorSchemeTest.kt@@ -0,0 +1,49 @@+package com.vayunmathur.library.ui++import androidx.compose.ui.graphics.Color+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotEquals++/**+ * Slice 2/3 (library/ui): [darkColorScheme] — the app-theme builder over+ * Material's dark baseline. Every override lands; everything else stays on+ * the baseline, so a theme that names five colours does not silently reset+ * the other eight.+ */+class Slice2ColorSchemeTest {++    @Test+    fun `the default is materials dark baseline`() {+        val ours = darkColorScheme()+        val baseline = androidx.compose.material3.darkColorScheme()+        assertEquals(baseline.primary, ours.primary)+        assertEquals(baseline.surface, ours.surface)+        assertEquals(baseline.error, ours.error)+        assertEquals(baseline.onPrimary, ours.onPrimary)+    }++    @Test+    fun `overrides land and the rest stays put`() {+        val scheme = darkColorScheme(+            primary = Color(0xFF123456),+            error = Color(0xFF654321),+        )+        assertEquals(Color(0xFF123456), scheme.primary)+        assertEquals(Color(0xFF654321), scheme.error)+        val baseline = androidx.compose.material3.darkColorScheme()+        assertEquals(baseline.secondary, scheme.secondary)+        assertEquals(baseline.surface, scheme.surface)+        assertEquals(baseline.onSurface, scheme.onSurface)+        assertEquals(baseline.primaryContainer, scheme.primaryContainer)+    }++    @Test+    fun `two builds with different overrides differ only there`() {+        val a = darkColorScheme(primary = Color.Red)+        val b = darkColorScheme(primary = Color.Blue)+        assertNotEquals(a.primary, b.primary)+        assertEquals(a.secondary, b.secondary)+        assertEquals(a.error, b.error)+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormExtraTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormExtraTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormExtraTest.ktnew file mode 100644index 0000000000..e6584d1d9a--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormExtraTest.kt@@ -0,0 +1,181 @@+package com.vayunmathur.library.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.compose.ui.test.performTextReplacement+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Slice 2/3 (library/ui): the FormDetailGroup/FormSection branches the main+ * suite leaves out — shared-element rows, expand-on-enter, default option+ * labels, mandatory empties, and the shared-text field path.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2FormExtraTest {++    @get:Rule+    val rule = createComposeRule()++    private data class Slice2Row(val number: String, val type: Int)++    @Test+    fun `shared-key rows edit through the morphing branch`() {+        val items = mutableListOf(Slice2Row("111", 0))+        rule.setContent {+            FormDetailGroup(+                items = items.toList(),+                label = "Slice2 Shared",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { index, v -> items[index] = items[index].copy(number = v) },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = { items.removeAt(it) },+                onAdd = {},+                currentType = { it.type },+                sharedKey = { "slice2-row-${it.number}" },+            )+        }+        rule.onNodeWithText("111").assertIsDisplayed()+        rule.onNodeWithText("111").performTextReplacement("1112")+        assertEquals("1112", items[0].number)+    }++    @Test+    fun `expand on enter renders rows and the add button`() {+        rule.setContent {+            FormDetailGroup(+                items = listOf(Slice2Row("111", 0)),+                label = "Slice2 Expand",+                addLabel = "Slice2 Add More",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = {},+                onAdd = {},+                currentType = { it.type },+                expandOnEnter = true,+            )+        }+        rule.onNodeWithText("111").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Add More").assertIsDisplayed()+    }++    @Test+    fun `default option labels fall back to the raw value`() {+        var picked = -1+        rule.setContent {+            FormDetailGroup(+                items = listOf(Slice2Row("111", 0)),+                label = "Slice2 Opts",+                addLabel = "Slice2 Add",+                typeOptions = listOf(7),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Type 0" },+                onTypeChange = { _, t -> picked = t },+                onRemove = {},+                onAdd = {},+                currentType = { it.type },+                optionLabel = null,+            )+        }+        // Open the type menu: the option renders as its raw value.+        rule.onNodeWithText("Type 0").performClick()+        rule.onNodeWithText("7").performClick()+        assertEquals(7, picked)+    }++    @Test+    fun `mandatory empty row shows no clear button`() {+        rule.setContent {+            FormDetailGroup(+                items = listOf(Slice2Row("", 0)),+                label = "Slice2 Empty",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = { error("must not remove a mandatory row") },+                onAdd = {},+                currentType = { it.type },+                isMandatory = { true },+            )+        }+        rule.onNodeWithText("Slice2 Add").assertIsDisplayed()+    }++    @Test+    fun `custom row without a label handler shows no extra field`() {+        rule.setContent {+            FormDetailGroup(+                items = listOf(Slice2Row("111", 0)),+                label = "Slice2 NoCustom",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = {},+                onAdd = {},+                currentType = { it.type },+                isCustom = { true },+                onLabelChange = null,+            )+        }+        rule.onNodeWithText("111").assertIsDisplayed()+    }++    @Test+    fun `shared-text labelled field edits`() {+        var value = ""+        rule.setContent {+            LabeledTextField(+                value = value,+                onValueChange = { value = it },+                label = "Slice2 Morph",+                sharedTextKey = "slice2-morph-key",+            )+        }+        rule.onNodeWithText("Slice2 Morph").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Morph").performTextInput("morphed")+        assertEquals("morphed", value)+    }++    @Test+    fun `type menu switches the row type`() {+        val items = mutableListOf(Slice2Row("111", 0))+        rule.setContent {+            FormDetailGroup(+                items = items.toList(),+                label = "Slice2 Switch",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0, 1),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Kind ${it.type}" },+                onTypeChange = { index, t -> items[index] = items[index].copy(type = t) },+                onRemove = {},+                onAdd = {},+                currentType = { it.type },+                optionLabel = { "Pick $it" },+            )+        }+        rule.onNodeWithText("Kind 0").performClick()+        rule.onNodeWithText("Pick 1").performClick()+        assertEquals(1, items[0].type)+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.ktnew file mode 100644index 0000000000..5d4d39f745--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2FormSettingsTest.kt@@ -0,0 +1,300 @@+package com.vayunmathur.library.ui++import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.hasContentDescription+import androidx.compose.ui.test.hasText+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.compose.ui.test.performTextReplacement+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Slice 2/3 (library/ui): the form and settings building blocks — sections,+ * labelled fields, detail groups, and the settings row family.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2FormSettingsTest {++    @get:Rule+    val rule = createComposeRule()++    // --- FormSection ----------------------------------------------------------++    @Test+    fun `form section shows its title and fields`() {+        rule.setContent {+            FormSection(title = "Slice2 Form") {+                Text("field one")+            }+        }+        rule.onNodeWithText("Slice2 Form").assertIsDisplayed()+        rule.onNodeWithText("field one").assertIsDisplayed()+    }++    @Test+    fun `untitled form section just shows its content`() {+        rule.setContent {+            FormSection {+                Text("bare field")+            }+        }+        rule.onNodeWithText("bare field").assertIsDisplayed()+    }++    // --- LabeledTextField -----------------------------------------------------++    @Test+    fun `labelled field edits and reports`() {+        var value = ""+        rule.setContent {+            LabeledTextField(value = value, onValueChange = { value = it }, label = "Slice2 Label")+        }+        rule.onNodeWithText("Slice2 Label").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Label").performTextInput("hello")+        assertEquals("hello", value)+    }++    @Test+    fun `supporting text and error flag render`() {+        rule.setContent {+            LabeledTextField(+                value = "bad",+                onValueChange = {},+                label = "Slice2 Field",+                isError = true,+                supportingText = "slice2 supporting",+            )+        }+        rule.onNodeWithText("slice2 supporting").assertIsDisplayed()+    }++    @Test+    fun `disabled field does not accept input`() {+        rule.setContent {+            LabeledTextField(value = "", onValueChange = {}, label = "Slice2 Off", enabled = false)+        }+        rule.onNodeWithText("Slice2 Off").assertIsNotEnabled()+    }++    // --- FormDetailGroup --------------------------------------------------------++    private data class Slice2Row(val number: String, val type: Int)++    @Test+    fun `detail group lists rows and removes one`() {+        val items = mutableListOf(Slice2Row("111", 0), Slice2Row("222", 1))+        var added = 0+        rule.setContent {+            FormDetailGroup(+                items = items.toList(),+                label = "Slice2 Number",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0, 1),+                value = { it.number },+                onValueChange = { index, v -> items[index] = items[index].copy(number = v) },+                typeLabel = { "Type ${it.type}" },+                onTypeChange = { index, t -> items[index] = items[index].copy(type = t) },+                onRemove = { items.removeAt(it) },+                onAdd = { added++ },+                currentType = { it.type },+            )+        }+        rule.onNodeWithText("111").assertIsDisplayed()+        rule.onNodeWithText("222").assertIsDisplayed()+        // The first row's remove button drops it; the add button fires onAdd.+        rule.onAllNodes(hasContentDescription("Remove"))[0].performClick()+        rule.waitForIdle()+        assertEquals(listOf("222"), items.map { it.number })+        rule.onNodeWithText("Slice2 Add").performClick()+        assertEquals(1, added)+    }++    @Test+    fun `detail group edits a value in place`() {+        val items = mutableListOf(Slice2Row("111", 0))+        rule.setContent {+            FormDetailGroup(+                items = items.toList(),+                label = "Slice2 Number",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { index, v -> items[index] = items[index].copy(number = v) },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = { items.removeAt(it) },+                onAdd = {},+                currentType = { it.type },+            )+        }+        rule.onNodeWithText("111").performTextReplacement("999")+        assertEquals("999", items[0].number)+    }++    @Test+    fun `mandatory row clears instead of removing`() {+        val items = mutableListOf(Slice2Row("111", 0))+        var removed = 0+        rule.setContent {+            FormDetailGroup(+                items = items.toList(),+                label = "Slice2 Number",+                addLabel = "Slice2 Add",+                typeOptions = listOf(0),+                value = { it.number },+                onValueChange = { index, v -> items[index] = items[index].copy(number = v) },+                typeLabel = { "Type" },+                onTypeChange = { _, _ -> },+                onRemove = { removed++ },+                onAdd = {},+                currentType = { it.type },+                isMandatory = { true },+            )+        }+        rule.onNodeWithContentDescription("Remove").performClick()+        rule.waitForIdle()+        assertEquals(0, removed)+        assertEquals("", items[0].number)+    }++    @Test+    fun `custom type label field shows when the row is custom`() {+        val items = listOf(Slice2Row("111", 99))+        rule.setContent {+            FormDetailGroup(+                items = items,+                label = "Slice2 Number",+                addLabel = "Slice2 Add",+                typeOptions = listOf(99),+                value = { it.number },+                onValueChange = { _, _ -> },+                typeLabel = { "Custom" },+                onTypeChange = { _, _ -> },+                onRemove = {},+                onAdd = {},+                currentType = { it.type },+                isCustom = { true },+                onLabelChange = { _, _ -> },+                customLabel = { "my label" },+                customLabelText = "Slice2 Custom",+            )+        }+        rule.onNodeWithText("my label").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Custom").assertIsDisplayed()+    }++    // --- SettingsSection / SettingsRow ------------------------------------------++    @Test+    fun `settings section shows title and rows`() {+        rule.setContent {+            SettingsSection(title = "Slice2 Settings") {+                SettingsRow(title = "Slice2 Row")+            }+        }+        rule.onNodeWithText("Slice2 Settings").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Row").assertIsDisplayed()+    }++    @Test+    fun `settings row click fires and supporting text shows`() {+        var clicked = 0+        rule.setContent {+            SettingsRow(title = "Slice2 Row", supportingText = "slice2 sub", onClick = { clicked++ })+        }+        rule.onNodeWithText("slice2 sub").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Row").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `row without a handler is not clickable`() {+        rule.setContent {+            SettingsRow(title = "Slice2 Static")+        }+        rule.onNodeWithText("Slice2 Static").assertIsDisplayed()+        // No click action: the node carries no clickable semantics.+        rule.onNodeWithText("Slice2 Static").performClick()+    }++    // --- SettingsSwitchRow --------------------------------------------------------++    @Test+    fun `switch row toggles from the row and the switch`() {+        val seen = mutableListOf<Boolean>()+        rule.setContent {+            SettingsSwitchRow(title = "Slice2 Toggle", checked = false, onCheckedChange = seen::add)+        }+        rule.onNodeWithText("Slice2 Toggle").performClick()+        assertEquals(listOf(true), seen)+    }++    // --- SettingsSelectRow --------------------------------------------------------++    @Test+    fun `select row shows the current choice and picks another`() {+        var selected = "A"+        rule.setContent {+            SettingsSelectRow(+                title = "Slice2 Pick",+                selected = selected,+                options = listOf("A", "B"),+                label = { "Choice $it" },+                onSelect = { selected = it },+            )+        }+        rule.onNodeWithText("Choice A").assertIsDisplayed()+        rule.onNodeWithText("Slice2 Pick").performClick()+        rule.onNodeWithText("Choice B").performClick()+        assertEquals("B", selected)+    }++    // --- SettingsDivider ------------------------------------------------------------++    @Test+    fun `settings divider renders without crashing`() {+        rule.setContent {+            SettingsSection {+                SettingsRow(title = "Above")+                SettingsDivider()+                SettingsRow(title = "Below")+            }+        }+        rule.onNodeWithText("Above").assertIsDisplayed()+        rule.onNodeWithText("Below").assertIsDisplayed()+    }++    // --- SettingsExposedSelectRow -----------------------------------------------------++    @Test+    fun `exposed select shows the current item and picks another`() {+        var selected = "X"+        rule.setContent {+            SettingsExposedSelectRow(+                label = "Slice2 Codec",+                selected = selected,+                options = listOf("X", "Y"),+                itemLabel = { "Item $it" },+                onSelect = { selected = it },+                itemSupporting = { if (it == "Y") "why Y" else null },+            )+        }+        rule.onNodeWithText("Item X").assertIsDisplayed()+        rule.onNodeWithText("Item X").performClick()+        // The open menu shows each option with its supporting line.+        assertTrue(+            rule.onAllNodes(hasText("why Y")).fetchSemanticsNodes().isNotEmpty(),+        )+        rule.onNodeWithText("Item Y").performClick()+        assertEquals("Y", selected)+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialArgsTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialArgsTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialArgsTest.ktnew file mode 100644index 0000000000..919cae5653--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialArgsTest.kt@@ -0,0 +1,340 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.BorderStroke+import androidx.compose.foundation.layout.Column+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.Add+import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.ui.Modifier+import androidx.compose.ui.graphics.Color+import androidx.compose.ui.graphics.vector.rememberVectorPainter+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.text.AnnotatedString+import androidx.compose.ui.text.font.FontWeight+import androidx.compose.ui.unit.dp+import androidx.compose.ui.unit.sp+import com.vayunmathur.library.util.LocalHostScaffoldInfo+import com.vayunmathur.library.util.LocalSnackbarHostState+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Slice 2/3 (library/ui): non-default argument paths and the branches the+ * sweep leaves out — painter icons, explicit styling args, the hosted+ * Scaffold branch, nav suite, and the indicator/divider tab row.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2MaterialArgsTest {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `icon renders from a painter`() {+        rule.setContent {+            val painter = rememberVectorPainter(image = Icons.Filled.Add)+            Icon(painter = painter, contentDescription = "slice2 painted")+        }+        rule.onNodeWithContentDescription("slice2 painted").assertIsDisplayed()+    }++    @Test+    fun `text honors explicit styling args`() {+        rule.setContent {+            Column {+                Text(+                    text = "slice2 styled text",+                    color = Color.Red,+                    fontSize = 20.sp,+                    fontWeight = FontWeight.Bold,+                    maxLines = 2,+                )+                Text(+                    text = AnnotatedString("slice2 styled annotated"),+                    color = Color.Blue,+                    fontWeight = FontWeight.Light,+                    maxLines = 1,+                )+            }+        }+        rule.onNodeWithText("slice2 styled text").assertIsDisplayed()+        rule.onNodeWithText("slice2 styled annotated").assertIsDisplayed()+    }++    @Test+    fun `buttons honor explicit styling args`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                Button(+                    onClick = { clicks += "b" },+                    border = BorderStroke(1.dp, Color.Red),+                    content = { Text("slice2 bordered") },+                )+                OutlinedButton(onClick = { clicks += "o" }, enabled = true) {+                    Text("slice2 obtn")+                }+                FloatingActionButton(+                    onClick = { clicks += "f" },+                    containerColor = Color.Green,+                    modifier = Modifier.testTag("slice2 fab arg"),+                ) { Text("F2") }+            }+        }+        rule.onNodeWithText("slice2 bordered").performClick()+        rule.onNodeWithText("slice2 obtn").performClick()+        rule.onNodeWithTag("slice2 fab arg").performClick()+        assertEquals(listOf("b", "o", "f"), clicks)+    }++    @Test+    fun `cards and surfaces honor explicit args`() {+        var clicked = 0+        rule.setContent {+            Column {+                Card(+                    border = BorderStroke(1.dp, Color.Blue),+                    content = { Text("slice2 card border") },+                )+                ElevatedCard(+                    onClick = { clicked++ },+                    enabled = true,+                    content = { Text("slice2 ecard arg") },+                )+                Surface(+                    tonalElevation = 2.dp,+                    shadowElevation = 2.dp,+                    border = BorderStroke(1.dp, Color.Gray),+                    content = { Text("slice2 surface arg") },+                )+            }+        }+        rule.onNodeWithText("slice2 card border").assertIsDisplayed()+        rule.onNodeWithText("slice2 surface arg").assertIsDisplayed()+        rule.onNodeWithText("slice2 ecard arg").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `app bars honor colors and scroll behavior`() {+        rule.setContent {+            Column {+                val behavior = appBarScrollBehavior(AppBarSize.Small)+                TopAppBar(+                    title = { Text("slice2 bar colors") },+                    navigationIcon = { IconAdd() },+                    scrollBehavior = behavior,+                )+                CenterAlignedTopAppBar(+                    title = { Text("slice2 center colors") },+                    scrollBehavior = behavior,+                )+            }+        }+        rule.onNodeWithText("slice2 bar colors").assertIsDisplayed()+        rule.onNodeWithText("slice2 center colors").assertIsDisplayed()+    }++    @Test+    fun `hosted scaffold renders content without a snackbar state`() {+        rule.setContent {+            CompositionLocalProvider(LocalHostScaffoldInfo provides true) {+                Scaffold(+                    topBar = { TopAppBar(title = { Text("slice2 hosted") }) },+                ) {+                    Text("slice2 hosted body")+                }+            }+        }+        rule.onNodeWithText("slice2 hosted").assertIsDisplayed()+        rule.onNodeWithText("slice2 hosted body").assertIsDisplayed()+    }++    @Test+    fun `hosted scaffold with a global snackbar state resolves the default host`() {+        rule.setContent {+            val snackbar = androidx.compose.material3.SnackbarHostState()+            CompositionLocalProvider(+                LocalHostScaffoldInfo provides true,+                LocalSnackbarHostState provides snackbar,+            ) {+                Scaffold {+                    Text("slice2 hosted snackbar body")+                }+            }+        }+        rule.onNodeWithText("slice2 hosted snackbar body").assertIsDisplayed()+    }++    @Test+    fun `tab rows honor explicit colors`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                TabRow(selectedTabIndex = 0, containerColor = Color.Red, contentColor = Color.White) {+                    Tab(selected = true, onClick = { clicks += "t" }, text = { Text("slice2 tab c") })+                }+                SecondaryTabRow(selectedTabIndex = 0, containerColor = Color.Blue, contentColor = Color.White) {+                    Tab(selected = false, onClick = { clicks += "s" }, text = { Text("slice2 stab c") })+                }+                PrimaryTabRow(selectedTabIndex = 0, containerColor = Color.Green, contentColor = Color.White) {+                    Tab(selected = false, onClick = { clicks += "p" }, text = { Text("slice2 ptab c") })+                }+                PrimaryScrollableTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "ps" }, text = { Text("slice2 pst c") })+                }+            }+        }+        rule.onNodeWithText("slice2 tab c").performClick()+        rule.onNodeWithText("slice2 stab c").performClick()+        rule.onNodeWithText("slice2 ptab c").performClick()+        rule.onNodeWithText("slice2 pst c").performClick()+        assertEquals(listOf("t", "s", "p", "ps"), clicks)+    }++    @Test+    fun `indicator tab row renders custom indicator and divider`() {+        var clicked = 0+        rule.setContent {+            SecondaryTabRow(+                selectedTabIndex = 0,+                indicator = { Text("slice2 indicator") },+                divider = { HorizontalDivider() },+            ) {+                Tab(selected = true, onClick = { clicked++ }, text = { Text("slice2 itab") })+            }+        }+        rule.onNodeWithText("slice2 indicator").assertIsDisplayed()+        rule.onNodeWithText("slice2 itab").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `navigation suite scaffold renders items and content`() {+        var picked = -1+        rule.setContent {+            NavigationSuiteScaffold(+                navigationSuiteItems = {+                    item(+                        selected = true,+                        onClick = { picked = 0 },+                        icon = { IconAdd() },+                        label = { Text("slice2 suite a") },+                    )+                    item(+                        selected = false,+                        onClick = { picked = 1 },+                        icon = { IconAdd() },+                        label = { Text("slice2 suite b") },+                    )+                },+            ) {+                Text("slice2 suite body")+            }+        }+        rule.onNodeWithText("slice2 suite body").assertIsDisplayed()+        rule.onNodeWithText("slice2 suite b").performClick()+        assertEquals(1, picked)+    }++    @Test+    fun `modal sheet and sheet scaffold honor explicit args`() {+        rule.setContent {+            Column {+                val sheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true)+                ModalBottomSheet(+                    onDismissRequest = {},+                    sheetState = sheetState,+                    containerColor = Color.White,+                ) {+                    Text("slice2 modal arg")+                }+            }+        }+        rule.onNodeWithText("slice2 modal arg").assertIsDisplayed()+    }++    @Test+    fun `bottom sheet scaffold honors explicit args`() {+        rule.setContent {+            val scaffoldState = rememberBottomSheetScaffoldState()+            BottomSheetScaffold(+                sheetContent = { Text("slice2 bss sheet") },+                scaffoldState = scaffoldState,+                sheetPeekHeight = 64.dp,+                sheetSwipeEnabled = false,+                sheetDragHandle = null,+                topBar = { Text("slice2 bss top") },+            ) {+                Text("slice2 bss body")+            }+        }+        rule.onNodeWithText("slice2 bss top").assertIsDisplayed()+        rule.onNodeWithText("slice2 bss body").assertIsDisplayed()+    }++    @Test+    fun `material theme entry honors explicit args`() {+        rule.setContent {+            MaterialTheme(+                colorScheme = darkColorScheme(primary = Color.Red),+                shapes = androidx.compose.material3.Shapes(),+                typography = androidx.compose.material3.Typography(),+            ) {+                Text("slice2 theme args")+            }+        }+        rule.onNodeWithText("slice2 theme args").assertIsDisplayed()+    }++    @Test+    fun `fields honor shapes and supporting content`() {+        var s = "12"+        rule.setContent {+            Column {+                OutlinedTextField(+                    value = s,+                    onValueChange = { s = it },+                    label = { Text("slice2 shape field") },+                    shape = androidx.compose.foundation.shape.RoundedCornerShape(4.dp),+                    prefix = { Text("slice2 prefix") },+                    suffix = { Text("slice2 suffix") },+                )+            }+        }+        rule.onNodeWithText("slice2 prefix").assertIsDisplayed()+        rule.onNodeWithText("slice2 suffix").assertIsDisplayed()+    }++    @Test+    fun `drawer item and bottom bar honor args`() {+        var clicked = 0+        rule.setContent {+            Column {+                NavigationDrawerItem(+                    label = { Text("slice2 ndi") },+                    selected = true,+                    onClick = { clicked++ },+                    icon = { IconAdd() },+                    badge = { Text("slice2 badge") },+                )+                BottomAppBar(contentPadding = androidx.compose.foundation.layout.PaddingValues(2.dp)) {+                    Text("slice2 bab")+                }+            }+        }+        rule.onNodeWithText("slice2 ndi").performClick()+        rule.onNodeWithText("slice2 badge").assertIsDisplayed()+        rule.onNodeWithText("slice2 bab").assertIsDisplayed()+        assertEquals(1, clicked)+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialExtraTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialExtraTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialExtraTest.ktnew file mode 100644index 0000000000..6070114b0e--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialExtraTest.kt@@ -0,0 +1,306 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.runtime.mutableStateOf+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasText+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Slice 2/3 (library/ui): sweep over MaterialComponentsExtra delegates —+ * theme entry, exposed menus, drawer item, bottom bars, sheets, FAB+ * variants, toolbars, nav suite, button group, tab rows, search input.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2MaterialExtraTest {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `material theme entry renders content`() {+        rule.setContent {+            MaterialTheme {+                Text("slice2 themed")+            }+        }+        rule.onNodeWithText("slice2 themed").assertIsDisplayed()+    }++    @Test+    fun `dynamic theme renders in both modes`() {+        rule.setContent {+            Column {+                DynamicTheme(darkTheme = true) {+                    Text("slice2 dark")+                }+                DynamicTheme(darkTheme = false) {+                    Text("slice2 light")+                }+            }+        }+        rule.onNodeWithText("slice2 dark").assertIsDisplayed()+        rule.onNodeWithText("slice2 light").assertIsDisplayed()+    }++    @Test+    fun `exposed menu selects an option`() {+        val expanded = mutableStateOf(false)+        val selected = mutableStateOf("X")+        rule.setContent {+            ExposedDropdownMenuBox(expanded = expanded.value, onExpandedChange = { expanded.value = it }) {+                OutlinedTextField(+                    value = selected.value,+                    onValueChange = {},+                    readOnly = true,+                    label = { Text("slice2 exposed") },+                    modifier = Modifier+                        .menuAnchor(ExposedDropdownMenuAnchorType.PrimaryNotEditable)+                        .testTag("slice2 exposed field"),+                )+                ExposedDropdownMenu(expanded = expanded.value, onDismissRequest = { expanded.value = false }) {+                    DropdownMenuItem(+                        text = { Text("slice2 opt Y") },+                        onClick = { selected.value = "Y"; expanded.value = false },+                    )+                }+            }+        }+        rule.onNodeWithText("X").performClick()+        rule.waitUntil(timeoutMillis = 5_000) {+            rule.onAllNodes(hasText("slice2 opt Y")).fetchSemanticsNodes().isNotEmpty()+        }+        rule.onNodeWithText("slice2 opt Y").performClick()+        assertEquals("Y", selected.value)+    }++    @Test+    fun `navigation drawer item fires`() {+        var clicked = 0+        rule.setContent {+            NavigationDrawerItem(+                label = { Text("slice2 nav drawer") },+                selected = false,+                onClick = { clicked++ },+            )+        }+        rule.onNodeWithText("slice2 nav drawer").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `bottom bars render content`() {+        rule.setContent {+            Column {+                BottomAppBar { Text("slice2 bottom bar") }+                CompactBottomAppBar { Text("slice2 compact bar") }+                FlexibleBottomAppBar { Text("slice2 flex bar") }+            }+        }+        rule.onNodeWithText("slice2 bottom bar").assertIsDisplayed()+        rule.onNodeWithText("slice2 compact bar").assertIsDisplayed()+        rule.onNodeWithText("slice2 flex bar").assertIsDisplayed()+    }++    @Test+    fun `modal bottom sheet renders and dismisses`() {+        var dismissed = 0+        rule.setContent {+            ModalBottomSheet(onDismissRequest = { dismissed++ }) {+                Text("slice2 sheet body")+            }+        }+        rule.onNodeWithText("slice2 sheet body").assertIsDisplayed()+        assertEquals(0, dismissed)+    }++    @Test+    fun `bottom sheet scaffold renders sheet and content`() {+        rule.setContent {+            BottomSheetScaffold(+                sheetContent = { Text("slice2 bs sheet") },+            ) {+                Text("slice2 bs body")+            }+        }+        rule.onNodeWithText("slice2 bs body").assertIsDisplayed()+    }++    @Test+    fun `extended and small fabs fire`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                ExtendedFloatingActionButton(onClick = { clicks += "e" }) { Text("slice2 ext fab") }+                ExtendedFloatingActionButton(+                    text = { Text("slice2 ext fab2") },+                    icon = { IconAdd() },+                    onClick = { clicks += "e2" },+                )+                SmallFloatingActionButton(+                    onClick = { clicks += "s" },+                    modifier = Modifier.testTag("slice2 small fab"),+                ) { IconAdd() }+            }+        }+        rule.onNodeWithText("slice2 ext fab").performClick()+        rule.onNodeWithText("slice2 ext fab2", useUnmergedTree = true).performClick()+        rule.onNodeWithTag("slice2 small fab").performClick()+        assertEquals(listOf("e", "e2", "s"), clicks)+    }++    @Test+    fun `toggle button and toggle fab flip`() {+        val seen = mutableListOf<Boolean>()+        rule.setContent {+            Column {+                ToggleButton(checked = false, onCheckedChange = { seen += it }) {+                    Text("slice2 toggle")+                }+                ToggleFloatingActionButton(+                    checked = true,+                    onCheckedChange = { seen += it },+                    modifier = Modifier.testTag("slice2 toggle fab"),+                ) {+                    IconAdd()+                }+            }+        }+        rule.onNodeWithText("slice2 toggle").performClick()+        rule.onNodeWithTag("slice2 toggle fab").performClick()+        assertEquals(listOf(true, false), seen)+    }++    @Test+    fun `fab menu item fires`() {+        var item = 0+        var fab = 0+        rule.setContent {+            FloatingActionButtonMenu(+                expanded = true,+                button = {+                    SmallFloatingActionButton(+                        onClick = { fab++ },+                        modifier = Modifier.testTag("slice2 menu fab"),+                    ) { IconAdd() }+                },+            ) {+                FloatingActionButtonMenuItem(+                    onClick = { item++ },+                    text = { Text("slice2 menu item") },+                    icon = { IconAdd() },+                )+            }+        }+        rule.onNodeWithText("slice2 menu item").performClick()+        assertEquals(1, item)+        assertEquals(0, fab)+    }++    @Test+    fun `vertical toolbar renders fab and actions`() {+        var primary = 0+        rule.setContent {+            VerticalFloatingToolbar(+                floatingActionButton = {+                    SmallFloatingActionButton(+                        onClick = { primary++ },+                        modifier = Modifier.testTag("slice2 toolbar fab"),+                    ) { IconAdd() }+                },+            ) {+                Text("slice2 toolbar action")+            }+        }+        rule.onNodeWithText("slice2 toolbar action").assertIsDisplayed()+        rule.onNodeWithTag("slice2 toolbar fab").performClick()+        assertEquals(1, primary)+    }++    @Test+    fun `short nav bar selects`() {+        var picked = -1+        rule.setContent {+            ShortNavigationBar {+                ShortNavigationBarItem(+                    selected = false,+                    onClick = { picked = 0 },+                    icon = { IconAdd() },+                    label = { Text("slice2 short a") },+                )+            }+        }+        rule.onNodeWithText("slice2 short a").performClick()+        assertEquals(0, picked)+    }++    @Test+    fun `tab row variants select`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                TabRow(selectedTabIndex = 0) {+                    Tab(selected = true, onClick = { clicks += "t" }, text = { Text("slice2 extra tab") })+                }+                SecondaryTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "s" }, text = { Text("slice2 extra tab s") })+                }+                PrimaryTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "p" }, text = { Text("slice2 extra tab p") })+                }+                PrimaryScrollableTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "ps" }, text = { Text("slice2 extra tab ps") })+                }+            }+        }+        rule.onNodeWithText("slice2 extra tab").performClick()+        rule.onNodeWithText("slice2 extra tab s").performClick()+        rule.onNodeWithText("slice2 extra tab p").performClick()+        rule.onNodeWithText("slice2 extra tab ps").performClick()+        assertEquals(listOf("t", "s", "p", "ps"), clicks)+    }++    @Test+    fun `search input field edits and searches`() {+        var query = ""+        var searched = ""+        rule.setContent {+            SearchBarInputField(+                query = query,+                onQueryChange = { query = it },+                onSearch = { searched = it },+                expanded = false,+                onExpandedChange = {},+                placeholder = { Text("slice2 input ph") },+            )+        }+        rule.onNodeWithText("slice2 input ph").assertIsDisplayed()+        rule.onNodeWithText("slice2 input ph").performTextInput("q")+        assertEquals("q", query)+        assertEquals("", searched)+    }++    @Test+    fun `button group renders`() {+        // Item-level APIs (clickableItem/toggleableItem) are covered by their+        // Material defaults here; the wrapper itself just renders the row.+        // Empty, so it has no size: it exists in the tree but is not displayed.+        // Fetching the node asserts it composed without crashing.+        rule.setContent {+            ButtonGroup(modifier = Modifier.testTag("slice2 group")) {+            }+        }+        rule.onNodeWithTag("slice2 group").fetchSemanticsNode()+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialStateTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialStateTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialStateTest.ktnew file mode 100644index 0000000000..00ffa5e506--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialStateTest.kt@@ -0,0 +1,150 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.unit.dp+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotNull+import kotlin.test.assertTrue++/**+ * Slice 2/3 (library/ui): the MaterialFunctions state factories and helpers —+ * each creates the state it promises with the requested initial values.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2MaterialStateTest {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `drawer state opens and closes`() {+        var opened = false+        rule.setContent {+            val drawer = rememberDrawerState(initialValue = DrawerValue.Closed)+            opened = drawer.isOpen+            Column {+                Text(if (drawer.isClosed) "slice2 shut" else "slice2 open")+            }+        }+        rule.onNodeWithText("slice2 shut").assertIsDisplayed()+        assertEquals(false, opened)+    }++    @Test+    fun `time picker state carries its initials`() {+        rule.setContent {+            val state = rememberTimePickerState(initialHour = 7, initialMinute = 45)+            assertTrue(state.hour == 7 && state.minute == 45)+            Column {+                TimePicker(state = state)+                Text("slice2 time tail")+            }+        }+        rule.onNodeWithText("slice2 time tail").assertIsDisplayed()+    }++    @Test+    fun `date picker states build and render`() {+        rule.setContent {+            val single = rememberDatePickerState(initialSelectedDateMillis = 2_000_000L)+            val range = rememberDateRangePickerState(+                initialSelectedStartDateMillis = 1_000_000L,+                initialSelectedEndDateMillis = 3_000_000L,+            )+            assertNotNull(single)+            assertNotNull(range)+            Column {+                DatePicker(state = single, modifier = Modifier.testTag("slice2 state dp"))+            }+        }+        rule.onNodeWithTag("slice2 state dp").assertIsDisplayed()+    }++    @Test+    fun `bottom sheet states build with defaults`() {+        rule.setContent {+            val sheet = rememberBottomSheetState()+            val modal = rememberModalBottomSheetState(skipPartiallyExpanded = true)+            val scaffold = rememberBottomSheetScaffoldState()+            val scaffold2 = rememberBottomSheetScaffoldState(bottomSheetState = sheet)+            assertNotNull(sheet)+            assertNotNull(modal)+            assertNotNull(scaffold)+            assertNotNull(scaffold2)+            Column {+                Text("slice2 sheet tail")+            }+        }+        rule.onNodeWithText("slice2 sheet tail").assertIsDisplayed()+    }++    @Test+    fun `slider and swipe states build`() {+        rule.setContent {+            val slider = rememberSliderState(value = 0.4f, steps = 3, valueRange = 0f..2f)+            val swipe = rememberSwipeToDismissBoxState()+            assertEquals(0.4f, slider.value)+            assertNotNull(swipe)+            Column {+                Text("slice2 misc tail")+            }+        }+        rule.onNodeWithText("slice2 misc tail").assertIsDisplayed()+    }++    @Test+    fun `scroll behavior matches the bar size`() {+        rule.setContent {+            val small = appBarScrollBehavior(AppBarSize.Small)+            val medium = appBarScrollBehavior(AppBarSize.MediumFlexible)+            val large = appBarScrollBehavior(AppBarSize.LargeFlexible)+            assertNotNull(small)+            assertNotNull(medium)+            assertNotNull(large)+            Column {+                Text("slice2 scroll tail")+            }+        }+        rule.onNodeWithText("slice2 scroll tail").assertIsDisplayed()+    }++    @Test+    fun `compact touch targets render content and stay clickable`() {+        var clicked = 0+        rule.setContent {+            CompactTouchTargets(size = 40.dp) {+                TextButton(+                    onClick = { clicked++ },+                    modifier = Modifier.testTag("slice2 compact"),+                ) {+                    Text("slice2 compact btn")+                }+            }+        }+        rule.onNodeWithText("slice2 compact btn").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `adaptive info is available`() {+        rule.setContent {+            val info = currentWindowAdaptiveInfo()+            assertNotNull(info)+            Column {+                Text("slice2 adaptive tail")+            }+        }+        rule.onNodeWithText("slice2 adaptive tail").assertIsDisplayed()+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweep2Test.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweep2Test.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweep2Test.ktnew file mode 100644index 0000000000..e50217540e--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweep2Test.kt@@ -0,0 +1,349 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Slice 2/3 (library/ui): material wrapper sweep, batch 2 — scaffold,+ * app bars, navigation, drawers, menus, dialogs, pickers, badges, tabs,+ * refresh, search.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2MaterialSweep2Test {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `scaffold renders bars fab and content`() {+        var fab = 0+        rule.setContent {+            Scaffold(+                topBar = { TopAppBar(title = { Text("slice2 top") }) },+                bottomBar = { Text("slice2 bottom") },+                floatingActionButton = {+                    FloatingActionButton(onClick = { fab++ }, modifier = Modifier.testTag("slice2 fab2")) {+                        Text("F")+                    }+                },+                snackbarHost = {},+            ) {+                Text("slice2 body")+            }+        }+        rule.onNodeWithText("slice2 top").assertIsDisplayed()+        rule.onNodeWithText("slice2 bottom").assertIsDisplayed()+        rule.onNodeWithText("slice2 body").assertIsDisplayed()+        rule.onNodeWithTag("slice2 fab2").performClick()+        assertEquals(1, fab)+    }++    @Test+    fun `app bars render titles and actions`() {+        var acted = 0+        rule.setContent {+            Column {+                TopAppBar(title = { Text("slice2 small") })+                CenterAlignedTopAppBar(title = { Text("slice2 center") })+                MediumFlexibleTopAppBar(title = { Text("slice2 medium") })+                LargeFlexibleTopAppBar(+                    title = { Text("slice2 large") },+                    actions = {+                        IconButton(onClick = { acted++ }, modifier = Modifier.testTag("slice2 bar act")) {+                            IconAdd()+                        }+                    },+                )+            }+        }+        rule.onNodeWithText("slice2 small").assertIsDisplayed()+        rule.onNodeWithText("slice2 center").assertIsDisplayed()+        rule.onNodeWithText("slice2 medium").assertIsDisplayed()+        rule.onNodeWithText("slice2 large").assertIsDisplayed()+        rule.onNodeWithTag("slice2 bar act").performClick()+        assertEquals(1, acted)+    }++    @Test+    fun `navigation bar selects`() {+        var picked = -1+        rule.setContent {+            NavigationBar {+                NavigationBarItem(+                    selected = true,+                    onClick = { picked = 0 },+                    icon = { IconAdd() },+                    label = { Text("slice2 nav a") },+                )+                NavigationBarItem(+                    selected = false,+                    onClick = { picked = 1 },+                    icon = { IconAdd() },+                    label = { Text("slice2 nav b") },+                )+            }+        }+        rule.onNodeWithText("slice2 nav b").performClick()+        assertEquals(1, picked)+    }++    @Test+    fun `navigation rail selects`() {+        var picked = -1+        rule.setContent {+            NavigationRail {+                NavigationRailItem(+                    selected = false,+                    onClick = { picked = 0 },+                    icon = { IconAdd() },+                    label = { Text("slice2 rail a") },+                )+            }+        }+        rule.onNodeWithText("slice2 rail a").performClick()+        assertEquals(0, picked)+    }++    @Test+    fun `modal drawer renders content and drawer sheet`() {+        rule.setContent {+            ModalNavigationDrawer(+                drawerContent = {+                    ModalDrawerSheet {+                        Text("slice2 drawer item")+                    }+                },+            ) {+                Text("slice2 drawer body")+            }+        }+        rule.onNodeWithText("slice2 drawer body").assertIsDisplayed()+    }++    @Test+    fun `dropdown menu items fire`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            DropdownMenu(expanded = true, onDismissRequest = {}) {+                DropdownMenuItem(text = { Text("slice2 menu a") }, onClick = { clicks += "a" })+                SelectableDropdownMenuItem(+                    selected = true,+                    onClick = { clicks += "s" },+                    text = { Text("slice2 menu sel") },+                )+                CheckableDropdownMenuItem(+                    checked = false,+                    onCheckedChange = { clicks += "c$it" },+                    text = { Text("slice2 menu chk") },+                )+            }+        }+        rule.onNodeWithText("slice2 menu a").performClick()+        rule.onNodeWithText("slice2 menu sel").performClick()+        rule.onNodeWithText("slice2 menu chk").performClick()+        assertEquals(listOf("a", "s", "ctrue"), clicks)+    }++    @Test+    fun `alert dialog confirms and dismisses`() {+        var confirmed = 0+        var dismissed = 0+        rule.setContent {+            AlertDialog(+                onDismissRequest = { dismissed++ },+                confirmButton = {+                    TextButton(onClick = { confirmed++ }) { Text("slice2 confirm") }+                },+                dismissButton = {+                    TextButton(onClick = { dismissed++ }) { Text("slice2 dismiss") }+                },+                title = { Text("slice2 alert") },+                text = { Text("slice2 alert body") },+            )+        }+        rule.onNodeWithText("slice2 alert").assertIsDisplayed()+        rule.onNodeWithText("slice2 confirm").performClick()+        rule.onNodeWithText("slice2 dismiss").performClick()+        assertEquals(1, confirmed)+        assertEquals(1, dismissed)+    }++    @Test+    fun `date and time pickers render with remembered state`() {+        rule.setContent {+            Column {+                val dateState = rememberDatePickerState(initialSelectedDateMillis = 1_000_000L)+                DatePicker(state = dateState, modifier = Modifier.testTag("slice2 dp"))+                val rangeState = rememberDateRangePickerState()+                DateRangePicker(state = rangeState, modifier = Modifier.testTag("slice2 drp"))+                val timeState = rememberTimePickerState(initialHour = 9, initialMinute = 30)+                TimePicker(state = timeState, modifier = Modifier.testTag("slice2 tp"))+                assertTrue(timeState.hour == 9 && timeState.minute == 30)+            }+        }+        rule.onNodeWithTag("slice2 dp").assertIsDisplayed()+        // The clock face composes (fetch proves it) but overflows the test+        // viewport, so it is not "displayed".+        rule.onNodeWithTag("slice2 tp").fetchSemanticsNode()+    }++    @Test+    fun `material date picker dialog confirms`() {+        var confirmed = 0+        var dismissed = 0+        rule.setContent {+            val dateState = rememberDatePickerState(initialSelectedDateMillis = 1_000_000L)+            DatePickerDialog(+                onDismissRequest = { dismissed++ },+                confirmButton = {+                    TextButton(onClick = { confirmed++ }) { Text("slice2 dp ok") }+                },+            ) {+                DatePicker(state = dateState)+            }+        }+        rule.onNodeWithText("slice2 dp ok").performClick()+        assertEquals(1, confirmed)+        assertEquals(0, dismissed)+    }++    @Test+    fun `badge and badged box render`() {+        rule.setContent {+            Column {+                BadgedBox(badge = { Badge { Text("3") } }) {+                    Text("slice2 badged")+                }+                Badge { Text("slice2 bare badge") }+            }+        }+        rule.onNodeWithText("slice2 badged").assertIsDisplayed()+        rule.onNodeWithText("3").assertIsDisplayed()+    }++    @Test+    fun `tabs select across all row variants`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                TabRow(selectedTabIndex = 0) {+                    Tab(selected = true, onClick = { clicks += "r" }, text = { Text("slice2 tab r") })+                }+                SecondaryTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "s" }, text = { Text("slice2 tab s") })+                }+                PrimaryTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "p" }, content = { Text("slice2 tab p") })+                }+                PrimaryScrollableTabRow(selectedTabIndex = 0) {+                    Tab(selected = false, onClick = { clicks += "ps" }, text = { Text("slice2 tab ps") })+                }+            }+        }+        rule.onNodeWithText("slice2 tab r").performClick()+        rule.onNodeWithText("slice2 tab s").performClick()+        rule.onNodeWithText("slice2 tab p").performClick()+        rule.onNodeWithText("slice2 tab ps").performClick()+        assertEquals(listOf("r", "s", "p", "ps"), clicks)+    }++    @Test+    fun `pull to refresh renders content and indicator`() {+        var refreshed = 0+        rule.setContent {+            PullToRefreshBox(isRefreshing = false, onRefresh = { refreshed++ }) {+                Text("slice2 refresh body")+            }+        }+        rule.onNodeWithText("slice2 refresh body").assertIsDisplayed()+        assertEquals(0, refreshed)+    }++    @Test+    fun `search bar renders input and content when expanded`() {+        var query = ""+        var expanded = true+        rule.setContent {+            SearchBar(+                inputField = {+                    SearchBarInputField(+                        query = query,+                        onQueryChange = { query = it },+                        onSearch = {},+                        expanded = expanded,+                        onExpandedChange = { expanded = it },+                        placeholder = { Text("slice2 search ph") },+                    )+                },+                expanded = expanded,+                onExpandedChange = { expanded = it },+            ) {+                Text("slice2 search result")+            }+        }+        rule.onNodeWithText("slice2 search ph").assertIsDisplayed()+        rule.onNodeWithText("slice2 search result").assertIsDisplayed()+    }++    @Test+    fun `snackbar host renders`() {+        rule.setContent {+            Column {+                val host = androidx.compose.material3.SnackbarHostState()+                SnackbarHost(hostState = host)+                Text("slice2 snackbar tail")+            }+        }+        rule.onNodeWithText("slice2 snackbar tail").assertIsDisplayed()+    }++    @Test+    fun `provide text style applies to content`() {+        rule.setContent {+            ProvideTextStyle(value = androidx.compose.material3.MaterialTheme.typography.bodyLarge) {+                Text("slice2 styled")+            }+        }+        rule.onNodeWithText("slice2 styled").assertIsDisplayed()+    }++    @Test+    fun `segmented row scope and swipe box render`() {+        rule.setContent {+            Column {+                val swipe = rememberSwipeToDismissBoxState()+                SwipeToDismissBox(+                    state = swipe,+                    backgroundContent = { Text("slice2 bg") },+                    modifier = Modifier.testTag("slice2 swipe"),+                ) {+                    Text("slice2 fg")+                }+            }+        }+        rule.onNodeWithText("slice2 fg").assertIsDisplayed()+    }++    @Test+    fun `slider state overload renders`() {+        rule.setContent {+            Column {+                val sliderState = rememberSliderState(value = 0.5f)+                Slider(state = sliderState, onValueChange = {}, modifier = Modifier.testTag("slice2 slider"))+            }+        }+        rule.onNodeWithTag("slice2 slider").assertIsDisplayed()+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweepTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweepTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweepTest.ktnew file mode 100644index 0000000000..488601f6ec--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/Slice2MaterialSweepTest.kt@@ -0,0 +1,281 @@+package com.vayunmathur.library.ui++import androidx.compose.foundation.layout.Column+import androidx.compose.material.icons.Icons+import androidx.compose.material.icons.filled.Add+import androidx.compose.ui.Modifier+import androidx.compose.ui.platform.testTag+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasContentDescription+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithTag+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.compose.ui.test.performTextInput+import androidx.compose.ui.text.AnnotatedString+import androidx.compose.ui.unit.dp+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Slice 2/3 (library/ui): sweep over the thin Material 3 wrapper delegates —+ * each renders through to Material and forwards its handlers. Batch 1: text,+ * icon, buttons, surfaces, cards, chips, selection controls, dividers,+ * progress, sliders, fields.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2MaterialSweepTest {++    @get:Rule+    val rule = createComposeRule()++    @Test+    fun `text renders both string and annotated forms`() {+        rule.setContent {+            Column {+                Text("slice2 plain")+                Text(AnnotatedString("slice2 annotated"))+            }+        }+        rule.onNodeWithText("slice2 plain").assertIsDisplayed()+        rule.onNodeWithText("slice2 annotated").assertIsDisplayed()+    }++    @Test+    fun `icon renders from an image vector`() {+        rule.setContent {+            Icon(Icons.Filled.Add, contentDescription = "slice2 plus")+        }+        rule.onNodeWithContentDescription("slice2 plus").assertIsDisplayed()+    }++    @Test+    fun `icon buttons fire`() {+        var plain = 0+        var filled = 0+        var tonal = 0+        rule.setContent {+            Column {+                IconButton(onClick = { plain++ }, modifier = Modifier.testTag("slice2 icon plain")) { IconAdd() }+                FilledIconButton(onClick = { filled++ }, modifier = Modifier.testTag("slice2 icon filled")) { IconAdd() }+                FilledTonalIconButton(onClick = { tonal++ }, modifier = Modifier.testTag("slice2 icon tonal")) { IconAdd() }+            }+        }+        rule.onNodeWithTag("slice2 icon plain").performClick()+        rule.onNodeWithTag("slice2 icon filled").performClick()+        rule.onNodeWithTag("slice2 icon tonal").performClick()+        assertEquals(1, plain)+        assertEquals(1, filled)+        assertEquals(1, tonal)+    }++    @Test+    fun `buttons fire and show their labels`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                Button(onClick = { clicks += "b" }) { Text("slice2 button") }+                OutlinedButton(onClick = { clicks += "o" }) { Text("slice2 outlined") }+                TextButton(onClick = { clicks += "t" }) { Text("slice2 textbtn") }+                FilledTonalButton(onClick = { clicks += "f" }) { Text("slice2 tonal") }+            }+        }+        rule.onNodeWithText("slice2 button").performClick()+        rule.onNodeWithText("slice2 outlined").performClick()+        rule.onNodeWithText("slice2 textbtn").performClick()+        rule.onNodeWithText("slice2 tonal").performClick()+        assertEquals(listOf("b", "o", "t", "f"), clicks)+    }++    @Test+    fun `fab fires and shows its content`() {+        var clicked = 0+        rule.setContent {+            FloatingActionButton(onClick = { clicked++ }) { Text("slice2 fab") }+        }+        rule.onNodeWithText("slice2 fab").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `surfaces render content and the clickable one fires`() {+        var clicked = 0+        rule.setContent {+            Column {+                Surface { Text("slice2 surface") }+                Surface(onClick = { clicked++ }) { Text("slice2 clickable") }+            }+        }+        rule.onNodeWithText("slice2 surface").assertIsDisplayed()+        rule.onNodeWithText("slice2 clickable").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `cards render content and the clickable ones fire`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                Card { Text("slice2 card") }+                Card(onClick = { clicks += "c" }) { Text("slice2 card click") }+                ElevatedCard { Text("slice2 elevated") }+                ElevatedCard(onClick = { clicks += "e" }) { Text("slice2 elevated click") }+                OutlinedCard { Text("slice2 outlined card") }+            }+        }+        rule.onNodeWithText("slice2 card").assertIsDisplayed()+        rule.onNodeWithText("slice2 elevated").assertIsDisplayed()+        rule.onNodeWithText("slice2 outlined card").assertIsDisplayed()+        rule.onNodeWithText("slice2 card click").performClick()+        rule.onNodeWithText("slice2 elevated click").performClick()+        assertEquals(listOf("c", "e"), clicks)+    }++    @Test+    fun `chips fire and show their labels`() {+        val clicks = mutableListOf<String>()+        rule.setContent {+            Column {+                InputChip(selected = true, onClick = { clicks += "i" }, label = { Text("slice2 input") })+                FilterChip(selected = false, onClick = { clicks += "f" }, label = { Text("slice2 filter") })+                AssistChip(onClick = { clicks += "a" }, label = { Text("slice2 assist") })+            }+        }+        rule.onNodeWithText("slice2 input").performClick()+        rule.onNodeWithText("slice2 filter").performClick()+        rule.onNodeWithText("slice2 assist").performClick()+        assertEquals(listOf("i", "f", "a"), clicks)+    }++    @Test+    fun `checkbox switch and radio forward their toggles`() {+        val seen = mutableListOf<Boolean>()+        rule.setContent {+            Column {+                Checkbox(checked = false, onCheckedChange = { seen += it ?: false }, modifier = Modifier.testTag("slice2 check"))+                Switch(checked = true, onCheckedChange = { seen += it }, modifier = Modifier.testTag("slice2 switch"))+                RadioButton(selected = false, onClick = { seen += true }, modifier = Modifier.testTag("slice2 radio"))+            }+        }+        rule.onNodeWithTag("slice2 check").performClick()+        rule.onNodeWithTag("slice2 switch").performClick()+        rule.onNodeWithTag("slice2 radio").performClick()+        assertEquals(listOf(true, false, true), seen)+    }++    @Test+    fun `tri-state checkbox fires`() {+        var clicked = 0+        rule.setContent {+            TriStateCheckbox(+                state = androidx.compose.ui.state.ToggleableState.Indeterminate,+                onClick = { clicked++ },+                modifier = Modifier.testTag("slice2 tri"),+            )+        }+        rule.onNodeWithTag("slice2 tri").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `dividers render between content`() {+        rule.setContent {+            Column {+                Text("slice2 above")+                HorizontalDivider()+                Text("slice2 below")+                VerticalDivider()+            }+        }+        rule.onNodeWithText("slice2 above").assertIsDisplayed()+        rule.onNodeWithText("slice2 below").assertIsDisplayed()+    }++    @Test+    fun `progress indicators render`() {+        rule.setContent {+            Column {+                CircularProgressIndicator()+                CircularProgressIndicator(progress = { 0.5f })+                LinearProgressIndicator()+                LinearProgressIndicator(progress = { 0.25f })+                LoadingIndicator()+                LoadingIndicator(progress = { 0.75f })+                ContainedLoadingIndicator()+                ContainedLoadingIndicator(progress = { 0.1f })+                Text("slice2 progress tail")+            }+        }+        rule.onNodeWithText("slice2 progress tail").assertIsDisplayed()+    }++    @Test+    fun `sliders render and report changes`() {+        var value = 0f+        var range = 0f..1f+        var stateValue = -1f+        rule.setContent {+            Column {+                Slider(value = value, onValueChange = { value = it })+                RangeSlider(value = range, onValueChange = { range = it })+                val sliderState = rememberSliderState(value = 0.3f)+                Slider(state = sliderState, onValueChange = { stateValue = it })+                Text("slice2 sliders tail")+            }+        }+        rule.onNodeWithText("slice2 sliders tail").assertIsDisplayed()+    }++    @Test+    fun `text fields edit both string and value forms`() {+        var s = ""+        var filled = androidx.compose.ui.text.input.TextFieldValue("a")+        var outlined = androidx.compose.ui.text.input.TextFieldValue("b")+        rule.setContent {+            Column {+                OutlinedTextField(value = s, onValueChange = { s = it }, label = { Text("slice2 out") })+                TextField(value = s, onValueChange = { s = it }, label = { Text("slice2 filled") })+                OutlinedTextField(value = outlined, onValueChange = { outlined = it }, label = { Text("slice2 out v") })+                TextField(value = filled, onValueChange = { filled = it }, label = { Text("slice2 filled v") })+            }+        }+        rule.onNodeWithText("slice2 out").performTextInput("x")+        assertEquals("x", s)+    }++    @Test+    fun `segmented row selects`() {+        var clicked = 0+        rule.setContent {+            SingleChoiceSegmentedButtonRow {+                SegmentedButton(+                    selected = true,+                    onClick = { clicked++ },+                    shape = androidx.compose.material3.SegmentedButtonDefaults.itemShape(0, 2),+                    label = { Text("slice2 seg") },+                )+            }+        }+        rule.onNodeWithText("slice2 seg").performClick()+        assertEquals(1, clicked)+    }++    @Test+    fun `list items render both overloads`() {+        var clicked = 0+        rule.setContent {+            Column {+                ListItem(headlineContent = { Text("slice2 headline") })+                ListItem(content = { Text("slice2 interactive") })+                ListItem(headlineContent = { Text("slice2 unused") }, tonalElevation = 0.dp, shadowElevation = 0.dp)+            }+        }+        rule.onNodeWithText("slice2 headline").assertIsDisplayed()+        rule.onNodeWithText("slice2 interactive").assertIsDisplayed()+        assertEquals(0, clicked)+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DateSelectionTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DateSelectionTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DateSelectionTest.ktnew file mode 100644index 0000000000..ef1553be32--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DateSelectionTest.kt@@ -0,0 +1,28 @@+package com.vayunmathur.library.ui.dialog++import kotlinx.datetime.LocalDate+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertNotEquals++/**+ * Slice 2/3 (library/ui): [DateSelection] value semantics — the clearable+ * date dialog's result wrapper compares by its date.+ */+class Slice2DateSelectionTest {++    @Test+    fun `empty and dated selections differ`() {+        assertEquals(DateSelection(null), DateSelection(null))+        assertNotEquals(DateSelection(null), DateSelection(LocalDate(2026, 11, 6)))+        assertEquals(DateSelection(LocalDate(2026, 11, 6)), DateSelection(LocalDate(2026, 11, 6)))+    }++    @Test+    fun `the date is readable and copies`() {+        val selection = DateSelection(LocalDate(2026, 11, 6))+        assertEquals(LocalDate(2026, 11, 6), selection.date)+        assertEquals(DateSelection(null), selection.copy(date = null))+        assertEquals(selection.hashCode(), DateSelection(LocalDate(2026, 11, 6)).hashCode())+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DialogComposeTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DialogComposeTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DialogComposeTest.ktnew file mode 100644index 0000000000..42704e969e--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/dialog/Slice2DialogComposeTest.kt@@ -0,0 +1,243 @@+package com.vayunmathur.library.ui.dialog++import androidx.compose.runtime.CompositionLocalProvider+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.ui.R as UiR+import com.vayunmathur.library.util.LocalNavResultRegistry+import com.vayunmathur.library.util.NavBackStack+import com.vayunmathur.library.util.NavKey+import com.vayunmathur.library.util.NavResultRegistry+import kotlinx.datetime.LocalDate+import kotlinx.datetime.LocalTime+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Slice 2/3 (library/ui): the shared date/time pickers — confirm delivers+ * the picked value through the result registry and pops the stack; cancel+ * and dismiss pop without delivering; Clear delivers an empty [DateSelection].+ */+@RunWith(RobolectricTestRunner::class)+class Slice2DialogComposeTest {++    @get:Rule+    val rule = createComposeRule()++    private val appContext: android.content.Context+        get() = ApplicationProvider.getApplicationContext()++    private object Slice2Key : NavKey++    private fun backStack() = NavBackStack(arrayOf<NavKey>(Slice2Key))++    // --- DatePickerDialog -------------------------------------------------++    @Test+    fun `confirming the date delivers a LocalDate and pops`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = "unset"+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-date") { delivered = it }+                DatePickerDialog(+                    backStack = stack,+                    resultKey = "slice2-date",+                    initialDate = LocalDate(2026, 11, 6),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).assertIsDisplayed()+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).performClick()+        // Delivery is a launched coroutine; waitUntil pumps the main thread so it runs.+        rule.waitUntil(timeoutMillis = 10_000) { delivered != "unset" }+        val date = delivered+        assertTrue(date is LocalDate, "expected a LocalDate, got $date")+        assertEquals(LocalDate(2026, 11, 6), date)+        assertTrue(stack.backStack.isEmpty(), "confirm must pop the dialog")+    }++    @Test+    fun `cancel pops without delivering`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered = false+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-date-cancel") { delivered = true }+                DatePickerDialog(+                    backStack = stack,+                    resultKey = "slice2-date-cancel",+                    initialDate = LocalDate(2026, 11, 6),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.cancel)).performClick()+        rule.waitForIdle()+        assertTrue(stack.backStack.isEmpty())+        assertEquals(false, delivered)+    }++    @Test+    fun `clear delivers an empty selection`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = null+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-date-clear") { delivered = it }+                DatePickerDialog(+                    backStack = stack,+                    resultKey = "slice2-date-clear",+                    initialDate = LocalDate(2026, 11, 6),+                    allowClear = true,+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.clear)).assertIsDisplayed()+        rule.onNodeWithText(appContext.getString(UiR.string.clear)).performClick()+        rule.waitUntil(timeoutMillis = 10_000) { delivered != null }+        assertEquals(DateSelection(null), delivered)+        assertTrue(stack.backStack.isEmpty())+    }++    @Test+    fun `a min date disables confirm for an earlier selection`() {+        // initialDate == minDate here: confirm stays enabled (documents the+        // boundary rather than the disabled path, which needs a day click).+        val stack = backStack()+        val registry = NavResultRegistry()+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                DatePickerDialog(+                    backStack = stack,+                    resultKey = "slice2-date-min",+                    initialDate = LocalDate(2026, 11, 6),+                    minDate = LocalDate(2026, 11, 6),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).assertIsDisplayed()+    }++    // --- TimePickerDialogContent --------------------------------------------++    @Test+    fun `confirming the time delivers a LocalTime and pops`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = null+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-time") { delivered = it }+                TimePickerDialogContent(+                    backStack = stack,+                    resultKey = "slice2-time",+                    initialTime = LocalTime(17, 30),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.time_picker_title)).assertIsDisplayed()+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).performClick()+        rule.waitUntil(timeoutMillis = 10_000) { delivered != null }+        assertEquals(LocalTime(17, 30), delivered)+        assertTrue(stack.backStack.isEmpty())+    }++    @Test+    fun `canceling the time pops without delivering`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered = false+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-time-cancel") { delivered = true }+                TimePickerDialogContent(+                    backStack = stack,+                    resultKey = "slice2-time-cancel",+                    initialTime = LocalTime(9, 0),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.cancel)).performClick()+        rule.waitForIdle()+        assertTrue(stack.backStack.isEmpty())+        assertEquals(false, delivered)+    }++    @Test+    fun `a future min time disables confirm`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = null+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-time-min") { delivered = it }+                TimePickerDialogContent(+                    backStack = stack,+                    resultKey = "slice2-time-min",+                    initialTime = LocalTime(17, 30),+                    minTime = LocalTime(18, 0),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).assertIsNotEnabled()+        assertEquals(null, delivered)+        assertEquals(1, stack.backStack.size)+    }++    @Test+    fun `a past min time leaves confirm enabled`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = null+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-time-min-ok") { delivered = it }+                TimePickerDialogContent(+                    backStack = stack,+                    resultKey = "slice2-time-min-ok",+                    initialTime = LocalTime(17, 30),+                    minTime = LocalTime(9, 0),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).assertIsEnabled()+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).performClick()+        rule.waitUntil(timeoutMillis = 10_000) { delivered != null }+        assertEquals(LocalTime(17, 30), delivered)+    }++    @Test+    fun `a max date still confirms inside the window`() {+        val stack = backStack()+        val registry = NavResultRegistry()+        var delivered: Any? = "unset"+        rule.setContent {+            CompositionLocalProvider(LocalNavResultRegistry provides registry) {+                com.vayunmathur.library.util.ResultEffect<Any>("slice2-date-max") { delivered = it }+                DatePickerDialog(+                    backStack = stack,+                    resultKey = "slice2-date-max",+                    initialDate = LocalDate(2026, 11, 6),+                    minDate = LocalDate(2026, 11, 1),+                    maxDate = LocalDate(2026, 11, 30),+                )+            }+        }+        rule.onNodeWithText(appContext.getString(UiR.string.ok)).performClick()+        rule.waitUntil(timeoutMillis = 10_000) { delivered != "unset" }+        assertEquals(LocalDate(2026, 11, 6), delivered)+        assertTrue(stack.backStack.isEmpty())+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameChromeTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameChromeTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameChromeTest.ktnew file mode 100644index 0000000000..9cf42d3213--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameChromeTest.kt@@ -0,0 +1,110 @@+package com.vayunmathur.library.ui.game++import androidx.compose.foundation.layout.Row+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.assertIsEnabled+import androidx.compose.ui.test.assertIsNotEnabled+import androidx.compose.ui.test.hasContentDescription+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithContentDescription+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.ui.R as UiR+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals++/**+ * Slice 2/3 (library/ui): the game chrome interactions — top-bar actions and+ * the level picker's stepping arrows.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2GameChromeTest {++    @get:Rule+    val rule = createComposeRule()++    private val appContext: android.content.Context+        get() = ApplicationProvider.getApplicationContext()++    // --- GameTopBarActions ----------------------------------------------------++    @Test+    fun `achievements action is always present and fires`() {+        var opened = 0+        rule.setContent {+            Row { GameTopBarActions(onOpenGameCenter = { opened++ }) }+        }+        rule.onNodeWithContentDescription("Badges").assertIsDisplayed()+        rule.onNodeWithContentDescription("Badges").performClick()+        assertEquals(1, opened)+    }++    @Test+    fun `settings action shows only when its handler is given`() {+        var opened = 0+        rule.setContent {+            Row { GameTopBarActions(onOpenGameCenter = {}, onOpenSettings = { opened++ }) }+        }+        rule.onNodeWithContentDescription("Settings").assertIsDisplayed()+        rule.onNodeWithContentDescription("Settings").performClick()+        assertEquals(1, opened)+    }++    @Test+    fun `no settings action without its handler`() {+        rule.setContent {+            Row { GameTopBarActions(onOpenGameCenter = {}) }+        }+        rule.onNodeWithContentDescription("Badges").assertIsDisplayed()+        assertEquals(+            0,+            rule.onAllNodes(hasContentDescription("Settings")).fetchSemanticsNodes().size,+        )+    }++    // --- LevelPickerBox arrows --------------------------------------------------++    @Test+    fun `forward steps up and back steps down`() {+        val stepped = mutableListOf<Int>()+        rule.setContent {+            LevelPickerBox(levelIndex = 1, maxLevelIndex = 2, isCompleted = false, onLevelChange = stepped::add)+        }+        rule.onNodeWithContentDescription("Forward").assertIsEnabled()+        rule.onNodeWithContentDescription("Forward").performClick()+        rule.onNodeWithContentDescription("Back").performClick()+        assertEquals(listOf(2, 0), stepped)+    }++    @Test+    fun `arrows gate at the ends of the pack`() {+        val stepped = mutableListOf<Int>()+        rule.setContent {+            LevelPickerBox(levelIndex = 0, maxLevelIndex = 0, isCompleted = false, onLevelChange = stepped::add)+        }+        rule.onNodeWithContentDescription("Back").assertIsNotEnabled()+        rule.onNodeWithContentDescription("Forward").assertIsNotEnabled()+        assertEquals(emptyList(), stepped)+    }++    @Test+    fun `level number reads one higher than its index`() {+        rule.setContent {+            LevelPickerBox(levelIndex = 0, maxLevelIndex = 2, isCompleted = false, onLevelChange = {})+        }+        rule.onNodeWithText("1").assertIsDisplayed()+    }++    // --- DailyStreakText edge -----------------------------------------------------++    @Test+    fun `a negative streak clamps to zero`() {+        rule.setContent { DailyStreakText(streak = -5L) }+        val zero = appContext.resources.getQuantityString(UiR.plurals.game_daily_streak, 0, 0)+        rule.onNodeWithText(zero).assertIsDisplayed()+    }+}
library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt
diff --git a/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.ktnew file mode 100644index 0000000000..60a650c862--- /dev/null+++ b/library/ui/src/test/java/com/vayunmathur/library/ui/game/Slice2GameComposeTest.kt@@ -0,0 +1,179 @@+package com.vayunmathur.library.ui.game++import androidx.compose.runtime.getValue+import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.setValue+import androidx.compose.ui.test.assertIsDisplayed+import androidx.compose.ui.test.hasContentDescription+import androidx.compose.ui.test.hasText+import androidx.compose.ui.test.junit4.createComposeRule+import androidx.compose.ui.test.onNodeWithText+import androidx.compose.ui.test.performClick+import androidx.test.core.app.ApplicationProvider+import com.vayunmathur.library.ui.R as UiR+import org.junit.Rule+import org.junit.runner.RunWith+import org.robolectric.RobolectricTestRunner+import kotlin.test.Test+import kotlin.test.assertEquals+import kotlin.test.assertTrue++/**+ * Slice 2/3 (library/ui): the game chrome — hearts, streak, info boxes, mode+ * chooser, result overlay, challenge card and top-bar actions.+ */+@RunWith(RobolectricTestRunner::class)+class Slice2GameComposeTest {++    @get:Rule+    val rule = createComposeRule()++    private val appContext: android.content.Context+        get() = ApplicationProvider.getApplicationContext()++    // --- HeartsRow ----------------------------------------------------------++    @Test+    fun `hearts announce the remaining count as one description`() {+        rule.setContent { HeartsRow(remaining = 2, total = 3) }+        val desc = appContext.resources.getQuantityString(UiR.plurals.game_hearts_left, 2, 2)+        val nodes = rule.onAllNodes(hasContentDescription(desc)).fetchSemanticsNodes()+        assertEquals(1, nodes.size, "the row carries one merged description")+    }++    @Test+    fun `remaining clamps to the row`() {+        var remaining by mutableStateOf(99)+        rule.setContent { HeartsRow(remaining = remaining, total = 2) }+        val desc = appContext.resources.getQuantityString(UiR.plurals.game_hearts_left, 2, 2)+        assertTrue(+            rule.onAllNodes(hasContentDescription(desc)).fetchSemanticsNodes().isNotEmpty(),+        )+        remaining = -5+        rule.waitForIdle()+        val zero = appContext.resources.getQuantityString(UiR.plurals.game_hearts_left, 0, 0)+        assertTrue(+            rule.onAllNodes(hasContentDescription(zero)).fetchSemanticsNodes().isNotEmpty(),+        )+    }++    // --- DailyStreakText ------------------------------------------------------++    @Test+    fun `streak text pluralises`() {+        var streak by mutableStateOf(1L)+        rule.setContent { DailyStreakText(streak = streak) }+        val one = appContext.resources.getQuantityString(UiR.plurals.game_daily_streak, 1, 1)+        rule.onNodeWithText(one).assertIsDisplayed()+        streak = 5L+        rule.waitForIdle()+        val five = appContext.resources.getQuantityString(UiR.plurals.game_daily_streak, 5, 5)+        rule.onNodeWithText(five).assertIsDisplayed()+    }++    // --- GameInfoBox / LevelPickerBox / MovesBox -------------------------------++    @Test+    fun `info box shows its title and content`() {+        rule.setContent {+            GameInfoBox(title = "Slice2 Level") {+                androidx.compose.foundation.layout.Box {}+            }+        }+        rule.onNodeWithText("Slice2 Level").assertIsDisplayed()+    }++    @Test+    fun `level picker steps and gates its arrows`() {+        var level = 1+        rule.setContent {+            LevelPickerBox(levelIndex = level, maxLevelIndex = 2, isCompleted = true, onLevelChange = { level = it })+        }+        rule.onNodeWithText("2").assertIsDisplayed()+        rule.onNodeWithText(appContext.getString(UiR.string.game_completed)).assertIsDisplayed()+        assertEquals(1, level)+    }++    @Test+    fun `moves box dashes an unknown best`() {+        var bestScore: Int? by mutableStateOf<Int?>(null)+        var moves by mutableStateOf(12)+        rule.setContent { MovesBox(moves = moves, bestScore = bestScore, optimalMoves = 10) }+        rule.onNodeWithText("12").assertIsDisplayed()+        rule.onNodeWithText("- / 10").assertIsDisplayed()+        moves = 9+        bestScore = 8+        rule.waitForIdle()+        rule.onNodeWithText("8 / 10").assertIsDisplayed()+    }++    // --- GameModeChooser ---------------------------------------------------------++    @Test+    fun `chooser shows the selection and picks another`() {+        var selected = "Easy"+        rule.setContent {+            GameModeChooser(+                selected = selected,+                options = listOf("Easy", "Hard"),+                label = { "Mode: $it" },+                menuLabel = { it },+                onSelect = { selected = it },+            )+        }+        rule.onNodeWithText("Mode: Easy").assertIsDisplayed()+        rule.onNodeWithText("Mode: Easy").performClick()+        rule.onNodeWithText("Hard").assertIsDisplayed()+        rule.onNodeWithText("Hard").performClick()+        assertEquals("Hard", selected)+    }++    // --- GameResultOverlay -----------------------------------------------------------++    @Test+    fun `result overlay shows title stats and both actions`() {+        var back = 0+        var again = 0+        rule.setContent {+            GameResultOverlay(+                title = "Slice2 Solved",+                won = true,+                onBack = { back++ },+                onPlayAgain = { again++ },+                stats = { androidx.compose.material3.Text("12 moves") },+            )+        }+        rule.onNodeWithText("Slice2 Solved").assertIsDisplayed()+        rule.onNodeWithText("12 moves").assertIsDisplayed()+        rule.onNodeWithText(appContext.getString(UiR.string.game_play_again)).performClick()+        rule.onNodeWithText(appContext.getString(UiR.string.game_back)).performClick()+        assertEquals(1, again)+        assertEquals(1, back)+    }++    @Test+    fun `a daily board hides play-again`() {+        rule.setContent {+            GameResultOverlay(title = "Daily", won = false, onBack = {}, onPlayAgain = null)+        }+        rule.onNodeWithText("Daily").assertIsDisplayed()+        assertTrue(+            rule.onAllNodes(hasText(appContext.getString(UiR.string.game_play_again)))+                .fetchSemanticsNodes().isEmpty(),+        )+    }++    // --- DailyChallengeCard ---------------------------------------------------------------++    @Test+    fun `challenge card opens on tap`() {+        var opened = 0+        rule.setContent {+            DailyChallengeCard(day = 20000L, completed = 2, total = 5, streak = 3L, onOpen = { opened++ })+        }+        rule.onNodeWithText(appContext.getString(UiR.string.game_daily_challenge)).assertIsDisplayed()+        rule.onNodeWithText("2/5").assertIsDisplayed()+        rule.onNodeWithText("2/5").performClick()+        assertEquals(1, opened)+    }+}