mirror of
https://github.com/praktimarc/kst4contest.git
synced 2026-11-19 01:52:29 +01:00
Let the wizard window tests find only the wizard's dialog
Written-by: Codex (GPT-6.2 Sol) Written-by: Claude Fable 5.2
This commit is contained in:
1 file changed
+25
-4
+25
-4
@@ -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 <T> 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<SetupWizardOutcome> { SetupWizardWindow.show(SetupWizardState(prefs), prefs) }
|
||||
val call = worker.submit<SetupWizardOutcome> {
|
||||
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.
|
||||
|
||||
Reference in new issue
Block a user