Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/src/main/java/com/anindra/messages/ui/InboxSettingsScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
}
}
2 changes: 1 addition & 1 deletion scripts