diff --git a/apps/wolf_3d_gui/lib/screens/game_screen.dart b/apps/wolf_3d_gui/lib/screens/game_screen.dart index 1835335..6c2089a 100644 --- a/apps/wolf_3d_gui/lib/screens/game_screen.dart +++ b/apps/wolf_3d_gui/lib/screens/game_screen.dart @@ -135,6 +135,10 @@ class GameScreen extends StatefulWidget { @visibleForTesting final bool skipEngineBootstrapForTest; + /// Triggers the quit flow during init for deterministic widget tests. + @visibleForTesting + final bool triggerQuitOnInitForTest; + /// Creates a gameplay screen driven by [wolf3d]. const GameScreen({ required this.wolf3d, @@ -142,6 +146,7 @@ class GameScreen extends StatefulWidget { this.hostShortcutRegistry = HostShortcutRegistry.defaults, this.appExitHandler, this.skipEngineBootstrapForTest = false, + this.triggerQuitOnInitForTest = false, super.key, }); @@ -164,6 +169,9 @@ class _GameScreenState extends State { void initState() { super.initState(); if (widget.skipEngineBootstrapForTest) { + if (widget.triggerQuitOnInitForTest) { + unawaited(_quitApplication()); + } return; } @@ -262,9 +270,6 @@ class _GameScreenState extends State { await quit; } - @visibleForTesting - Future debugQuitForTest() => _quitApplication(); - @override Widget build(BuildContext context) { final engine = _engine; diff --git a/apps/wolf_3d_gui/test/game_screen_quit_test.dart b/apps/wolf_3d_gui/test/game_screen_quit_test.dart index 24ce1f3..5797ed2 100644 --- a/apps/wolf_3d_gui/test/game_screen_quit_test.dart +++ b/apps/wolf_3d_gui/test/game_screen_quit_test.dart @@ -56,20 +56,14 @@ void main() { home: GameScreen( wolf3d: wolf3d, skipEngineBootstrapForTest: true, + triggerQuitOnInitForTest: true, appExitHandler: () async { appExitCallCount++; }, ), ), ); - - final dynamic state = tester.state(find.byType(GameScreen)); - - await Future.wait([ - state.debugQuitForTest() as Future, - state.debugQuitForTest() as Future, - state.debugQuitForTest() as Future, - ]); + await tester.pump(const Duration(milliseconds: 10)); expect(audio.stopAllAudioCallCount, 1); expect(audio.disposeCallCount, 1);