feat: Add triggerQuitOnInitForTest to GameScreen for deterministic testing
Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
@@ -135,6 +135,10 @@ class GameScreen extends StatefulWidget {
|
|||||||
@visibleForTesting
|
@visibleForTesting
|
||||||
final bool skipEngineBootstrapForTest;
|
final bool skipEngineBootstrapForTest;
|
||||||
|
|
||||||
|
/// Triggers the quit flow during init for deterministic widget tests.
|
||||||
|
@visibleForTesting
|
||||||
|
final bool triggerQuitOnInitForTest;
|
||||||
|
|
||||||
/// Creates a gameplay screen driven by [wolf3d].
|
/// Creates a gameplay screen driven by [wolf3d].
|
||||||
const GameScreen({
|
const GameScreen({
|
||||||
required this.wolf3d,
|
required this.wolf3d,
|
||||||
@@ -142,6 +146,7 @@ class GameScreen extends StatefulWidget {
|
|||||||
this.hostShortcutRegistry = HostShortcutRegistry.defaults,
|
this.hostShortcutRegistry = HostShortcutRegistry.defaults,
|
||||||
this.appExitHandler,
|
this.appExitHandler,
|
||||||
this.skipEngineBootstrapForTest = false,
|
this.skipEngineBootstrapForTest = false,
|
||||||
|
this.triggerQuitOnInitForTest = false,
|
||||||
super.key,
|
super.key,
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -164,6 +169,9 @@ class _GameScreenState extends State<GameScreen> {
|
|||||||
void initState() {
|
void initState() {
|
||||||
super.initState();
|
super.initState();
|
||||||
if (widget.skipEngineBootstrapForTest) {
|
if (widget.skipEngineBootstrapForTest) {
|
||||||
|
if (widget.triggerQuitOnInitForTest) {
|
||||||
|
unawaited(_quitApplication());
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -262,9 +270,6 @@ class _GameScreenState extends State<GameScreen> {
|
|||||||
await quit;
|
await quit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@visibleForTesting
|
|
||||||
Future<void> debugQuitForTest() => _quitApplication();
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final engine = _engine;
|
final engine = _engine;
|
||||||
|
|||||||
@@ -56,20 +56,14 @@ void main() {
|
|||||||
home: GameScreen(
|
home: GameScreen(
|
||||||
wolf3d: wolf3d,
|
wolf3d: wolf3d,
|
||||||
skipEngineBootstrapForTest: true,
|
skipEngineBootstrapForTest: true,
|
||||||
|
triggerQuitOnInitForTest: true,
|
||||||
appExitHandler: () async {
|
appExitHandler: () async {
|
||||||
appExitCallCount++;
|
appExitCallCount++;
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
await tester.pump(const Duration(milliseconds: 10));
|
||||||
final dynamic state = tester.state(find.byType(GameScreen));
|
|
||||||
|
|
||||||
await Future.wait<void>([
|
|
||||||
state.debugQuitForTest() as Future<void>,
|
|
||||||
state.debugQuitForTest() as Future<void>,
|
|
||||||
state.debugQuitForTest() as Future<void>,
|
|
||||||
]);
|
|
||||||
|
|
||||||
expect(audio.stopAllAudioCallCount, 1);
|
expect(audio.stopAllAudioCallCount, 1);
|
||||||
expect(audio.disposeCallCount, 1);
|
expect(audio.disposeCallCount, 1);
|
||||||
|
|||||||
Reference in New Issue
Block a user