mirror of https://github.com/flutter/pinball.git
feat: user initials submission (#341)
* feat: initial implementation * feat: tests * fix: lint * fix: removing wrong commited images * feat: pr suggestions * feat: PR suggestions * Apply suggestions from code review Co-authored-by: Alejandro Santiago <dev@alestiago.com> * Apply suggestions from code review * Apply suggestions from code review Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com> * fix * pr suggestions * fixing comments * pr suggestions * lint Co-authored-by: Alejandro Santiago <dev@alestiago.com> Co-authored-by: Allison Ryan <77211884+allisonryan0002@users.noreply.github.com>pull/320/head
parent
2ad0196e44
commit
e9b902355d
@ -0,0 +1,56 @@
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
||||
import 'package:pinball/leaderboard/models/leader_board_entry.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart';
|
||||
|
||||
part 'backbox_event.dart';
|
||||
part 'backbox_state.dart';
|
||||
|
||||
/// {@template backbox_bloc}
|
||||
/// Bloc which manages the Backbox display.
|
||||
/// {@endtemplate}
|
||||
class BackboxBloc extends Bloc<BackboxEvent, BackboxState> {
|
||||
/// {@macro backbox_bloc}
|
||||
BackboxBloc({
|
||||
required LeaderboardRepository leaderboardRepository,
|
||||
}) : _leaderboardRepository = leaderboardRepository,
|
||||
super(LoadingState()) {
|
||||
on<PlayerInitialsRequested>(_onPlayerInitialsRequested);
|
||||
on<PlayerInitialsSubmitted>(_onPlayerInitialsSubmitted);
|
||||
}
|
||||
|
||||
final LeaderboardRepository _leaderboardRepository;
|
||||
|
||||
void _onPlayerInitialsRequested(
|
||||
PlayerInitialsRequested event,
|
||||
Emitter<BackboxState> emit,
|
||||
) {
|
||||
emit(
|
||||
InitialsFormState(
|
||||
score: event.score,
|
||||
character: event.character,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _onPlayerInitialsSubmitted(
|
||||
PlayerInitialsSubmitted event,
|
||||
Emitter<BackboxState> emit,
|
||||
) async {
|
||||
try {
|
||||
emit(LoadingState());
|
||||
await _leaderboardRepository.addLeaderboardEntry(
|
||||
LeaderboardEntryData(
|
||||
playerInitials: event.initials,
|
||||
score: event.score,
|
||||
character: event.character.toType,
|
||||
),
|
||||
);
|
||||
emit(InitialsSuccessState());
|
||||
} catch (error, stackTrace) {
|
||||
addError(error, stackTrace);
|
||||
emit(InitialsFailureState());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,53 @@
|
||||
part of 'backbox_bloc.dart';
|
||||
|
||||
/// {@template backbox_event}
|
||||
/// Base class for backbox events.
|
||||
/// {@endtemplate}
|
||||
abstract class BackboxEvent extends Equatable {
|
||||
/// {@macro backbox_event}
|
||||
const BackboxEvent();
|
||||
}
|
||||
|
||||
/// {@template player_initials_requested}
|
||||
/// Event that triggers the user initials display.
|
||||
/// {@endtemplate}
|
||||
class PlayerInitialsRequested extends BackboxEvent {
|
||||
/// {@macro player_initials_requested}
|
||||
const PlayerInitialsRequested({
|
||||
required this.score,
|
||||
required this.character,
|
||||
});
|
||||
|
||||
/// Player's score.
|
||||
final int score;
|
||||
|
||||
/// Player's character.
|
||||
final CharacterTheme character;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [score, character];
|
||||
}
|
||||
|
||||
/// {@template player_initials_submitted}
|
||||
/// Event that submits the user score and initials.
|
||||
/// {@endtemplate}
|
||||
class PlayerInitialsSubmitted extends BackboxEvent {
|
||||
/// {@macro player_initials_submitted}
|
||||
const PlayerInitialsSubmitted({
|
||||
required this.score,
|
||||
required this.initials,
|
||||
required this.character,
|
||||
});
|
||||
|
||||
/// Player's score.
|
||||
final int score;
|
||||
|
||||
/// Player's initials.
|
||||
final String initials;
|
||||
|
||||
/// Player's character.
|
||||
final CharacterTheme character;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [score, initials, character];
|
||||
}
|
@ -0,0 +1,59 @@
|
||||
part of 'backbox_bloc.dart';
|
||||
|
||||
/// {@template backbox_state}
|
||||
/// The base state for all [BackboxState].
|
||||
/// {@endtemplate backbox_state}
|
||||
abstract class BackboxState extends Equatable {
|
||||
/// {@macro backbox_state}
|
||||
const BackboxState();
|
||||
}
|
||||
|
||||
/// Loading state for the backbox.
|
||||
class LoadingState extends BackboxState {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// State when the leaderboard was successfully loaded.
|
||||
class LeaderboardSuccessState extends BackboxState {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// State when the leaderboard failed to load.
|
||||
class LeaderboardFailureState extends BackboxState {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// {@template initials_form_state}
|
||||
/// State when the user is inputting their initials.
|
||||
/// {@endtemplate}
|
||||
class InitialsFormState extends BackboxState {
|
||||
/// {@macro initials_form_state}
|
||||
const InitialsFormState({
|
||||
required this.score,
|
||||
required this.character,
|
||||
}) : super();
|
||||
|
||||
/// Player's score.
|
||||
final int score;
|
||||
|
||||
/// Player's character.
|
||||
final CharacterTheme character;
|
||||
|
||||
@override
|
||||
List<Object?> get props => [score, character];
|
||||
}
|
||||
|
||||
/// State when the leaderboard was successfully loaded.
|
||||
class InitialsSuccessState extends BackboxState {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
||||
|
||||
/// State when the initials submission failed.
|
||||
class InitialsFailureState extends BackboxState {
|
||||
@override
|
||||
List<Object?> get props => [];
|
||||
}
|
@ -1 +1,4 @@
|
||||
export 'initials_input_display.dart';
|
||||
export 'initials_submission_failure_display.dart';
|
||||
export 'initials_submission_success_display.dart';
|
||||
export 'loading_display.dart';
|
||||
|
@ -0,0 +1,28 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_ui/pinball_ui.dart';
|
||||
|
||||
final _bodyTextPaint = TextPaint(
|
||||
style: const TextStyle(
|
||||
fontSize: 3,
|
||||
color: PinballColors.white,
|
||||
fontFamily: PinballFonts.pixeloidSans,
|
||||
),
|
||||
);
|
||||
|
||||
/// {@template initials_submission_failure_display}
|
||||
/// [Backbox] display for when a failure occurs during initials submission.
|
||||
/// {@endtemplate}
|
||||
class InitialsSubmissionFailureDisplay extends TextComponent
|
||||
with HasGameRef<PinballGame> {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
position = Vector2(0, -10);
|
||||
anchor = Anchor.center;
|
||||
text = 'Failure!';
|
||||
textRenderer = _bodyTextPaint;
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_ui/pinball_ui.dart';
|
||||
|
||||
final _bodyTextPaint = TextPaint(
|
||||
style: const TextStyle(
|
||||
fontSize: 3,
|
||||
color: PinballColors.white,
|
||||
fontFamily: PinballFonts.pixeloidSans,
|
||||
),
|
||||
);
|
||||
|
||||
/// {@template initials_submission_success_display}
|
||||
/// [Backbox] display for initials successfully submitted.
|
||||
/// {@endtemplate}
|
||||
class InitialsSubmissionSuccessDisplay extends TextComponent
|
||||
with HasGameRef<PinballGame> {
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
position = Vector2(0, -10);
|
||||
anchor = Anchor.center;
|
||||
text = 'Success!';
|
||||
textRenderer = _bodyTextPaint;
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_ui/pinball_ui.dart';
|
||||
|
||||
final _bodyTextPaint = TextPaint(
|
||||
style: const TextStyle(
|
||||
fontSize: 3,
|
||||
color: PinballColors.white,
|
||||
fontFamily: PinballFonts.pixeloidSans,
|
||||
),
|
||||
);
|
||||
|
||||
/// {@template loading_display}
|
||||
/// Display used to show the loading animation.
|
||||
/// {@endtemplate}
|
||||
class LoadingDisplay extends TextComponent with HasGameRef<PinballGame> {
|
||||
/// {@template loading_display}
|
||||
LoadingDisplay();
|
||||
|
||||
late final String _label;
|
||||
|
||||
@override
|
||||
Future<void> onLoad() async {
|
||||
await super.onLoad();
|
||||
|
||||
position = Vector2(0, -10);
|
||||
anchor = Anchor.center;
|
||||
text = _label = gameRef.l10n.loading;
|
||||
textRenderer = _bodyTextPaint;
|
||||
|
||||
await add(
|
||||
TimerComponent(
|
||||
period: 1,
|
||||
repeat: true,
|
||||
onTick: () {
|
||||
final index = text.indexOf('.');
|
||||
if (index != -1 && text.substring(index).length == 3) {
|
||||
text = _label;
|
||||
} else {
|
||||
text = '$text.';
|
||||
}
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
@ -0,0 +1,92 @@
|
||||
// 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;
|
||||
|
||||
group('BackboxBloc', () {
|
||||
blocTest<BackboxBloc, BackboxState>(
|
||||
'adds InitialsFormState on PlayerInitialsRequested',
|
||||
setUp: () {
|
||||
leaderboardRepository = _MockLeaderboardRepository();
|
||||
},
|
||||
build: () => BackboxBloc(leaderboardRepository: leaderboardRepository),
|
||||
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),
|
||||
act: (bloc) => bloc.add(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 10,
|
||||
initials: 'AAA',
|
||||
character: DashTheme(),
|
||||
),
|
||||
),
|
||||
expect: () => [
|
||||
LoadingState(),
|
||||
InitialsSuccessState(),
|
||||
],
|
||||
);
|
||||
|
||||
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),
|
||||
act: (bloc) => bloc.add(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 10,
|
||||
initials: 'AAA',
|
||||
character: DashTheme(),
|
||||
),
|
||||
),
|
||||
expect: () => [
|
||||
LoadingState(),
|
||||
InitialsFailureState(),
|
||||
],
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/components/backbox/bloc/backbox_bloc.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart';
|
||||
|
||||
void main() {
|
||||
group('BackboxEvent', () {
|
||||
group('PlayerInitialsRequested', () {
|
||||
test('can be instantiated', () {
|
||||
expect(
|
||||
PlayerInitialsRequested(score: 0, character: AndroidTheme()),
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
PlayerInitialsRequested(score: 0, character: AndroidTheme()),
|
||||
equals(
|
||||
PlayerInitialsRequested(score: 0, character: AndroidTheme()),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsRequested(score: 0, character: AndroidTheme()),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsRequested(score: 1, character: AndroidTheme()),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsRequested(score: 0, character: AndroidTheme()),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsRequested(score: 0, character: SparkyTheme()),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('PlayerInitialsSubmitted', () {
|
||||
test('can be instantiated', () {
|
||||
expect(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
equals(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 1,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: SparkyTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmitted(
|
||||
score: 0,
|
||||
initials: 'BBB',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,116 @@
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/components/backbox/bloc/backbox_bloc.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart';
|
||||
|
||||
void main() {
|
||||
group('BackboxState', () {
|
||||
group('LoadingState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(LoadingState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(LoadingState(), equals(LoadingState()));
|
||||
});
|
||||
});
|
||||
|
||||
group('LeaderboardSuccessState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(LeaderboardSuccessState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(LeaderboardSuccessState(), equals(LeaderboardSuccessState()));
|
||||
});
|
||||
});
|
||||
|
||||
group('LeaderboardFailureState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(LeaderboardFailureState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(LeaderboardFailureState(), equals(LeaderboardFailureState()));
|
||||
});
|
||||
});
|
||||
|
||||
group('InitialsFormState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
equals(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
InitialsFormState(
|
||||
score: 1,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
InitialsFormState(
|
||||
score: 0,
|
||||
character: SparkyTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('InitialsSuccessState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(InitialsSuccessState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(InitialsSuccessState(), equals(InitialsSuccessState()));
|
||||
});
|
||||
|
||||
group('InitialsFailureState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(InitialsFailureState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(InitialsFailureState(), equals(InitialsFailureState()));
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/components/backbox/displays/initials_submission_failure_display.dart';
|
||||
|
||||
import '../../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('InitialsSubmissionFailureDisplay', () {
|
||||
final flameTester = FlameTester(EmptyKeyboardPinballTestGame.new);
|
||||
|
||||
flameTester.test('renders correctly', (game) async {
|
||||
await game.ensureAdd(InitialsSubmissionFailureDisplay());
|
||||
|
||||
final component = game.firstChild<TextComponent>();
|
||||
expect(component, isNotNull);
|
||||
expect(component?.text, equals('Failure!'));
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/components/backbox/displays/initials_submission_success_display.dart';
|
||||
|
||||
import '../../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('InitialsSubmissionSuccessDisplay', () {
|
||||
final flameTester = FlameTester(EmptyKeyboardPinballTestGame.new);
|
||||
|
||||
flameTester.test('renders correctly', (game) async {
|
||||
await game.ensureAdd(InitialsSubmissionSuccessDisplay());
|
||||
|
||||
final component = game.firstChild<TextComponent>();
|
||||
expect(component, isNotNull);
|
||||
expect(component?.text, equals('Success!'));
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:mocktail/mocktail.dart';
|
||||
import 'package:pinball/game/components/backbox/displays/loading_display.dart';
|
||||
import 'package:pinball/l10n/l10n.dart';
|
||||
|
||||
import '../../../../helpers/helpers.dart';
|
||||
|
||||
class _MockAppLocalizations extends Mock implements AppLocalizations {
|
||||
@override
|
||||
String get loading => 'Loading';
|
||||
}
|
||||
|
||||
void main() {
|
||||
group('LoadingDisplay', () {
|
||||
final flameTester = FlameTester(
|
||||
() => EmptyPinballTestGame(
|
||||
l10n: _MockAppLocalizations(),
|
||||
),
|
||||
);
|
||||
|
||||
flameTester.test('renders correctly', (game) async {
|
||||
await game.ensureAdd(LoadingDisplay());
|
||||
|
||||
final component = game.firstChild<TextComponent>();
|
||||
expect(component, isNotNull);
|
||||
expect(component?.text, equals('Loading'));
|
||||
});
|
||||
|
||||
flameTester.test('use ellipses as animation', (game) async {
|
||||
await game.ensureAdd(LoadingDisplay());
|
||||
|
||||
final component = game.firstChild<TextComponent>();
|
||||
expect(component?.text, equals('Loading'));
|
||||
|
||||
final timer = component?.firstChild<TimerComponent>();
|
||||
|
||||
timer?.update(1.1);
|
||||
expect(component?.text, equals('Loading.'));
|
||||
|
||||
timer?.update(1.1);
|
||||
expect(component?.text, equals('Loading..'));
|
||||
|
||||
timer?.update(1.1);
|
||||
expect(component?.text, equals('Loading...'));
|
||||
|
||||
timer?.update(1.1);
|
||||
expect(component?.text, equals('Loading'));
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
// ignore_for_file: prefer_const_constructors
|
||||
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
||||
import 'package:pinball/leaderboard/models/leader_board_entry.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart';
|
||||
|
||||
void main() {
|
||||
group('LeaderboardEntry', () {
|
||||
group('toEntry', () {
|
||||
test('returns the correct from a to entry data', () {
|
||||
expect(
|
||||
LeaderboardEntryData.empty.toEntry(1),
|
||||
LeaderboardEntry(
|
||||
rank: '1',
|
||||
playerInitials: '',
|
||||
score: 0,
|
||||
character: CharacterType.dash.toTheme.leaderboardIcon,
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
group('CharacterType', () {
|
||||
test('toTheme returns the correct theme', () {
|
||||
expect(CharacterType.dash.toTheme, equals(DashTheme()));
|
||||
expect(CharacterType.sparky.toTheme, equals(SparkyTheme()));
|
||||
expect(CharacterType.android.toTheme, equals(AndroidTheme()));
|
||||
expect(CharacterType.dino.toTheme, equals(DinoTheme()));
|
||||
});
|
||||
});
|
||||
|
||||
group('CharacterTheme', () {
|
||||
test('toType returns the correct type', () {
|
||||
expect(DashTheme().toType, equals(CharacterType.dash));
|
||||
expect(SparkyTheme().toType, equals(CharacterType.sparky));
|
||||
expect(AndroidTheme().toType, equals(CharacterType.android));
|
||||
expect(DinoTheme().toType, equals(CharacterType.dino));
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
Loading…
Reference in new issue