Fixes even more async test issues

pull/505/head
Alvaro Almeida Freire Stivi 1 year ago
parent 3ae8a0c36b
commit d157d81e91
No known key found for this signature in database

@ -300,6 +300,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds PlayerInitialsSubmitted when initials are submitted', 'adds PlayerInitialsSubmitted when initials are submitted',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final state = InitialsFormState( final state = InitialsFormState(
score: 10, score: 10,
character: game.character, character: game.character,
@ -336,6 +337,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds GameOverInfoDisplay when InitialsSuccessState', 'adds GameOverInfoDisplay when InitialsSuccessState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final state = InitialsSuccessState(score: 100); final state = InitialsSuccessState(score: 100);
whenListen( whenListen(
bloc, bloc,
@ -350,6 +352,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -363,6 +366,7 @@ void main() {
'adds the mobile controls overlay ' 'adds the mobile controls overlay '
'when platform is mobile at InitialsFormState', 'when platform is mobile at InitialsFormState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final platformHelper = _MockPlatformHelper(); final platformHelper = _MockPlatformHelper();
final state = InitialsFormState( final state = InitialsFormState(
score: 10, score: 10,
@ -382,6 +386,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -395,6 +400,7 @@ void main() {
'remove the mobile controls overlay ' 'remove the mobile controls overlay '
'when InitialsSuccessState', 'when InitialsSuccessState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final platformHelper = _MockPlatformHelper(); final platformHelper = _MockPlatformHelper();
final state = InitialsSuccessState(score: 10); final state = InitialsSuccessState(score: 10);
whenListen( whenListen(
@ -411,6 +417,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -423,6 +430,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds InitialsSubmissionSuccessDisplay on InitialsSuccessState', 'adds InitialsSubmissionSuccessDisplay on InitialsSuccessState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final state = InitialsSuccessState(score: 100); final state = InitialsSuccessState(score: 100);
whenListen( whenListen(
bloc, bloc,
@ -437,6 +445,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -449,6 +458,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds ShareScoreRequested event when sharing', 'adds ShareScoreRequested event when sharing',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final state = InitialsSuccessState(score: 100); final state = InitialsSuccessState(score: 100);
whenListen( whenListen(
bloc, bloc,
@ -484,6 +494,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds InitialsSubmissionFailureDisplay on InitialsFailureState', 'adds InitialsSubmissionFailureDisplay on InitialsFailureState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
whenListen( whenListen(
bloc, bloc,
Stream<BackboxState>.empty(), Stream<BackboxState>.empty(),
@ -500,6 +511,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -521,6 +533,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds ShareDisplay on ShareState', 'adds ShareDisplay on ShareState',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final state = ShareState(score: 100); final state = ShareState(score: 100);
whenListen( whenListen(
bloc, bloc,
@ -535,6 +548,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
expect( expect(
@ -547,6 +561,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'opens Facebook link when sharing with Facebook', 'opens Facebook link when sharing with Facebook',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
when(() => urlLauncher.canLaunch(any())) when(() => urlLauncher.canLaunch(any()))
.thenAnswer((_) async => true); .thenAnswer((_) async => true);
when( when(
@ -711,6 +726,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'closes the subscription when it is removed', 'closes the subscription when it is removed',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final streamController = StreamController<BackboxState>(); final streamController = StreamController<BackboxState>();
whenListen( whenListen(
bloc, bloc,
@ -751,6 +767,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'adds PlayerInitialsSubmitted when the timer is finished', 'adds PlayerInitialsSubmitted when the timer is finished',
setUp: (game, _) async { setUp: (game, _) async {
await game.onLoad();
final initialState = InitialsFailureState( final initialState = InitialsFailureState(
score: 10, score: 10,
character: theme.DashTheme(), character: theme.DashTheme(),
@ -769,6 +786,7 @@ void main() {
backbox, backbox,
platformHelper: platformHelper, platformHelper: platformHelper,
); );
await game.ready();
}, },
verify: (game, _) async { verify: (game, _) async {
game.update(4); game.update(4);

@ -77,6 +77,7 @@ void main() {
'adds GameBonus.dashNest to the game ' 'adds GameBonus.dashNest to the game '
'when signpost becomes fully activated', 'when signpost becomes fully activated',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad();
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final signpostBloc = _MockSignpostCubit(); final signpostBloc = _MockSignpostCubit();
@ -94,6 +95,7 @@ void main() {
signpostBloc: signpostBloc, signpostBloc: signpostBloc,
); );
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
await game.ready();
streamController.add(SignpostState.active3); streamController.add(SignpostState.active3);
await tester.pump(); await tester.pump();
@ -108,6 +110,7 @@ void main() {
'calls onProgressed and onReset ' 'calls onProgressed and onReset '
'when signpost becomes fully activated', 'when signpost becomes fully activated',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad();
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final dashBumpersBloc = _MockDashBumpersCubit(); final dashBumpersBloc = _MockDashBumpersCubit();
@ -127,6 +130,7 @@ void main() {
dashBumpersBloc: dashBumpersBloc, dashBumpersBloc: dashBumpersBloc,
); );
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
await game.ready();
streamController.add(SignpostState.active3); streamController.add(SignpostState.active3);
await tester.pump(); await tester.pump();
@ -140,6 +144,7 @@ void main() {
'adds BonusBallSpawningBehavior to the game ' 'adds BonusBallSpawningBehavior to the game '
'when signpost becomes fully activated', 'when signpost becomes fully activated',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.onLoad();
final behavior = FlutterForestBonusBehavior(); final behavior = FlutterForestBonusBehavior();
final parent = FlutterForest.test(); final parent = FlutterForest.test();
final signpostBloc = _MockSignpostCubit(); final signpostBloc = _MockSignpostCubit();
@ -157,11 +162,10 @@ void main() {
signpostBloc: signpostBloc, signpostBloc: signpostBloc,
); );
await parent.ensureAdd(behavior); await parent.ensureAdd(behavior);
streamController.add(SignpostState.active3); streamController.add(SignpostState.active3);
await tester.pump();
await game.ready(); await game.ready();
await tester.pump();
expect( expect(
game.descendants().whereType<BonusBallSpawningBehavior>().length, game.descendants().whereType<BonusBallSpawningBehavior>().length,
equals(1), equals(1),

Loading…
Cancel
Save