fix: update test

pull/254/head
arturplaczek 3 years ago
parent 7f6eb96baf
commit 2785f881ba

@ -16,11 +16,13 @@ void main() {
group('PinballGamePage', () {
late CharacterThemeCubit characterThemeCubit;
late GameBloc gameBloc;
late StartGameBloc startGameBloc;
setUp(() async {
await Future.wait<void>(game.preLoadAssets());
characterThemeCubit = MockCharacterThemeCubit();
gameBloc = MockGameBloc();
startGameBloc = MockStartGameBloc();
whenListen(
characterThemeCubit,
@ -28,6 +30,12 @@ void main() {
initialState: const CharacterThemeState.initial(),
);
whenListen(
startGameBloc,
const Stream<StartGameState>.empty(),
initialState: const StartGameState.initial(),
);
whenListen(
gameBloc,
Stream.value(const GameState.initial()),
@ -170,9 +178,17 @@ void main() {
group('PinballGameView', () {
final gameBloc = MockGameBloc();
final startGameBloc = MockStartGameBloc();
late CharacterThemeCubit characterThemeCubit;
setUp(() async {
await Future.wait<void>(game.preLoadAssets());
characterThemeCubit = MockCharacterThemeCubit();
whenListen(
characterThemeCubit,
const Stream<CharacterThemeState>.empty(),
initialState: const CharacterThemeState.initial(),
);
whenListen(
gameBloc,
@ -192,6 +208,7 @@ void main() {
PinballGameView(game: game),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
characterThemeCubit: characterThemeCubit,
);
expect(
@ -216,10 +233,17 @@ void main() {
initialState: startGameState,
);
whenListen(
startGameBloc,
Stream.value(startGameState),
initialState: startGameState,
);
await tester.pumpApp(
PinballGameView(game: game),
gameBloc: gameBloc,
startGameBloc: startGameBloc,
characterThemeCubit: characterThemeCubit,
);
expect(

@ -4,16 +4,25 @@ import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mockingjay/mockingjay.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball/l10n/l10n.dart';
import 'package:pinball/select_character/select_character.dart';
import 'package:pinball/start_game/start_game.dart';
import 'package:pinball_theme/pinball_theme.dart';
import '../helpers/helpers.dart';
class MockBuildContext extends Mock implements BuildContext {}
void main() {
late CharacterThemeCubit characterThemeCubit;
late StartGameBloc startGameBloc;
setUpAll(() async {
await Future.wait<void>(SelectedCharacter.loadAssets(MockBuildContext()));
await Future.wait<void>(StarAnimation.loadAssets());
});
setUp(() {
characterThemeCubit = MockCharacterThemeCubit();
startGameBloc = MockStartGameBloc();
@ -37,15 +46,17 @@ void main() {
group('CharacterSelectionView', () {
testWidgets('renders correctly', (tester) async {
const titleText = 'Choose your character!';
final l10n = await AppLocalizations.delegate.load(const Locale('en'));
await tester.pumpApp(
CharacterSelectionView(),
characterThemeCubit: characterThemeCubit,
);
expect(find.text(titleText), findsOneWidget);
expect(find.text(l10n.characterSelectionTitle), findsOneWidget);
expect(find.text(l10n.characterSelectionSubtitle), findsOneWidget);
expect(find.byType(SelectedCharacter), findsOneWidget);
expect(find.byType(TextButton), findsOneWidget);
expect(find.byType(PinballButton), findsOneWidget);
});
testWidgets('calls characterSelected when a character image is tapped',
@ -76,8 +87,8 @@ void main() {
characterThemeCubit: characterThemeCubit,
startGameBloc: startGameBloc,
);
await tester.ensureVisible(find.byType(TextButton));
await tester.tap(find.byType(TextButton));
await tester.ensureVisible(find.byType(PinballButton));
await tester.tap(find.byType(PinballButton));
await tester.pumpAndSettle();
verify(() => startGameBloc.add(CharacterSelected())).called(1);

Loading…
Cancel
Save