office: remember state args in slice-4 test compositions
- Commit
83354bc94e2555fb018e7423ba2d60ae64787f85- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-08 06:17 UTC (28 days ago)
- Parents
40b87f7
What: wrap the 30 inline mutableStateOf/mutableIntStateOf arguments passed
to overlay composables inside rule.setContent in Slice4MenusOverlaysTest,
Slice4PresentationTest and Slice4ShellTest with remember { }, plus the
remember import in each file.
Why: :office:lintDev failed on 30 UnrememberedMutableState errors —
creating a state object during composition without remember.
Root cause: the state args were constructed inline on every recomposition,
discarding the previous state object each time. In these static-render
tests nothing recomposes mid-test, so it only tripped the lint gate, but
the same pattern under recomposition would reset selection state
(activeCell/activeSlide/pendingReplace) on every recompose.
Rejected alternatives: hoisting each state to a local val before
setContent (loses parameter-inferred type arguments — mutableStateOf(null)
would need explicit type params at every site); lint suppression (hides a
real recomposition hazard). remember { } preserves generic inference
through the expected parameter type with a one-token change per site.
User-visible effect: none; test-only change.
Verification: :office:lint green, :office:testDevUnitTest 953/0/0.Diff
office/src/test/java/com/vayunmathur/office/Slice4MenusOverlaysTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/Slice4MenusOverlaysTest.kt b/office/src/test/java/com/vayunmathur/office/Slice4MenusOverlaysTest.ktindex df0dffa642..4e01752169 100644--- a/office/src/test/java/com/vayunmathur/office/Slice4MenusOverlaysTest.kt+++ b/office/src/test/java/com/vayunmathur/office/Slice4MenusOverlaysTest.kt@@ -3,6 +3,7 @@ package com.vayunmathur.office import androidx.compose.runtime.Composable import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText@@ -164,9 +165,9 @@ class Slice4MenusOverlaysTest { CellOverlays( state = state, viewModel = viewModel,- activeCell = mutableStateOf(Triple(0, 0, 0)),- activeSlide = mutableIntStateOf(0),- activeSlideEl = mutableIntStateOf(-1),+ activeCell = remember { mutableStateOf(Triple(0, 0, 0)) },+ activeSlide = remember { mutableIntStateOf(0) },+ activeSlideEl = remember { mutableIntStateOf(-1) }, ) } rule.onNodeWithText("Text Color").assertIsDisplayed()@@ -185,9 +186,9 @@ class Slice4MenusOverlaysTest { CellOverlays( state = state, viewModel = vm(sheetDoc()),- activeCell = mutableStateOf(null),- activeSlide = mutableIntStateOf(0),- activeSlideEl = mutableIntStateOf(-1),+ activeCell = remember { mutableStateOf(null) },+ activeSlide = remember { mutableIntStateOf(0) },+ activeSlideEl = remember { mutableIntStateOf(-1) }, ) } // No active cell: color pickers stay hidden, nothing crashes.@@ -202,8 +203,8 @@ class Slice4MenusOverlaysTest { SlideElementOverlays( state = state, viewModel = vm(textDoc()),- activeSlide = mutableIntStateOf(0),- activeSlideEl = mutableIntStateOf(-1),+ activeSlide = remember { mutableIntStateOf(0) },+ activeSlideEl = remember { mutableIntStateOf(-1) }, ) } rule.onNodeWithText("Text Color").assertDoesNotExist()
office/src/test/java/com/vayunmathur/office/Slice4ShellTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/Slice4ShellTest.kt b/office/src/test/java/com/vayunmathur/office/Slice4ShellTest.ktindex 6cb12b890e..331a970df2 100644--- a/office/src/test/java/com/vayunmathur/office/Slice4ShellTest.kt+++ b/office/src/test/java/com/vayunmathur/office/Slice4ShellTest.kt@@ -5,6 +5,7 @@ import androidx.compose.foundation.lazy.rememberLazyListState import androidx.compose.material3.DrawerValue import androidx.compose.runtime.mutableIntStateOf import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember import androidx.compose.runtime.rememberCoroutineScope import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createAndroidComposeRule@@ -124,14 +125,14 @@ class Slice4ShellTest { isOnline = false, focusedPara = -1, saveAsName = "Notes.odt",- activeCell = mutableStateOf(null),- activeSlide = mutableIntStateOf(0),- activeSlideEl = mutableIntStateOf(-1),- activeRunStart = mutableIntStateOf(-1),- activeRunEnd = mutableIntStateOf(-1),- selStart = mutableIntStateOf(0),- selEnd = mutableIntStateOf(0),- pendingReplace = mutableStateOf(null),+ activeCell = remember { mutableStateOf(null) },+ activeSlide = remember { mutableIntStateOf(0) },+ activeSlideEl = remember { mutableIntStateOf(-1) },+ activeRunStart = remember { mutableIntStateOf(-1) },+ activeRunEnd = remember { mutableIntStateOf(-1) },+ selStart = remember { mutableIntStateOf(0) },+ selEnd = remember { mutableIntStateOf(0) },+ pendingReplace = remember { mutableStateOf(null) }, listState = rememberLazyListState(), scope = rememberCoroutineScope(), launchers = rememberDocumentLaunchers(@@ -160,14 +161,14 @@ class Slice4ShellTest { isOnline = false, focusedPara = -1, saveAsName = "Notes.odt",- activeCell = mutableStateOf(null),- activeSlide = mutableIntStateOf(0),- activeSlideEl = mutableIntStateOf(-1),- activeRunStart = mutableIntStateOf(-1),- activeRunEnd = mutableIntStateOf(-1),- selStart = mutableIntStateOf(0),- selEnd = mutableIntStateOf(0),- pendingReplace = mutableStateOf(null),+ activeCell = remember { mutableStateOf(null) },+ activeSlide = remember { mutableIntStateOf(0) },+ activeSlideEl = remember { mutableIntStateOf(-1) },+ activeRunStart = remember { mutableIntStateOf(-1) },+ activeRunEnd = remember { mutableIntStateOf(-1) },+ selStart = remember { mutableIntStateOf(0) },+ selEnd = remember { mutableIntStateOf(0) },+ pendingReplace = remember { mutableStateOf(null) }, listState = rememberLazyListState(), scope = rememberCoroutineScope(), launchers = rememberDocumentLaunchers(
office/src/test/java/com/vayunmathur/office/ui/Slice4PresentationTest.kt
diff --git a/office/src/test/java/com/vayunmathur/office/ui/Slice4PresentationTest.kt b/office/src/test/java/com/vayunmathur/office/ui/Slice4PresentationTest.ktindex 3bd865c3a1..c9b0b9843f 100644--- a/office/src/test/java/com/vayunmathur/office/ui/Slice4PresentationTest.kt+++ b/office/src/test/java/com/vayunmathur/office/ui/Slice4PresentationTest.kt@@ -1,6 +1,7 @@ package com.vayunmathur.office.ui import androidx.compose.runtime.mutableStateOf+import androidx.compose.runtime.remember import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.hasSetTextAction import androidx.compose.ui.test.junit4.createComposeRule@@ -151,9 +152,9 @@ class Slice4PresentationTest { document = document, viewModel = viewModel, isPresentation = true,- activeCell = mutableStateOf(null),- activeSlide = mutableStateOf(0),- pendingReplace = mutableStateOf(null),+ activeCell = remember { mutableStateOf(null) },+ activeSlide = remember { mutableStateOf(0) },+ pendingReplace = remember { mutableStateOf(null) }, launchers = rememberDocumentLaunchers( viewModel, DocumentScreenState(),@@ -211,9 +212,9 @@ class Slice4PresentationTest { listOf(OdfContentBlock.Paragraph(OdfParagraph(listOf(OdfSpan("x")))))), viewModel = vm(deck()), isPresentation = false,- activeCell = mutableStateOf(null),- activeSlide = mutableStateOf(0),- pendingReplace = mutableStateOf(null),+ activeCell = remember { mutableStateOf(null) },+ activeSlide = remember { mutableStateOf(0) },+ pendingReplace = remember { mutableStateOf(null) }, launchers = rememberDocumentLaunchers( vm(deck()), DocumentScreenState(),