mirror of https://github.com/flutter/pinball.git
feat: add user at end game (#98)
* refactor: move user score to gameover dialog * feat: added input textfield * feat: fixed ui * feat: send user added to bloc and firebase * chore: todo for future ui refactor * feat: capitalize playerinitials to bloc * refactor: show button on success add user * test: fixed tests * test: adding more tests for tap * test: fixed tests * test: fixed tests for gameover dialog pressed buttons * fix: fixed tests and docpull/112/head
parent
90131d9724
commit
4558acd03d
@ -1,44 +1,195 @@
|
|||||||
// ignore_for_file: prefer_const_constructors
|
// ignore_for_file: prefer_const_constructors
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
||||||
import 'package:mockingjay/mockingjay.dart';
|
import 'package:mockingjay/mockingjay.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
import 'package:pinball/game/game.dart';
|
||||||
import 'package:pinball/l10n/l10n.dart';
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball/leaderboard/leaderboard.dart';
|
||||||
import 'package:pinball_theme/pinball_theme.dart';
|
import 'package:pinball_theme/pinball_theme.dart';
|
||||||
|
|
||||||
import '../../../helpers/helpers.dart';
|
import '../../../helpers/helpers.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('GameOverDialog', () {
|
group('GameOverDialog', () {
|
||||||
testWidgets('renders correctly', (tester) async {
|
testWidgets('renders GameOverDialogView', (tester) async {
|
||||||
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
const GameOverDialog(
|
GameOverDialog(
|
||||||
|
score: 1000,
|
||||||
theme: DashTheme(),
|
theme: DashTheme(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(find.text(l10n.gameOver), findsOneWidget);
|
expect(find.byType(GameOverDialogView), findsOneWidget);
|
||||||
expect(find.text(l10n.leaderboard), findsOneWidget);
|
});
|
||||||
|
|
||||||
|
group('GameOverDialogView', () {
|
||||||
|
late LeaderboardBloc leaderboardBloc;
|
||||||
|
|
||||||
|
final leaderboard = [
|
||||||
|
LeaderboardEntry(
|
||||||
|
rank: '1',
|
||||||
|
playerInitials: 'ABC',
|
||||||
|
score: 5000,
|
||||||
|
character: DashTheme().characterAsset,
|
||||||
|
),
|
||||||
|
];
|
||||||
|
final entryData = LeaderboardEntryData(
|
||||||
|
playerInitials: 'VGV',
|
||||||
|
score: 10000,
|
||||||
|
character: CharacterType.dash,
|
||||||
|
);
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
leaderboardBloc = MockLeaderboardBloc();
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: const LeaderboardState.initial(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders input text view when bloc emits [loading]',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.widgetWithText(TextButton, l10n.addUser), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders error view when bloc emits [error]', (tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState.initial()
|
||||||
|
.copyWith(status: LeaderboardStatus.error),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text(l10n.error), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders success view when bloc emits [success]',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState(
|
||||||
|
status: LeaderboardStatus.success,
|
||||||
|
ranking: LeaderboardRanking(ranking: 1, outOf: 2),
|
||||||
|
leaderboard: leaderboard,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.widgetWithText(TextButton, l10n.leaderboard),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('adds LeaderboardEntryAdded when tap on add user button',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState.initial(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.enterText(
|
||||||
|
find.byKey(const Key('player_initials_text_field')),
|
||||||
|
entryData.playerInitials,
|
||||||
|
);
|
||||||
|
|
||||||
|
final button = find.widgetWithText(TextButton, l10n.addUser);
|
||||||
|
await tester.ensureVisible(button);
|
||||||
|
await tester.tap(button);
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => leaderboardBloc.add(LeaderboardEntryAdded(entry: entryData)),
|
||||||
|
).called(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('tapping on leaderboard button navigates to LeaderBoardPage',
|
testWidgets('navigates to LeaderboardPage when tap on leaderboard button',
|
||||||
(tester) async {
|
(tester) async {
|
||||||
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
final navigator = MockNavigator();
|
final navigator = MockNavigator();
|
||||||
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
|
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState(
|
||||||
|
status: LeaderboardStatus.success,
|
||||||
|
ranking: LeaderboardRanking(ranking: 1, outOf: 2),
|
||||||
|
leaderboard: leaderboard,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
const GameOverDialog(
|
BlocProvider.value(
|
||||||
theme: DashTheme(),
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
),
|
),
|
||||||
navigator: navigator,
|
navigator: navigator,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.tap(find.widgetWithText(TextButton, l10n.leaderboard));
|
final button = find.widgetWithText(TextButton, l10n.leaderboard);
|
||||||
|
await tester.ensureVisible(button);
|
||||||
|
await tester.tap(button);
|
||||||
|
|
||||||
verify(() => navigator.push<void>(any())).called(1);
|
verify(() => navigator.push<void>(any())).called(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in new issue