diff --git a/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt b/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt index a642c4ec..5e07a9c0 100644 --- a/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt +++ b/app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt @@ -446,14 +446,18 @@ internal fun InboxCategoryRulesScreen( Spacer(Modifier.height(SettingsLayout.GROUP_GAP)) // Nothing is drawn until the table has been read once: an empty // "no rules yet" under every tab was mistaken for rules going missing. - val byCategory = remember(rules) { rules?.let { InboxCategoryRules.group(it) } } - byCategory?.forEach { (category, inTab) -> + val sections = remember(rules) { + rules?.let { InboxCategoryRules.group(it).entries.toList() } + } + sections?.forEachIndexed { index, (category, inTab) -> RuleSection( category = category, rules = inTab, onDelete = { vm.deleteCategoryRule(it) } ) - Spacer(Modifier.height(12.dp)) + // Only between sections: a spacer after the last one stacked + // with the footer's own gap and left a band above the note. + if (index != sections.lastIndex) Spacer(Modifier.height(12.dp)) } SettingsFooter(stringResource(R.string.settings_inbox_rules_footer)) } diff --git a/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt b/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt new file mode 100644 index 00000000..19ae9a7f --- /dev/null +++ b/app/src/test/java/com/anindra/messages/ui/InboxRulesFooterGapTest.kt @@ -0,0 +1,44 @@ +package com.anindra.messages.ui + +import org.junit.Assert.assertTrue +import org.junit.Test +import java.io.File + +/** + * The Categories & rules footer used to sit under an unconditional 12dp spacer + * that was meant to separate sections; after the last section it stacked with + * the footer's own 6dp gap and left a band above the note. The spacer is now + * conditional, which is invisible to a compiler and easy to reintroduce. + */ +class InboxRulesFooterGapTest { + + private val screen: String by lazy { + val root = generateSequence(File("").absoluteFile) { it.parentFile } + .firstOrNull { File(it, "gradle/libs.versions.toml").isFile } + ?: error("repo root not found") + File(root, "app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt").readText() + } + + @Test + fun theSectionSpacerIsSkippedAfterTheLastSection() { + assertTrue( + "the rules screen no longer indexes its sections", + Regex("""sections\?\.forEachIndexed \{ index, \(category, inTab\) ->""") + .containsMatchIn(screen) + ) + assertTrue( + "the spacer after a rule section is unconditional again", + Regex("""if \(index != sections\.lastIndex\) Spacer\(Modifier\.height\(12\.dp\)\)""") + .containsMatchIn(screen) + ) + } + + @Test + fun theFooterStillFollowsTheSections() { + assertTrue( + "the rules footer is missing", + Regex("""if \(index != sections\.lastIndex\)[\s\S]{0,120}SettingsFooter\(stringResource\(R\.string\.settings_inbox_rules_footer\)\)""") + .containsMatchIn(screen) + ) + } +} diff --git a/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt b/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt index f7b027e1..483d09d6 100644 --- a/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt +++ b/app/src/test/java/com/anindra/messages/ui/RulesFirstReadTest.kt @@ -44,13 +44,16 @@ class RulesFirstReadTest { @Test fun noSectionIsDrawnBeforeTheRulesArrive() { + // Anchored on the null-guarded grouping, not on the exact shape the + // sections are later turned into (the footer fix wraps it in + // `.entries.toList()`); renaming that should not fail this test. assertTrue( "the sections are drawn from a possibly-null answer", - screen.contains("rules?.let { InboxCategoryRules.group(it) }") + Regex("""rules\?\.let \{\s*InboxCategoryRules\.group\(it\)""").containsMatchIn(screen) ) assertFalse( "the sections fall back to an empty grouping before the read", - screen.contains("InboxCategoryRules.group(rules)") + Regex("""InboxCategoryRules\.group\(rules\)""").containsMatchIn(screen) ) } } diff --git a/scripts b/scripts index 8fa0729c..fe4cd766 160000 --- a/scripts +++ b/scripts @@ -1 +1 @@ -Subproject commit 8fa0729c98ae86f82346c99036c01db6bb51169b +Subproject commit fe4cd76658ad2a47e94374fc30155c6a17a3671b