mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Harden the setup wizard after the branch review
Written-by: Gemini 4 Hydrogen (Antigravity) Written-by: Claude Fable 5.2
This commit is contained in:
13 files changed
+248
-31
No files matched your search
+38
@@ -1,5 +1,8 @@
|
||||
package kst4contest.view;
|
||||
|
||||
import kst4contest.controller.ActiveOperatorProfile;
|
||||
import kst4contest.model.OperatorProfile;
|
||||
import kst4contest.model.OperatorProfileSelection;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
@@ -20,4 +23,39 @@ class ApplicationRuntimeLauncherSetupWizardTest {
|
||||
assertTrue(ApplicationRuntimeLauncher.consumeSetupWizardRequest());
|
||||
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(), "the request must not stick");
|
||||
}
|
||||
|
||||
@Test
|
||||
void switchGuardAllowsOnlyOneSwitchAtATime() {
|
||||
try {
|
||||
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||
assertFalse(ApplicationRuntimeLauncher.beginSwitch(),
|
||||
"a second switch must be refused while one is in progress");
|
||||
} finally {
|
||||
ApplicationRuntimeLauncher.endSwitch();
|
||||
}
|
||||
|
||||
try {
|
||||
assertTrue(ApplicationRuntimeLauncher.beginSwitch(),
|
||||
"ending the first switch must release the guard");
|
||||
} finally {
|
||||
ApplicationRuntimeLauncher.endSwitch();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void rerunSetupWizardWhileSwitchInProgressReturnsFalseAndClearsRequest() {
|
||||
OperatorProfileSelection previous = ActiveOperatorProfile.get();
|
||||
OperatorProfile profile = new OperatorProfile("wizard-guard-test", "Wizard Guard Test", false, false);
|
||||
ActiveOperatorProfile.set(new OperatorProfileSelection(profile, "preferences.xml", "worked.db", false));
|
||||
assertTrue(ApplicationRuntimeLauncher.beginSwitch());
|
||||
try {
|
||||
assertFalse(ApplicationRuntimeLauncher.rerunSetupWizard());
|
||||
assertFalse(ApplicationRuntimeLauncher.consumeSetupWizardRequest(),
|
||||
"a refused rerun must not leave a wizard request behind");
|
||||
} finally {
|
||||
ApplicationRuntimeLauncher.endSwitch();
|
||||
ApplicationRuntimeLauncher.consumeSetupWizardRequest();
|
||||
ActiveOperatorProfile.set(previous);
|
||||
}
|
||||
}
|
||||
}
|
||||
+12
@@ -112,4 +112,16 @@ class SetupWizardContentScreenTest {
|
||||
|
||||
onNodeWithText("The settings could not be written. Nothing was changed.").assertExists()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun theSummaryShowsTheChosenLanguage() = runComposeUiTest {
|
||||
val state = SetupWizardState(configuredProfile().apply { setGuiOptions_language("de") })
|
||||
state.chooseLoginSource(WizardSource.KEEP)
|
||||
state.chooseStationSource(WizardSource.KEEP)
|
||||
state.next()
|
||||
state.next()
|
||||
show(state)
|
||||
|
||||
onNodeWithText("DE").assertExists()
|
||||
}
|
||||
}
|
||||
+16
-1
@@ -12,7 +12,7 @@ import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
|
||||
/** When the wizard opens at all, decided without a window. */
|
||||
class SetupWizardLauncherTest(@TempDir private val directory: Path) {
|
||||
class SetupWizardLauncherTest(@param:TempDir private val directory: Path) {
|
||||
|
||||
private fun templateFile(): Path {
|
||||
val file = directory.resolve("preferences.xml")
|
||||
@@ -81,6 +81,21 @@ class SetupWizardLauncherTest(@TempDir private val directory: Path) {
|
||||
assertArrayEquals(before, Files.readAllBytes(garbage), "the unreadable file was touched")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFileTheReaderThrowsOnNeverOpensTheWizard() {
|
||||
val file = templateFile()
|
||||
val original = Files.readString(file)
|
||||
assertTrue(original.contains("<ChatCategory>2</ChatCategory>"))
|
||||
Files.writeString(file, original.replace("<ChatCategory>2</ChatCategory>", "<ChatCategory>2.0</ChatCategory>"))
|
||||
val before = Files.readAllBytes(file)
|
||||
|
||||
assertEquals(
|
||||
SetupWizardOutcome.NOT_SHOWN,
|
||||
SetupWizardLauncher.run(ChatPreferences(file), forced = true, neverShown),
|
||||
)
|
||||
assertArrayEquals(before, Files.readAllBytes(file), "the unreadable file was touched")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aFailedSaveKeepsTheWizardOpen() {
|
||||
val source = ChatPreferences(templateFile()).apply { assertTrue(readPreferencesFromXmlFile()) }
|
||||
|
||||
@@ -351,4 +351,67 @@ class SetupWizardStateTest {
|
||||
assertTrue(state.mandatoryComplete)
|
||||
assertFalse(state.pages.contains(WizardPage.SITE))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun storablePasswordsAndNamesRejectDelimitersAndOuterWhitespace() {
|
||||
listOf("secret", "se cret").forEach {
|
||||
assertTrue(SetupWizardState.isStorablePassword(it), "'$it' must be accepted")
|
||||
}
|
||||
listOf("", " ", " secret", "secret ", "se|cret", "se\ncret", "se\rcret").forEach {
|
||||
assertFalse(SetupWizardState.isStorablePassword(it), "'$it' must be refused")
|
||||
}
|
||||
|
||||
listOf("Philipp", "Philipp W").forEach {
|
||||
assertTrue(SetupWizardState.isStorableName(it), "'$it' must be accepted")
|
||||
}
|
||||
listOf("", " ", "Phil|ipp", "Phil\nipp", "Phil\ripp").forEach {
|
||||
assertFalse(SetupWizardState.isStorableName(it), "'$it' must be refused")
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun aRefusedPasswordOrNameIsReportedAndBlocksCompletion() {
|
||||
val state = SetupWizardState(freshInstallation())
|
||||
assertFalse(state.nameRefused)
|
||||
state.name = " "
|
||||
assertFalse(state.nameRefused)
|
||||
assertFalse(state.canGoNext)
|
||||
state.name = "Phil|ipp"
|
||||
assertTrue(state.nameRefused)
|
||||
assertFalse(state.canGoNext)
|
||||
|
||||
state.fillFirstInstallation()
|
||||
state.back()
|
||||
assertEquals(WizardPage.LOGIN, state.page)
|
||||
assertFalse(state.passwordRefused)
|
||||
|
||||
listOf(" secret", "secret ", " ", "se|cret", "se\ncret").forEach { refused ->
|
||||
state.password = refused
|
||||
assertTrue(state.passwordRefused, "'$refused' must set passwordRefused")
|
||||
assertFalse(state.canGoNext, "'$refused' must block Next on login")
|
||||
assertFalse(state.mandatoryComplete, "'$refused' must block mandatoryComplete")
|
||||
}
|
||||
|
||||
state.password = ""
|
||||
assertFalse(state.passwordRefused)
|
||||
assertFalse(state.canGoNext)
|
||||
|
||||
state.password = "se cret"
|
||||
assertFalse(state.passwordRefused)
|
||||
assertTrue(state.canGoNext)
|
||||
assertTrue(state.mandatoryComplete)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun keepingALoginWithAStorablePasswordSkipsTheLoginPage() {
|
||||
val state = SetupWizardState(configuredProfile())
|
||||
state.chooseLoginSource(WizardSource.KEEP)
|
||||
state.chooseStationSource(WizardSource.KEEP)
|
||||
state.next()
|
||||
|
||||
assertFalse(state.pages.contains(WizardPage.LOGIN))
|
||||
assertEquals(WizardPage.PERSONAL, state.page)
|
||||
state.next()
|
||||
assertEquals(WizardPage.SUMMARY, state.page)
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ import java.nio.file.StandardCopyOption
|
||||
* What the wizard does to a real preferences file: nothing until Save, exactly the answers
|
||||
* afterwards, and every setting it never asked about left as it was.
|
||||
*/
|
||||
class SetupWizardWriteTest(@TempDir private val directory: Path) {
|
||||
class SetupWizardWriteTest(@param:TempDir private val directory: Path) {
|
||||
|
||||
/** A copy of the bundled template, read the way the runtime reads a profile. */
|
||||
private fun templateFile(): Path {
|
||||
|
||||
Reference in new issue
Block a user