You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pinball/test/game/view/widgets/round_count_display_test.dart

137 lines
3.1 KiB

import 'package:bloc_test/bloc_test.dart';
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/game.dart';
import 'package:pinball_ui/pinball_ui.dart';
import '../../../helpers/helpers.dart';
class _MockGameBloc extends Mock implements GameBloc {}
void main() {
group('RoundCountDisplay renders', () {
late GameBloc gameBloc;
const initialState = GameState(
score: 0,
feat: game bloc multiplier (#213) * feat: added events for multiplier * feat: added events for increment, apply and reset multiplier * feat: added multiplier to game bloc state * test: test for multiplier at game bloc * test: added multiplier to game state * refactor: multiplier always increased by 1 * refactor: add multiplier state on BallLost * refactor: added round to game state and changed gameover and ball lost logic * test: fixed tests for game bloc * refactor: multiplier max value 6 at game bloc * test: fixed tests with new game over logic * chore: properties renamed and removed unused * Update lib/game/bloc/game_event.dart Co-authored-by: Alejandro Santiago <dev@alestiago.com> * fix: pubspec from main * refactor: pubspec from main * chore: removed unused import * feat: ball added event to game bloc * test: fixed test for ball added * feat: added BallAdded event on ball mounted * test: fixing tests for BallAdded * test: flamebloctester for ball added * test: refactored tests for pinballgame * refactor: BallAdded event on ball mounted * chore: removed unnecessary imports * test: refactor tests for pinball_game * refactor: use rounds instead of balls * refactor: changed BallLost event with RoundLost, and moved part of the logic to controlled_ball * test: tests for RoundLost * fix: fixed wrong tests for pinball_game * test: remove deleted balls property from GameState * chore: doc Co-authored-by: Alejandro Santiago <dev@alestiago.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
2 years ago
multiplier: 1,
rounds: 3,
bonusHistory: [],
);
setUp(() {
gameBloc = _MockGameBloc();
whenListen(
gameBloc,
Stream.value(initialState),
initialState: initialState,
);
});
testWidgets('three active round indicator', (tester) async {
await tester.pumpApp(
const RoundCountDisplay(),
gameBloc: gameBloc,
);
await tester.pump();
expect(find.byType(RoundIndicator), findsNWidgets(3));
});
testWidgets('two active round indicator', (tester) async {
final state = initialState.copyWith(
feat: game bloc multiplier (#213) * feat: added events for multiplier * feat: added events for increment, apply and reset multiplier * feat: added multiplier to game bloc state * test: test for multiplier at game bloc * test: added multiplier to game state * refactor: multiplier always increased by 1 * refactor: add multiplier state on BallLost * refactor: added round to game state and changed gameover and ball lost logic * test: fixed tests for game bloc * refactor: multiplier max value 6 at game bloc * test: fixed tests with new game over logic * chore: properties renamed and removed unused * Update lib/game/bloc/game_event.dart Co-authored-by: Alejandro Santiago <dev@alestiago.com> * fix: pubspec from main * refactor: pubspec from main * chore: removed unused import * feat: ball added event to game bloc * test: fixed test for ball added * feat: added BallAdded event on ball mounted * test: fixing tests for BallAdded * test: flamebloctester for ball added * test: refactored tests for pinballgame * refactor: BallAdded event on ball mounted * chore: removed unnecessary imports * test: refactor tests for pinball_game * refactor: use rounds instead of balls * refactor: changed BallLost event with RoundLost, and moved part of the logic to controlled_ball * test: tests for RoundLost * fix: fixed wrong tests for pinball_game * test: remove deleted balls property from GameState * chore: doc Co-authored-by: Alejandro Santiago <dev@alestiago.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
2 years ago
rounds: 2,
);
whenListen(
gameBloc,
Stream.value(state),
initialState: state,
);
await tester.pumpApp(
const RoundCountDisplay(),
gameBloc: gameBloc,
);
await tester.pump();
expect(
find.byWidgetPredicate(
(widget) => widget is RoundIndicator && widget.isActive,
),
findsNWidgets(2),
);
expect(
find.byWidgetPredicate(
(widget) => widget is RoundIndicator && !widget.isActive,
),
findsOneWidget,
);
});
testWidgets('one active round indicator', (tester) async {
final state = initialState.copyWith(
feat: game bloc multiplier (#213) * feat: added events for multiplier * feat: added events for increment, apply and reset multiplier * feat: added multiplier to game bloc state * test: test for multiplier at game bloc * test: added multiplier to game state * refactor: multiplier always increased by 1 * refactor: add multiplier state on BallLost * refactor: added round to game state and changed gameover and ball lost logic * test: fixed tests for game bloc * refactor: multiplier max value 6 at game bloc * test: fixed tests with new game over logic * chore: properties renamed and removed unused * Update lib/game/bloc/game_event.dart Co-authored-by: Alejandro Santiago <dev@alestiago.com> * fix: pubspec from main * refactor: pubspec from main * chore: removed unused import * feat: ball added event to game bloc * test: fixed test for ball added * feat: added BallAdded event on ball mounted * test: fixing tests for BallAdded * test: flamebloctester for ball added * test: refactored tests for pinballgame * refactor: BallAdded event on ball mounted * chore: removed unnecessary imports * test: refactor tests for pinball_game * refactor: use rounds instead of balls * refactor: changed BallLost event with RoundLost, and moved part of the logic to controlled_ball * test: tests for RoundLost * fix: fixed wrong tests for pinball_game * test: remove deleted balls property from GameState * chore: doc Co-authored-by: Alejandro Santiago <dev@alestiago.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
2 years ago
rounds: 1,
);
whenListen(
gameBloc,
Stream.value(state),
initialState: state,
);
await tester.pumpApp(
const RoundCountDisplay(),
gameBloc: gameBloc,
);
await tester.pump();
expect(
find.byWidgetPredicate(
(widget) => widget is RoundIndicator && widget.isActive,
),
findsOneWidget,
);
expect(
find.byWidgetPredicate(
(widget) => widget is RoundIndicator && !widget.isActive,
),
findsNWidgets(2),
);
});
});
testWidgets('active round indicator is displaying with proper color',
(tester) async {
await tester.pumpApp(
const RoundIndicator(isActive: true),
);
await tester.pump();
expect(
find.byWidgetPredicate(
(widget) => widget is Container && widget.color == PinballColors.yellow,
),
findsOneWidget,
);
});
testWidgets('inactive round indicator is displaying with proper color',
(tester) async {
await tester.pumpApp(
const RoundIndicator(isActive: false),
);
await tester.pump();
expect(
find.byWidgetPredicate(
(widget) =>
widget is Container &&
widget.color == PinballColors.yellow.withAlpha(128),
),
findsOneWidget,
);
});
}