pull/254/head
arturplaczek 3 years ago
parent 8017cde249
commit 7f6eb96baf

@ -8,6 +8,7 @@ import 'package:leaderboard_repository/leaderboard_repository.dart';
import 'package:mockingjay/mockingjay.dart'; import 'package:mockingjay/mockingjay.dart';
import 'package:pinball/l10n/l10n.dart'; import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/leaderboard/leaderboard.dart'; import 'package:pinball/leaderboard/leaderboard.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_theme/pinball_theme.dart'; import 'package:pinball_theme/pinball_theme.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
@ -145,21 +146,25 @@ void main() {
expect(find.byType(ListView), findsOneWidget); expect(find.byType(ListView), findsOneWidget);
}); });
testWidgets('navigates to CharacterSelectionPage when retry is tapped', testWidgets('adds PlayTapped event when retry is tapped', (tester) async {
(tester) async { final startGameBloc = MockStartGameBloc();
final navigator = MockNavigator();
when(() => navigator.push<void>(any())).thenAnswer((_) async {}); whenListen(
startGameBloc,
Stream.value(const StartGameState.initial()),
initialState: const StartGameState.initial(),
);
await tester.pumpApp( await tester.pumpApp(
LeaderboardPage( LeaderboardPage(
theme: DashTheme(), theme: DashTheme(),
), ),
navigator: navigator, startGameBloc: startGameBloc,
); );
await tester.ensureVisible(find.byType(TextButton)); await tester.ensureVisible(find.byType(TextButton));
await tester.tap(find.byType(TextButton)); await tester.tap(find.byType(TextButton));
verify(() => navigator.push<void>(any())).called(1); verify(() => startGameBloc.add(PlayTapped())).called(1);
}); });
}); });
} }

@ -11,7 +11,7 @@ void main() {
group('loads SpriteAnimationWidget correctly for', () { group('loads SpriteAnimationWidget correctly for', () {
setUpAll(() async { setUpAll(() async {
await StarAnimation.loadAssets(); await Future.wait<void>(StarAnimation.loadAssets());
}); });
testWidgets('starA', (tester) async { testWidgets('starA', (tester) async {

@ -8,16 +8,41 @@ import 'package:pinball/start_game/start_game.dart';
import '../../helpers/helpers.dart'; import '../../helpers/helpers.dart';
class MockBuildContext extends Mock implements BuildContext {}
void main() { void main() {
late StartGameBloc startGameBloc; late StartGameBloc startGameBloc;
late CharacterThemeCubit characterThemeCubit;
late PinballGame pinballGame; late PinballGame pinballGame;
late GameFlowController gameController;
setUpAll(() async {
await Future.wait<void>(
[
...SelectedCharacter.loadAssets(MockBuildContext()),
...StarAnimation.loadAssets(),
],
);
});
group('StartGameListener', () { setUp(() {
setUp(() { startGameBloc = MockStartGameBloc();
startGameBloc = MockStartGameBloc(); characterThemeCubit = MockCharacterThemeCubit();
pinballGame = MockPinballGame(); pinballGame = MockPinballGame();
}); gameController = MockGameFlowController();
when(() => pinballGame.gameFlowController).thenAnswer(
(_) => gameController,
);
whenListen(
characterThemeCubit,
Stream.value(const CharacterThemeState.initial()),
initialState: const CharacterThemeState.initial(),
);
});
group('StartGameListener', () {
testWidgets( testWidgets(
'on selectCharacter status shows SelectCharacter dialog', 'on selectCharacter status shows SelectCharacter dialog',
(tester) async { (tester) async {
@ -35,9 +60,10 @@ void main() {
child: const SizedBox.shrink(), child: const SizedBox.shrink(),
), ),
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
characterThemeCubit: characterThemeCubit,
); );
await tester.pumpAndSettle(); await tester.pump();
expect( expect(
find.byType(CharacterSelectionDialog), find.byType(CharacterSelectionDialog),
@ -63,9 +89,10 @@ void main() {
child: const SizedBox.shrink(), child: const SizedBox.shrink(),
), ),
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
characterThemeCubit: characterThemeCubit,
); );
await tester.pumpAndSettle(); await tester.pump();
expect( expect(
find.byType(HowToPlayDialog), find.byType(HowToPlayDialog),
@ -75,7 +102,7 @@ void main() {
); );
testWidgets( testWidgets(
'on play status call start on game controller', 'do nothing on play status',
(tester) async { (tester) async {
whenListen( whenListen(
startGameBloc, startGameBloc,
@ -85,10 +112,6 @@ void main() {
initialState: const StartGameState.initial(), initialState: const StartGameState.initial(),
); );
final gameController = MockGameFlowController();
when(() => pinballGame.gameFlowController)
.thenAnswer((invocation) => gameController);
await tester.pumpApp( await tester.pumpApp(
StartGameListener( StartGameListener(
game: pinballGame, game: pinballGame,
@ -97,10 +120,16 @@ void main() {
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
); );
await tester.pumpAndSettle(kThemeAnimationDuration); await tester.pump();
await tester.pumpAndSettle(kThemeAnimationDuration);
verify(gameController.start).called(1); expect(
find.byType(HowToPlayDialog),
findsNothing,
);
expect(
find.byType(CharacterSelectionDialog),
findsNothing,
);
}, },
); );
@ -123,7 +152,7 @@ void main() {
startGameBloc: startGameBloc, startGameBloc: startGameBloc,
); );
await tester.pumpAndSettle(); await tester.pump();
expect( expect(
find.byType(HowToPlayDialog), find.byType(HowToPlayDialog),

Loading…
Cancel
Save