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/components/backbox/bloc/backbox_bloc_test.dart

202 lines
6.2 KiB

// ignore_for_file: prefer_const_constructors
import 'package:bloc_test/bloc_test.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart';
import 'package:mocktail/mocktail.dart';
import 'package:pinball/game/components/backbox/bloc/backbox_bloc.dart';
import 'package:pinball_theme/pinball_theme.dart';
class _MockLeaderboardRepository extends Mock implements LeaderboardRepository {
}
void main() {
late LeaderboardRepository leaderboardRepository;
const emptyEntries = <LeaderboardEntryData>[];
const filledEntries = [LeaderboardEntryData.empty];
group('BackboxBloc', () {
test('inits state with LeaderboardSuccessState when has entries', () {
leaderboardRepository = _MockLeaderboardRepository();
final bloc = BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: filledEntries,
);
expect(bloc.state, isA<LeaderboardSuccessState>());
});
test('inits state with LeaderboardFailureState when has no entries', () {
leaderboardRepository = _MockLeaderboardRepository();
final bloc = BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: null,
);
expect(bloc.state, isA<LeaderboardFailureState>());
});
blocTest<BackboxBloc, BackboxState>(
'adds InitialsFormState on PlayerInitialsRequested',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(
PlayerInitialsRequested(
score: 100,
character: AndroidTheme(),
),
),
expect: () => [
InitialsFormState(score: 100, character: AndroidTheme()),
],
);
group('PlayerInitialsSubmitted', () {
blocTest<BackboxBloc, BackboxState>(
'adds [LoadingState, InitialsSuccessState] when submission succeeds',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
when(
() => leaderboardRepository.addLeaderboardEntry(
LeaderboardEntryData(
playerInitials: 'AAA',
score: 10,
character: CharacterType.dash,
),
),
).thenAnswer((_) async {});
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(
PlayerInitialsSubmitted(
score: 10,
initials: 'AAA',
character: DashTheme(),
),
),
expect: () => [
LoadingState(),
feat: `GameOverInfoDisplay` on game over `Backbox` (#359) * feat: info screen ui * feat: info screen ui * feat: replay button * feat: added replay button and game flow * feat: game over info display flow at backbox * test: fixed tests and coverage * test: fix tests and coverage * chore: info display doc" * refactor: text component name * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/view/widgets/replay_button_overlay_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/view/widgets/replay_button_overlay.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/bloc/backbox_bloc_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: changed names and removed replaying * refactor: removed restart logic changes for another pr * feat: link underscore * chore: test fixed, names changed * chore: unused import * feat: add replayButtonOverlay at GameOverInfoDisplay * feat: added open source url url launcher * feat: launch url and test * chore: removed comments * fix: remove overlay for Replay to merge info screen * chore: unused import * test: load images bug fix * Update lib/game/components/backbox/displays/game_over_info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: removed props from state for sharing only score * feat: moved open links to info display and added link to OS * test: fixed merge tests * chore: unused imports and annotation missed * Update lib/game/components/backbox/bloc/backbox_state.dart * chore: tappables added to cspell Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> Co-authored-by: Tom Arra <tarra3@gmail.com>
3 years ago
InitialsSuccessState(score: 10),
],
);
blocTest<BackboxBloc, BackboxState>(
'adds [LoadingState, InitialsFailureState] when submission fails',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
when(
() => leaderboardRepository.addLeaderboardEntry(
LeaderboardEntryData(
playerInitials: 'AAA',
score: 10,
character: CharacterType.dash,
),
),
).thenThrow(Exception('Error'));
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(
PlayerInitialsSubmitted(
score: 10,
initials: 'AAA',
character: DashTheme(),
),
),
expect: () => [
LoadingState(),
InitialsFailureState(score: 10, character: DashTheme()),
],
);
});
feat: `GameOverInfoDisplay` on game over `Backbox` (#359) * feat: info screen ui * feat: info screen ui * feat: replay button * feat: added replay button and game flow * feat: game over info display flow at backbox * test: fixed tests and coverage * test: fix tests and coverage * chore: info display doc" * refactor: text component name * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/bloc/backbox_state.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/start_game/widgets/start_game_listener_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/view/widgets/replay_button_overlay_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/info_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/view/widgets/replay_button_overlay.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/bloc/backbox_bloc_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/l10n/arb/app_en.arb Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: changed names and removed replaying * refactor: removed restart logic changes for another pr * feat: link underscore * chore: test fixed, names changed * chore: unused import * feat: add replayButtonOverlay at GameOverInfoDisplay * feat: added open source url url launcher * feat: launch url and test * chore: removed comments * fix: remove overlay for Replay to merge info screen * chore: unused import * test: load images bug fix * Update lib/game/components/backbox/displays/game_over_info_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: removed props from state for sharing only score * feat: moved open links to info display and added link to OS * test: fixed merge tests * chore: unused imports and annotation missed * Update lib/game/components/backbox/bloc/backbox_state.dart * chore: tappables added to cspell Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> Co-authored-by: Tom Arra <tarra3@gmail.com>
3 years ago
group('ShareScoreRequested', () {
blocTest<BackboxBloc, BackboxState>(
'emits ShareState',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(
ShareScoreRequested(score: 100),
),
expect: () => [
ShareState(score: 100),
],
);
});
feat: social networks `ShareDisplay` (#406) * feat: share screen and tests * chore: assets gen * feat: added share repository * feature: injecting sharerepository * feat: share url * feat: state for showing ShareDisplay at Backbox * test: tests for sharing links * test: backbox tests * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update lib/game/components/backbox/displays/share_display.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/displays/share_display_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * Update test/game/components/backbox/backbox_test.dart Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * refactor: moved down social networks icons * refactor: url and text for share Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>
3 years ago
group('ShareScoreRequested', () {
blocTest<BackboxBloc, BackboxState>(
'emits ShareState',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(
ShareScoreRequested(score: 100),
),
expect: () => [
ShareState(score: 100),
],
);
});
group('LeaderboardRequested', () {
blocTest<BackboxBloc, BackboxState>(
'adds [LoadingState, LeaderboardSuccessState] when request succeeds',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
when(
() => leaderboardRepository.fetchTop10Leaderboard(),
).thenAnswer(
(_) async => [LeaderboardEntryData.empty],
);
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(LeaderboardRequested()),
expect: () => [
LoadingState(),
LeaderboardSuccessState(entries: const [LeaderboardEntryData.empty]),
],
);
blocTest<BackboxBloc, BackboxState>(
'adds [LoadingState, LeaderboardFailureState] when request fails',
setUp: () {
leaderboardRepository = _MockLeaderboardRepository();
when(
() => leaderboardRepository.fetchTop10Leaderboard(),
).thenThrow(Exception('Error'));
},
build: () => BackboxBloc(
leaderboardRepository: leaderboardRepository,
initialEntries: emptyEntries,
),
act: (bloc) => bloc.add(LeaderboardRequested()),
expect: () => [
LoadingState(),
LeaderboardFailureState(),
],
);
});
});
}