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_bloc/flutter_bloc.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})
: super(key: key);
/// Score achieved by the current user.
final int score;
/// Theme of the current user.
final CharacterTheme theme;
@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 {
const GameOverDialogView({Key? key, required this.score, required this.theme})
: super(key: key);
/// {@macro game_over_dialog_view}
const GameOverDialogView({
Key? key,
required this.score,
required this.theme,
}) : super(key: key);
/// Score achieved by the current user.
final int score;
/// Theme of the current user.
final CharacterTheme theme;
@override
@ -81,6 +93,7 @@ class _GameOverDialogViewState extends State<GameOverDialogView> {
height: 15,
),
TextField(
key: const Key('player_initials_text_field'),
controller: playerInitialsInputController,
textCapitalization: TextCapitalization.characters,
decoration: InputDecoration(

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

Loading…
Cancel
Save