nonogram: check clue fit on resolved sizes; satisfy detekt in tests (#ux-audit)
- Commit
d30d065a0794dd09b6efe0e826b9442a0bbcc23a- Author
- Vayun Mathur <[email protected]>
- When
- 2026-11-13 08:38 UTC (23 days ago)
- Parents
721d6c6
Follow-up to the previous two test commits. - cluesFitTheirSlotsAtLargeFontScale measured the laid-out paragraph, but Robolectric's stand-in text metrics report glyph boxes that have nothing to do with the real font (a 12px line box came back as 35px). The test now asserts the resolved font size and line height against the slot (the Text's max height, +1px rounding), which is what the fix controls and what the old `.sp` sizing gets wrong at 200% font scale (both values were twice the slot). - The set/resetMain retry helper used the same `if (...) return; ...` one-liner shape that detekt reads as an empty else block (EmptyElseBlock, an error); rewritten as a bounded while loop.
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 f1db823e07..b89c8311a9 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@@ -48,8 +48,13 @@ class NonogramViewModelTest { /** 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()+ var attempts = 0+ while (attempts++ < RETRIES && runCatching(action).isFailure) Thread.sleep(10)+ if (attempts > RETRIES) action()+ }++ private companion object {+ const val RETRIES = 20 } private fun await(desc: String, cond: () -> Boolean) {
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 f0806c610e..2e747b5731 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,12 +315,15 @@ 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.+ // Checked on the resolved style rather than measured glyphs, which Robolectric's+ // stand-in text metrics do not report faithfully. The slot is the Text's max height;+ // 1px of tolerance covers rounding it to whole pixels. The old `.sp` sizing fails both+ // checks at 200%: its font and line box were each twice what the slot was fitted for. 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 <= 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")+ assertTrue(linePx <= slotPx, "clue '$text' line box ${linePx}px overflows its ${slotPx}px slot") } }