nonogram: drain the store between VM tests; fix clue-fit tolerance (#ux-audit)
- Commit
721d6c69ac8b66f1f98b31753d9485e2df0e7d97- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 08:32 UTC (23 days ago)
- Parents
7dcb620
Follow-up to the previous test-hardening commit, from the next container run. NonogramViewModelTest: the store still wedged after the daily test. DataStore runs each edit's transform in the caller's context, and some ViewModel edits are still legitimately issued on Main (mark mode, the daily-day rollover on load, the win bookkeeping). One still queued when tearDown resets Main waits on the paused Robolectric looper forever, and every later edit queues behind it. tearDown now writes the current mark mode back twice (a same-value barrier: edits apply in order) so the store is idle before Main is reset, and set/resetMain retry briefly if a background coroutine is touching Main at that instant. Verified in an isolated container run of the class with per-test write probes: every probe succeeded and the suite completed. NonogramScreensTest.cluesFitTheirSlotsAtLargeFontScale: the hasVisualOverflow assertion also tripped on a 1px rounding of the slot height to whole pixels. It now checks the font size and the line box against the slot (the Text's max height) with 1px tolerance, and that no clue is cut off at the sides - which still fails for the old `.sp` sizing, whose line box is twice the slot at 200%.
Diff
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.ktindex 6e91d711aa..f1db823e07 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/platform/NonogramViewModelTest.kt@@ -27,8 +27,30 @@ import kotlin.test.assertTrue @RunWith(RobolectricTestRunner::class) class NonogramViewModelTest { private val app get() = ApplicationProvider.getApplicationContext<Application>()- @BeforeTest fun setUp() { Dispatchers.setMain(Dispatchers.Unconfined) }- @AfterTest fun tearDown() { Dispatchers.resetMain() }+ @BeforeTest fun setUp() { retrying { Dispatchers.setMain(Dispatchers.Unconfined) } }++ /**+ * Drains the store before Main is reset.+ *+ * The DataStore outlives each test, and runs an edit's transform in the caller's context: an edit+ * a ViewModel issued on Main that is still queued when Main goes back to the paused Robolectric+ * looper never runs, and every later edit queues behind it. A same-value write is a barrier —+ * edits are applied in order — and the second catches anything the first one's echo set off.+ */+ @AfterTest fun tearDown() {+ val store = com.vayunmathur.games.nonogram.data.NonogramDataStore(app)+ repeat(2) {+ runCatching { blocking { store.setMarkMode(store.markMode.first()) } }+ Thread.sleep(50)+ }+ retrying { Dispatchers.resetMain() }+ }++ /** set/resetMain throw if a background coroutine happens to be using Main at that instant. */+ private fun retrying(action: () -> Unit) {+ repeat(20) { if (runCatching(action).isSuccess) return; Thread.sleep(10) }+ action()+ } private fun await(desc: String, cond: () -> Boolean) { val deadline = System.currentTimeMillis() + 20_000
games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt
diff --git a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.ktindex 7f22b0ec80..f0806c610e 100644--- a/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt+++ b/games/nonogram/src/test/java/com/vayunmathur/games/nonogram/ui/NonogramScreensTest.kt@@ -315,10 +315,12 @@ class NonogramScreensTest { node.config[SemanticsActions.GetTextLayoutResult].action?.invoke(results) val r = results.single() val text = r.layoutInput.text.text+ // The slot is the Text's max height; allow 1px for rounding the slot to whole pixels.+ val slotPx = r.layoutInput.constraints.maxHeight + 1f val fontPx = with(r.layoutInput.density) { r.layoutInput.style.fontSize.toPx() }- val linePx = with(r.layoutInput.density) { r.layoutInput.style.lineHeight.toPx() }- assertTrue(fontPx <= linePx + 0.5f, "clue '$text' is ${fontPx}px in a ${linePx}px slot")- assertTrue(!r.hasVisualOverflow, "clue '$text' clips at 200% font scale")+ assertTrue(fontPx <= slotPx, "clue '$text' is ${fontPx}px in a ${slotPx}px slot")+ assertTrue(r.multiParagraph.height <= slotPx, "clue '$text' line box ${r.multiParagraph.height}px overflows its ${slotPx}px slot")+ assertTrue(!r.didOverflowWidth, "clue '$text' is cut off at the sides at 200% font scale") } }