From f871f551f7e72810508cf02530fedb43d1b4c688 Mon Sep 17 00:00:00 2001 From: Philipp Wagner Date: Wed, 18 Nov 2026 19:45:19 +0100 Subject: [PATCH] Let the wizard window tests find only the wizard's dialog Written-by: Codex (GPT-6.2 Sol) Written-by: Claude Fable 5.2 --- .../compose/wizard/SetupWizardWindowTest.kt | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardWindowTest.kt b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardWindowTest.kt index ddf6c46e..b4eaa54c 100644 --- a/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardWindowTest.kt +++ b/app-desktop/src/test/kotlin/kst4contest/view/compose/wizard/SetupWizardWindowTest.kt @@ -5,6 +5,7 @@ import kst4contest.testing.Await.awaitUntil import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Assumptions.assumeFalse import org.junit.jupiter.api.Test +import java.awt.Dialog import java.awt.EventQueue import java.awt.GraphicsEnvironment import java.awt.Window @@ -21,10 +22,16 @@ import java.util.concurrent.TimeUnit */ class SetupWizardWindowTest { - private fun prefs() = ChatPreferences(Path.of("setup-wizard-window-test-unused.xml")) + private companion object { + fun prefs() = ChatPreferences(Path.of("setup-wizard-window-test-unused.xml")) + + val wizardTitle = wizardLanguageStore(SetupWizardState(prefs())).strings.wizardTitle + } private fun showingDialog(): Window? = - Window.getWindows().firstOrNull { it.isShowing && it.javaClass.name.contains("ComposeDialog") } + Window.getWindows().firstOrNull { + it is Dialog && it.isShowing && it.javaClass.name.contains("ComposeDialog") && it.title == wizardTitle + } /** Removes whatever dialog this test still has showing, without waiting and without failing again. */ private fun disposeLeftoverDialog() { @@ -33,6 +40,16 @@ class SetupWizardWindowTest { } } + private fun showWithInterruptedCleanup(show: () -> T): T { + try { + return show() + } catch (interrupted: InterruptedException) { + // invokeAndWait can post the open event after the test's first cleanup was queued. + disposeLeftoverDialog() + throw interrupted + } + } + private val closer = Executors.newSingleThreadExecutor() /** Closes the dialog the way its X does, as soon as it is on screen. */ @@ -55,7 +72,9 @@ class SetupWizardWindowTest { try { val closing = closeOnceShowing() val prefs = prefs() - val call = worker.submit { SetupWizardWindow.show(SetupWizardState(prefs), prefs) } + val call = worker.submit { + showWithInterruptedCleanup { SetupWizardWindow.show(SetupWizardState(prefs), prefs) } + } // A dialog that never appears must fail the test, not hang it. val outcome = call.get(20, TimeUnit.SECONDS) @@ -79,7 +98,9 @@ class SetupWizardWindowTest { val closing = closeOnceShowing() val prefs = prefs() val call = worker.submit { - EventQueue.invokeAndWait { SetupWizardWindow.show(SetupWizardState(prefs), prefs) } + showWithInterruptedCleanup { + EventQueue.invokeAndWait { SetupWizardWindow.show(SetupWizardState(prefs), prefs) } + } } // A deadlock here has no timeout of its own: without one this never completes.