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:pinball/l10n/l10n.dart';
import 'package:pinball/leaderboard/leaderboard.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_theme/pinball_theme.dart';
import '../../helpers/helpers.dart';
@ -145,21 +146,25 @@ void main() {
expect(find.byType(ListView), findsOneWidget);
});
testWidgets('navigates to CharacterSelectionPage when retry is tapped',
(tester) async {
final navigator = MockNavigator();
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
testWidgets('adds PlayTapped event when retry is tapped', (tester) async {
final startGameBloc = MockStartGameBloc();
whenListen(
startGameBloc,
Stream.value(const StartGameState.initial()),
initialState: const StartGameState.initial(),
);
await tester.pumpApp(
LeaderboardPage(
theme: DashTheme(),
),
navigator: navigator,
startGameBloc: startGameBloc,
);
await tester.ensureVisible(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', () {
setUpAll(() async {
await StarAnimation.loadAssets();
await Future.wait<void>(StarAnimation.loadAssets());
});
testWidgets('starA', (tester) async {

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

Loading…
Cancel
Save