fix: fixed tests and doc

pull/98/head
RuiAlonso 4 years ago
parent 90099d017c
commit 8d4827d000

@ -1,5 +1,3 @@
// ignore_for_file: public_member_api_docs
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:leaderboard_repository/leaderboard_repository.dart'; import 'package:leaderboard_repository/leaderboard_repository.dart';
@ -16,7 +14,10 @@ class GameOverDialog extends StatelessWidget {
const GameOverDialog({Key? key, required this.score, required this.theme}) const GameOverDialog({Key? key, required this.score, required this.theme})
: super(key: key); : super(key: key);
/// Score achieved by the current user.
final int score; final int score;
/// Theme of the current user.
final CharacterTheme theme; final CharacterTheme theme;
@override @override
@ -30,11 +31,22 @@ class GameOverDialog extends StatelessWidget {
} }
} }
/// {@template game_over_dialog_view}
/// View for showing final score when the game is finished.
/// {@endtemplate}
@visibleForTesting
class GameOverDialogView extends StatefulWidget { class GameOverDialogView extends StatefulWidget {
const GameOverDialogView({Key? key, required this.score, required this.theme}) /// {@macro game_over_dialog_view}
: super(key: key); const GameOverDialogView({
Key? key,
required this.score,
required this.theme,
}) : super(key: key);
/// Score achieved by the current user.
final int score; final int score;
/// Theme of the current user.
final CharacterTheme theme; final CharacterTheme theme;
@override @override
@ -81,6 +93,7 @@ class _GameOverDialogViewState extends State<GameOverDialogView> {
height: 15, height: 15,
), ),
TextField( TextField(
key: const Key('player_initials_text_field'),
controller: playerInitialsInputController, controller: playerInitialsInputController,
textCapitalization: TextCapitalization.characters, textCapitalization: TextCapitalization.characters,
decoration: InputDecoration( decoration: InputDecoration(

@ -31,8 +31,16 @@ void main() {
group('GameOverDialogView', () { group('GameOverDialogView', () {
late LeaderboardBloc leaderboardBloc; late LeaderboardBloc leaderboardBloc;
final leaderboard = [
LeaderboardEntry(
rank: '1',
playerInitials: 'ABC',
score: 5000,
character: DashTheme().characterAsset,
),
];
final entryData = LeaderboardEntryData( final entryData = LeaderboardEntryData(
playerInitials: '', playerInitials: 'VGV',
score: 10000, score: 10000,
character: CharacterType.dash, character: CharacterType.dash,
); );
@ -54,8 +62,8 @@ void main() {
BlocProvider.value( BlocProvider.value(
value: leaderboardBloc, value: leaderboardBloc,
child: GameOverDialogView( child: GameOverDialogView(
score: 10000, score: entryData.score,
theme: DashTheme(), theme: entryData.character.toTheme,
), ),
), ),
); );
@ -77,8 +85,8 @@ void main() {
BlocProvider.value( BlocProvider.value(
value: leaderboardBloc, value: leaderboardBloc,
child: GameOverDialogView( child: GameOverDialogView(
score: 10000, score: entryData.score,
theme: DashTheme(), theme: entryData.character.toTheme,
), ),
), ),
); );
@ -96,14 +104,7 @@ void main() {
initialState: LeaderboardState( initialState: LeaderboardState(
status: LeaderboardStatus.success, status: LeaderboardStatus.success,
ranking: LeaderboardRanking(ranking: 1, outOf: 2), ranking: LeaderboardRanking(ranking: 1, outOf: 2),
leaderboard: [ leaderboard: leaderboard,
LeaderboardEntry(
rank: '1',
playerInitials: 'ABC',
score: 5000,
character: DashTheme().characterAsset,
),
],
), ),
); );
@ -111,8 +112,8 @@ void main() {
BlocProvider.value( BlocProvider.value(
value: leaderboardBloc, value: leaderboardBloc,
child: GameOverDialogView( child: GameOverDialogView(
score: 10000, score: entryData.score,
theme: DashTheme(), theme: entryData.character.toTheme,
), ),
), ),
); );
@ -143,10 +144,14 @@ void main() {
), ),
); );
await tester.enterText(
find.byKey(const Key('player_initials_text_field')),
entryData.playerInitials,
);
final button = find.widgetWithText(TextButton, l10n.addUser); final button = find.widgetWithText(TextButton, l10n.addUser);
await tester.ensureVisible(button); await tester.ensureVisible(button);
await tester.tap(button); await tester.tap(button);
await tester.pumpAndSettle();
verify( verify(
() => leaderboardBloc.add(LeaderboardEntryAdded(entry: entryData)), () => leaderboardBloc.add(LeaderboardEntryAdded(entry: entryData)),
@ -163,15 +168,8 @@ void main() {
const Stream<LeaderboardState>.empty(), const Stream<LeaderboardState>.empty(),
initialState: LeaderboardState( initialState: LeaderboardState(
status: LeaderboardStatus.success, status: LeaderboardStatus.success,
ranking: LeaderboardRanking(ranking: 0, outOf: 0), ranking: LeaderboardRanking(ranking: 1, outOf: 2),
leaderboard: [ leaderboard: leaderboard,
LeaderboardEntry(
rank: '1',
playerInitials: 'ABC',
score: 10000,
character: DashTheme().characterAsset,
),
],
), ),
); );
@ -179,8 +177,8 @@ void main() {
BlocProvider.value( BlocProvider.value(
value: leaderboardBloc, value: leaderboardBloc,
child: GameOverDialogView( child: GameOverDialogView(
score: 10000, score: entryData.score,
theme: DashTheme(), theme: entryData.character.toTheme,
), ),
), ),
navigator: navigator, navigator: navigator,
@ -189,7 +187,6 @@ void main() {
final button = find.widgetWithText(TextButton, l10n.leaderboard); final button = find.widgetWithText(TextButton, l10n.leaderboard);
await tester.ensureVisible(button); await tester.ensureVisible(button);
await tester.tap(button); await tester.tap(button);
await tester.pumpAndSettle();
verify(() => navigator.push<void>(any())).called(1); verify(() => navigator.push<void>(any())).called(1);
}); });

@ -1,4 +1,3 @@
import 'package:bloc_test/bloc_test.dart';
import 'package:flame/components.dart'; import 'package:flame/components.dart';
import 'package:flame/input.dart'; import 'package:flame/input.dart';
import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_forge2d/flame_forge2d.dart';

Loading…
Cancel
Save