Offer other profiles as a source on the setup wizard's entry page

Written-by: Codex (GPT-6.2 Sol)
Written-by: Claude Fable 5.2
This commit is contained in:
Rsclub2_2 committed 2026-11-18 22:28:04 +01:00
1 parent 76e086f4c0
commit dc164403be
6 files changed
+235 -4

No files matched your search

@@ -220,4 +220,56 @@ class SetupWizardContentScreenTest {
onNodeWithText("Will be switched off: network log synchronisation, AirScout.").assertExists()
}
private fun donor(id: String, name: String, callsign: String, locator: String) =
WizardDonor(id, name, ChatPreferences(Path.of("setup-wizard-screen-donor-unused.xml")).apply {
setStn_loginCallSign(callsign)
setStn_loginPassword("secret")
setStn_loginLocatorMainCat(locator)
setStn_bandActive144(true)
setLoginChatCategoryMain(ChatCategory(2))
setLoginToSecondChatEnabled(false)
})
private fun emptyProfile() =
ChatPreferences(Path.of("setup-wizard-screen-test-unused.xml")).apply {
setStn_loginCallSign("")
setStn_loginPassword("")
setStn_loginLocatorMainCat("JO54ME")
setStn_bandActive144(true)
setLoginChatCategoryMain(ChatCategory(2))
setLoginToSecondChatEnabled(false)
}
@Test
fun aSingleDonorIsNamedInTheOptionAndTakenWithOneClick() = runComposeUiTest {
val state = SetupWizardState(emptyProfile(), listOf(donor("a", "Conteststation", "DL0TEST", "JO50AA")))
show(state)
onNodeWithText("Take the login from profile \"Conteststation\" (DL0TEST)").performClick()
onNodeWithText("Take the station from profile \"Conteststation\" (locator JO50AA)").performClick()
assertEquals(WizardSource.TAKE, state.loginSource)
assertEquals("a", state.loginDonor?.profileId)
assertEquals(WizardSource.TAKE, state.stationSource)
onNodeWithText("Next").performClick()
assertEquals(WizardPage.PERSONAL, state.page)
assertEquals("DL0TEST", state.callsign)
}
@Test
fun withSeveralDonorsNextWaitsForAProfile() = runComposeUiTest {
val state = SetupWizardState(
emptyProfile(),
listOf(donor("a", "Conteststation", "DL0TEST", "JO50AA"), donor("b", "Portabel", "DL0TEST/P", "JN58QA")),
)
show(state)
onNodeWithText("Take the login from another profile").performClick()
onNodeWithText("Set up a new station").performClick()
onNodeWithText("Next").performClick()
assertEquals(WizardPage.ENTRY, state.page, "which profile is not said yet")
}
}
@@ -3,6 +3,7 @@ package kst4contest.view.compose.wizard
import kst4contest.model.ChatPreferences
import org.junit.jupiter.api.Assertions.assertArrayEquals
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test
@@ -130,4 +131,76 @@ class SetupWizardLauncherTest(@param:TempDir private val directory: Path) {
assertEquals(SetupWizardOutcome.SAVED, saveFromWizard(state, prefs, connect = false))
assertEquals(SetupWizardOutcome.SAVED_AND_CONNECT, saveFromWizard(state, prefs, connect = true))
}
private fun profileFile(name: String, callsign: String, password: String): Path {
val file = directory.resolve(name)
ChatPreferences::class.java.getResourceAsStream(ChatPreferences.PREFERENCE_RESOURCE).use { template ->
Files.copy(requireNotNull(template), file, StandardCopyOption.REPLACE_EXISTING)
}
ChatPreferences(file).apply {
assertTrue(readPreferencesFromXmlFile())
setStn_loginCallSign(callsign)
setStn_loginPassword(password)
assertTrue(writePreferencesToXmlFile())
}
return file
}
@Test
fun onlyConfiguredReadableProfilesBecomeDonors() {
val configured = profileFile("configured.xml", "DL0TEST", "secret")
val emptyLogin = profileFile("empty.xml", "", "")
val template = profileFile("template.xml", "DO5AMF", "changeMe")
val garbage = directory.resolve("garbage.xml").also { Files.writeString(it, "this is not xml <<<") }
val donors = loadDonors(
listOf(
DonorCandidate("a", "Conteststation", configured),
DonorCandidate("b", "Leer", emptyLogin),
DonorCandidate("c", "Vorlage", template),
DonorCandidate("d", "Kaputt", garbage),
DonorCandidate("e", "Fehlt", directory.resolve("missing.xml")),
)
)
assertEquals(listOf("a"), donors.map { it.profileId })
assertEquals("Conteststation", donors.single().displayName)
assertEquals("DL0TEST", donors.single().callsign)
}
@Test
fun aMissingDonorFileIsNotCreated() {
val missing = directory.resolve("missing.xml")
loadDonors(listOf(DonorCandidate("e", "Fehlt", missing)))
assertFalse(Files.exists(missing), "looking for a donor must not create its file")
}
@Test
fun readingADonorLeavesItsFileAlone() {
val configured = profileFile("configured.xml", "DL0TEST", "secret")
val before = Files.readAllBytes(configured)
loadDonors(listOf(DonorCandidate("a", "Conteststation", configured)))
assertArrayEquals(before, Files.readAllBytes(configured))
}
@Test
fun donorsAreOnlyLoadedWhenTheWizardOpens() {
var loaded = 0
val donors = { loaded++; emptyList<WizardDonor>() }
SetupWizardLauncher.run(ChatPreferences(configuredFile()), forced = false, donors, neverShown)
assertEquals(0, loaded, "a configured profile starts without reading other profiles")
var seen: List<WizardDonor>? = null
SetupWizardLauncher.run(ChatPreferences(templateFile()), forced = false, donors) { state, _ ->
seen = state.donors
SetupWizardOutcome.LATER
}
assertEquals(1, loaded)
assertEquals(emptyList<WizardDonor>(), seen)
}
}