Draw the setup wizard pages

Written-by: Codex (GPT-6.2 Sol)
Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 21:32:10 +01:00
1 parent 78fc5b98fa
commit 64a6eab35f
4 files changed
+482

No files matched your search

@@ -0,0 +1,115 @@
package kst4contest.view.compose.wizard
import androidx.compose.ui.test.ComposeUiTest
import androidx.compose.ui.test.ExperimentalTestApi
import androidx.compose.ui.test.onNodeWithText
import androidx.compose.ui.test.performClick
import androidx.compose.ui.test.runComposeUiTest
import kst4contest.model.ChatCategory
import kst4contest.model.ChatPreferences
import kst4contest.view.compose.Kst4ContestTheme
import kst4contest.view.i18n.LanguageStore
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
import java.nio.file.Path
import java.util.Locale
/**
* The drawn wizard, clicked the way an operator clicks it. The rules live in
* SetupWizardState and are tested there; this holds the wiring -- that a button reaches the
* state, and that a button which must not work does not.
*/
@OptIn(ExperimentalTestApi::class)
class SetupWizardContentScreenTest {
private fun configuredProfile() =
ChatPreferences(Path.of("setup-wizard-screen-test-unused.xml")).apply {
setStn_loginCallSign("DL0TEST")
setStn_loginPassword("secret")
setStn_loginNameMainCat("Philipp")
setStn_loginLocatorMainCat("JO50AA")
setStn_bandActive144(true)
setLoginChatCategoryMain(ChatCategory(2))
// Stated, not left to the compiled-in default: with a second chat and no second
// category the summary could not be saved.
setLoginToSecondChatEnabled(false)
}
private class Recorded {
var later = 0
val saves = mutableListOf<Boolean>()
}
private fun ComposeUiTest.show(state: SetupWizardState, saveFailed: Boolean = false): Recorded {
val recorded = Recorded()
// English, whatever language an earlier test in this JVM left behind.
val english = LanguageStore({ "en" }, {}, Locale.ENGLISH)
setContent {
Kst4ContestTheme(darkMode = false, baseFontSizeSp = 12f) {
SetupWizardContent(
state = state,
languageStore = english,
saveFailed = saveFailed,
onLater = { recorded.later++ },
onSave = { recorded.saves += it },
)
}
}
return recorded
}
@Test
fun nextDoesNothingUntilBothSourcesAreChosen() = runComposeUiTest {
val state = SetupWizardState(configuredProfile())
show(state)
onNodeWithText("Next").performClick()
assertEquals(WizardPage.ENTRY, state.page, "Next worked without a choice")
onNodeWithText("Leave the login unchanged (DL0TEST)").performClick()
onNodeWithText("Leave the station unchanged (locator JO50AA)").performClick()
assertEquals(WizardSource.KEEP, state.loginSource)
assertEquals(WizardSource.KEEP, state.stationSource)
onNodeWithText("Next").performClick()
assertEquals(WizardPage.PERSONAL, state.page)
}
@Test
fun laterIsReportedAndNothingElse() = runComposeUiTest {
val recorded = show(SetupWizardState(configuredProfile()))
onNodeWithText("Later").performClick()
assertEquals(1, recorded.later)
assertTrue(recorded.saves.isEmpty())
}
@Test
fun theSummaryOffersBothWaysOfSaving() = runComposeUiTest {
val state = SetupWizardState(configuredProfile())
state.chooseLoginSource(WizardSource.KEEP)
state.chooseStationSource(WizardSource.KEEP)
state.next()
state.next()
val recorded = show(state)
onNodeWithText("Save").performClick()
onNodeWithText("Save and connect").performClick()
assertEquals(listOf(false, true), recorded.saves)
}
@Test
fun aFailedSaveIsToldToTheOperator() = runComposeUiTest {
val state = SetupWizardState(configuredProfile())
state.chooseLoginSource(WizardSource.KEEP)
state.chooseStationSource(WizardSource.KEEP)
state.next()
state.next()
show(state, saveFailed = true)
onNodeWithText("The settings could not be written. Nothing was changed.").assertExists()
}
}