mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Harden beacon sessions and mark automatic messages
This commit is contained in:
1 parent
19bcdb428d
commit
f13fe54fde
63 files changed
+1905
-252
No files matched your search
@@ -0,0 +1,58 @@
|
||||
package kst4contest.view.compose
|
||||
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class BeaconStatusColorsTest {
|
||||
private val neutral = Color(0xFF123456)
|
||||
|
||||
@Test
|
||||
fun `active and activity colours are the approved traffic colours`() {
|
||||
assertEquals(
|
||||
ThreadButtonColors(Color(0xFF238636), Color(0xFF56D364), Color.White),
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_ACTIVE, false, false, neutral),
|
||||
)
|
||||
assertEquals(
|
||||
ThreadButtonColors(Color(0xFFFFB300), Color(0xFFFFE082), Color(0xFF1B1B1B)),
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_ACTIVE, true, false, neutral),
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `off uses neutral background and theme specific red text`() {
|
||||
assertEquals(Color(0xFFD50000),
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, false, neutral).text)
|
||||
assertEquals(Color(0xFFFF6B6B),
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, true, neutral).text)
|
||||
assertEquals(neutral,
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_OFF, false, true, neutral).background)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `failed stays red even when a highlight is requested`() {
|
||||
val colors = beaconThreadButtonColors(
|
||||
ThreadStatusVisualStyle.BEACON_FAILED,
|
||||
true,
|
||||
false,
|
||||
neutral,
|
||||
)
|
||||
assertEquals(ThreadButtonColors(Color(0xFFD50000), Color(0xFFFF6B6B), Color.White), colors)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `failed suppresses the flash while active status allows it`() {
|
||||
val button = ThreadStatusButton("MyBeacon")
|
||||
button.report("MyBeacon: on", "active", ThreadStatusVisualStyle.BEACON_ACTIVE)
|
||||
assertTrue(button.highlighted)
|
||||
|
||||
button.report("MyBeacon: FAILED", "failed", ThreadStatusVisualStyle.BEACON_FAILED)
|
||||
assertFalse(button.highlighted)
|
||||
assertEquals(
|
||||
ThreadButtonColors(Color(0xFFD50000), Color(0xFFFF6B6B), Color.White),
|
||||
beaconThreadButtonColors(ThreadStatusVisualStyle.BEACON_FAILED, true, false, neutral),
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package kst4contest.view.compose
|
||||
|
||||
import kst4contest.model.BeaconStatusSnapshot
|
||||
import kst4contest.model.BeaconStatusSnapshot.AggregateState
|
||||
import kst4contest.model.BeaconStatusSnapshot.CategoryStatus
|
||||
import kst4contest.model.BeaconStatusSnapshot.InactiveReason
|
||||
import kst4contest.view.i18n.LanguageStore
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertFalse
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.Locale
|
||||
|
||||
class BeaconStatusPresentationTest {
|
||||
@Test
|
||||
fun `partial status keeps the inactive category reason in English`() {
|
||||
val presentation = BeaconStatusPresentation.from(snapshot(AggregateState.PARTIAL))
|
||||
|
||||
assertEquals("1/2", presentation.label)
|
||||
assertTrue(presentation.tooltip.contains("Main category: active"))
|
||||
assertTrue(presentation.tooltip.contains("primary QRG missing or invalid"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `the same category reasons are available in German`() {
|
||||
val language = LanguageStore({ "de" }, {}, Locale.UK)
|
||||
try {
|
||||
val presentation = BeaconStatusPresentation.from(
|
||||
snapshot(AggregateState.PARTIAL),
|
||||
language.strings,
|
||||
)
|
||||
|
||||
assertTrue(presentation.tooltip.contains("Hauptkategorie: aktiv"))
|
||||
assertTrue(presentation.tooltip.contains("Haupt-QRG fehlt oder ist ungültig"))
|
||||
assertFalse(presentation.tooltip.contains("144."))
|
||||
} finally {
|
||||
language.use("en")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `failed style overrides an active category`() {
|
||||
val main = CategoryStatus(true, true, true, InactiveReason.USER_DISABLED)
|
||||
val second = CategoryStatus(false, false, false, InactiveReason.NOT_ACTIVATED_THIS_SESSION)
|
||||
val presentation = BeaconStatusPresentation.from(
|
||||
BeaconStatusSnapshot(AggregateState.FAILED, main, second),
|
||||
)
|
||||
|
||||
assertEquals("FAILED", presentation.label)
|
||||
assertEquals(ThreadStatusVisualStyle.BEACON_FAILED, presentation.style)
|
||||
assertTrue(presentation.tooltip.contains("send failed"))
|
||||
}
|
||||
|
||||
private fun snapshot(state: AggregateState): BeaconStatusSnapshot = BeaconStatusSnapshot(
|
||||
state,
|
||||
CategoryStatus(true, true, false, InactiveReason.USER_DISABLED),
|
||||
CategoryStatus(true, false, false, InactiveReason.PRIMARY_QRG_UNAVAILABLE),
|
||||
)
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import androidx.compose.ui.text.input.TextFieldValue
|
||||
import kst4contest.model.ChatCategory
|
||||
import kst4contest.model.ChatMember
|
||||
import kst4contest.model.ChatMessage
|
||||
import kst4contest.controller.RadioSlot
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNull
|
||||
import org.junit.jupiter.api.Assertions.assertSame
|
||||
@@ -233,6 +234,20 @@ class ChatInputStateTest {
|
||||
assertEquals("432.200 ", state.value.text)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `manual QRG commits keep their radio source explicit`() {
|
||||
val actions = FakeActions()
|
||||
val state = ChatInputState(actions)
|
||||
|
||||
state.commitOwnQrg(mainCategory = true, "144.300")
|
||||
state.commitOwnQrg(mainCategory = false, "1296.100")
|
||||
|
||||
assertEquals(
|
||||
listOf(RadioSlot.FIRST to "144.300", RadioSlot.SECOND to "1296.100"),
|
||||
actions.manualQrgs,
|
||||
)
|
||||
}
|
||||
|
||||
// ---- the snippets ------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -407,6 +422,7 @@ class ChatInputStateTest {
|
||||
val resolvedTemplates = mutableListOf<String>()
|
||||
val recordedCqs = mutableListOf<String>()
|
||||
val recomputeReasons = mutableListOf<String>()
|
||||
val manualQrgs = mutableListOf<Pair<RadioSlot, String>>()
|
||||
|
||||
override fun panelSelection(): ChatMember? = panelSelection
|
||||
override fun tableSelection(): ChatMember? = tableSelection
|
||||
@@ -431,5 +447,6 @@ class ChatInputStateTest {
|
||||
override fun queue(message: ChatMessage) { queued += message }
|
||||
override fun ownQrgMain(): String = ownQrgMain
|
||||
override fun ownQrgSecond(): String = ownQrgSecond
|
||||
override fun applyManualQrg(slot: RadioSlot, value: String) { manualQrgs += slot to value }
|
||||
}
|
||||
}
|
||||
@@ -173,13 +173,24 @@ class BeaconTabStateTest(@TempDir private val tempDir: Path) {
|
||||
s.prefs.setBcn_beaconIntervalInMinutesMainCat(5)
|
||||
val state = s.state()
|
||||
|
||||
assertNotNull(state.commitBeaconInterval("0"))
|
||||
assertNotNull(state.commitBeaconInterval("4"))
|
||||
|
||||
assertEquals(5, s.prefs.getBcn_beaconIntervalInMinutesMainCat())
|
||||
assertEquals(0, s.timerRestarts,
|
||||
"restarting the timer per rejected keystroke would disturb the cooldown")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `exactly five minutes is accepted`() {
|
||||
val s = Session()
|
||||
val state = s.state()
|
||||
|
||||
assertNull(state.commitBeaconInterval("5"))
|
||||
|
||||
assertEquals(5, s.prefs.getBcn_beaconIntervalInMinutesMainCat())
|
||||
assertEquals(5, s.prefs.getBcn_beaconIntervalInMinutesSecondCat())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `an interval that is not a whole number is refused`() {
|
||||
val s = Session()
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ class RemainingTextsFollowTheLanguageTest {
|
||||
|
||||
assertEquals("Wertung", score.title(), "the column title stayed in the old language")
|
||||
assertEquals(
|
||||
"Einen ganzzahligen Bakenabstand von mindestens 1 Minute eingeben.",
|
||||
"Einen ganzzahligen Bakenabstand von mindestens 5 Minuten eingeben.",
|
||||
beacon.commitBeaconInterval("0"),
|
||||
"the refusal from the tab state stayed in the old language",
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user