weather: the pollen block shows no-data instead of a fabricated 0/4
- Commit
965c5fb71ea737cc8a38913a6c5a9e8ed45237a7- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 11:59 UTC (5 days ago)
- Parents
2f06f82
WxGrid only loads pollen for CAMS-Europe; elsewhere every species is null (a no-air-quality bundle gives null air entirely). PollenBlock collapsed that absence with ?: 0.0, rendering a measured-looking '0/4 None' at every such location — asserting no pollen where the pack says nothing. The neighbouring AirQuality and UV blocks render '—' for the same state. The block now keeps the null: no species present -> value and label both '—'; present-data thresholds (0/10/50/200) are unchanged and a genuine 0.0 still shows '0/4 None'. Three regression tests (two failed pre-fix; the genuine- zero pin passed throughout). Map valid-time, widget candidates and saved-location flow were audited and cleared. Verified: :weather:testDevUnitTest 246 tests pass; lint errors are pre-existing on the untouched Route.kt.
Diff
weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt
diff --git a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/PollenBlock.ktindex 1747c1e5f7..cc8a9fcdb2 100644--- a/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt+++ b/weather/src/main/java/com/vayunmathur/weather/ui/components/blocks/PollenBlock.kt@@ -22,6 +22,11 @@ import com.vayunmathur.weather.network.AirQualityCurrent */ @Composable fun PollenBlock(air: AirQualityCurrent?) {+ // Null only when the pack carries no pollen species at all (outside+ // CAMS-Europe coverage, or no `aq` section): that is no data, not a+ // measured zero, so it renders the same em-dash as the AirQuality/UV+ // blocks instead of fabricating a "0/4 None" level. A species present+ // at 0.0 is a genuine zero and keeps "0/4 None". val worst = listOfNotNull( air?.grassPollen, air?.alderPollen,@@ -29,28 +34,33 @@ fun PollenBlock(air: AirQualityCurrent?) { air?.olivePollen, air?.ragweedPollen, air?.mugwortPollen,- ).maxOrNull() ?: 0.0- val level = when {- worst <= 0.0 -> 0- worst < 10 -> 1- worst < 50 -> 2- worst < 200 -> 3- else -> 4- }- val labelRes = when (level) {- 0 -> UiR.string.none- 1 -> R.string.level_low- 2 -> UiR.string.medium- 3 -> R.string.level_high- else -> R.string.level_severe+ ).maxOrNull()+ val level = worst?.let {+ when {+ it <= 0.0 -> 0+ it < 10 -> 1+ it < 50 -> 2+ it < 200 -> 3+ else -> 4+ } }- val label = stringResource(labelRes)+ val label = level?.let {+ stringResource(+ when (it) {+ 0 -> UiR.string.none+ 1 -> R.string.level_low+ 2 -> UiR.string.medium+ 3 -> R.string.level_high+ else -> R.string.level_severe+ },+ )+ } ?: "—" SquareBlock { Box(Modifier.align(Alignment.TopStart)) { BlockHeader(icon = { m, c -> IconGrass(m, c) }, title = stringResource(R.string.block_pollen)) } Text(- text = "$level/4",+ text = level?.let { "$it/4" } ?: "—", style = MaterialTheme.typography.displayMediumEmphasized, modifier = Modifier.align(Alignment.Center).offset(y = 4.dp), color = MaterialTheme.colorScheme.onSurface,
weather/src/test/java/com/vayunmathur/weather/ui/ComposeBlocksTest.kt
diff --git a/weather/src/test/java/com/vayunmathur/weather/ui/ComposeBlocksTest.kt b/weather/src/test/java/com/vayunmathur/weather/ui/ComposeBlocksTest.ktindex 30e7fcbe4b..b3eebc1d33 100644--- a/weather/src/test/java/com/vayunmathur/weather/ui/ComposeBlocksTest.kt+++ b/weather/src/test/java/com/vayunmathur/weather/ui/ComposeBlocksTest.kt@@ -1,5 +1,6 @@ package com.vayunmathur.weather.ui +import androidx.compose.ui.test.assertCountEquals import androidx.compose.ui.test.assertIsDisplayed import androidx.compose.ui.test.junit4.createComposeRule import androidx.compose.ui.test.onNodeWithText@@ -113,6 +114,35 @@ class ComposeBlocksTest { rule.onNodeWithText("12").assertIsDisplayed() } + // Regression: a pack with no pollen species at all (every non-Europe+ // bundle, whose `aq` carries AQI but null pollen, or a bundle with no+ // `aq` section) must read as no-data, not as a measured "0/4 None" —+ // the same em-dash the AirQuality/UV blocks use for missing data. A+ // species genuinely present at 0.0 keeps the real "0/4 None".+ @Test fun pollenBlockMissingSpeciesShowsNoData() {+ rule.setContent {+ PollenBlock(AirQualityCurrent(time = "2026-07-15T14:00", usAqi = 42))+ }+ rule.onNodeWithText("0/4").assertDoesNotExist()+ rule.onNodeWithText("None", substring = true).assertDoesNotExist()+ rule.onAllNodesWithText("—").assertCountEquals(2)+ }++ @Test fun pollenBlockNullAirShowsNoData() {+ rule.setContent { PollenBlock(null) }+ rule.onNodeWithText("0/4").assertDoesNotExist()+ rule.onAllNodesWithText("—").assertCountEquals(2)+ }++ @Test fun pollenBlockGenuineZeroStillShowsNone() {+ rule.setContent {+ PollenBlock(+ AirQualityCurrent(time = "2026-07-15T14:00", usAqi = 42, grassPollen = 0.0),+ )+ }+ rule.onNodeWithText("0/4").assertIsDisplayed()+ }+ @Test fun sunMoonPrecipBlocks() { rule.setContent { SunBlock(