mirror of https://github.com/flutter/pinball.git
parent
a3e0e35b9c
commit
f32985d0bc
@ -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('PlayerInitialsSubmited', () {
|
||||
blocTest<BackboxBloc, BackboxState>(
|
||||
'adds [LoadingState, InitialsSuccessState] when submission works',
|
||||
setUp: () {
|
||||
leaderboardRepository = _MockLeaderboardRepository();
|
||||
when(
|
||||
() => leaderboardRepository.addLeaderboardEntry(
|
||||
LeaderboardEntryData(
|
||||
playerInitials: 'AAA',
|
||||
score: 10,
|
||||
character: CharacterType.dash,
|
||||
),
|
||||
),
|
||||
).thenAnswer((_) async {});
|
||||
},
|
||||
build: () => BackboxBloc(leaderboardRepository: leaderboardRepository),
|
||||
act: (bloc) => bloc.add(
|
||||
PlayerInitialsSubmited(
|
||||
score: 10,
|
||||
initials: 'AAA',
|
||||
character: DashTheme(),
|
||||
),
|
||||
),
|
||||
expect: () => [
|
||||
LoadingState(),
|
||||
InitialsSuccessState(),
|
||||
],
|
||||
);
|
||||
|
||||
blocTest<BackboxBloc, BackboxState>(
|
||||
'adds [LoadingState, InitialsSuccessState] when submission works',
|
||||
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(
|
||||
PlayerInitialsSubmited(
|
||||
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('PlayerInitialsSubmited', () {
|
||||
test('can be instantiated', () {
|
||||
expect(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNotNull,
|
||||
);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
equals(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmited(
|
||||
score: 1,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: SparkyTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'AAA',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
isNot(
|
||||
equals(
|
||||
PlayerInitialsSubmited(
|
||||
score: 0,
|
||||
initials: 'BBB',
|
||||
character: AndroidTheme(),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
@ -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('BackboxState', () {
|
||||
group('LoadingState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(LoadingState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(LoadingState(), equals(LoadingState()));
|
||||
});
|
||||
});
|
||||
|
||||
group('FailureState', () {
|
||||
test('can be instantiated', () {
|
||||
expect(FailureState(), isNotNull);
|
||||
});
|
||||
|
||||
test('supports value comparison', () {
|
||||
expect(FailureState(), equals(FailureState()));
|
||||
});
|
||||
});
|
||||
|
||||
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 InitialsFormState', () {
|
||||
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,50 @@
|
||||
// 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(EmptyKeyboardPinballTestGame.new);
|
||||
|
||||
flameTester.test('renders correctly', (game) async {
|
||||
await game.ensureAdd(LoadingDisplay(l10n: _MockAppLocalizations()));
|
||||
|
||||
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(l10n: _MockAppLocalizations()));
|
||||
|
||||
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'));
|
||||
});
|
||||
});
|
||||
}
|
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 1.4 MiB |
After Width: | Height: | Size: 16 KiB |
@ -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