|
|
@ -1,35 +1,72 @@
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:async';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:bloc_test/bloc_test.dart';
|
|
|
|
import 'package:bloc_test/bloc_test.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
|
|
|
|
import 'package:flame_bloc/flame_bloc.dart';
|
|
|
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../../helpers/helpers.dart';
|
|
|
|
class _TestGame extends Forge2DGame {
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
|
|
|
Future<void> onLoad() async {
|
|
|
|
|
|
|
|
images.prefix = '';
|
|
|
|
|
|
|
|
await images.loadAll([
|
|
|
|
|
|
|
|
Assets.images.signpost.inactive.keyName,
|
|
|
|
|
|
|
|
Assets.images.signpost.active1.keyName,
|
|
|
|
|
|
|
|
Assets.images.signpost.active2.keyName,
|
|
|
|
|
|
|
|
Assets.images.signpost.active3.keyName,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Future<void> pump(
|
|
|
|
|
|
|
|
Signpost child, {
|
|
|
|
|
|
|
|
SignpostCubit? signpostBloc,
|
|
|
|
|
|
|
|
DashBumpersCubit? dashBumpersBloc,
|
|
|
|
|
|
|
|
}) async {
|
|
|
|
|
|
|
|
await onLoad();
|
|
|
|
|
|
|
|
await ensureAdd(
|
|
|
|
|
|
|
|
FlameMultiBlocProvider(
|
|
|
|
|
|
|
|
providers: [
|
|
|
|
|
|
|
|
FlameBlocProvider<SignpostCubit, SignpostState>.value(
|
|
|
|
|
|
|
|
value: signpostBloc ?? SignpostCubit(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
FlameBlocProvider<DashBumpersCubit, DashBumpersState>.value(
|
|
|
|
|
|
|
|
value: dashBumpersBloc ?? DashBumpersCubit(),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
],
|
|
|
|
|
|
|
|
children: [child],
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
class _MockSignpostCubit extends Mock implements SignpostCubit {}
|
|
|
|
class _MockSignpostCubit extends Mock implements SignpostCubit {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockDashBumpersCubit extends Mock implements DashBumpersCubit {}
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final assets = [
|
|
|
|
|
|
|
|
Assets.images.signpost.inactive.keyName,
|
|
|
|
final flameTester = FlameTester(_TestGame.new);
|
|
|
|
Assets.images.signpost.active1.keyName,
|
|
|
|
|
|
|
|
Assets.images.signpost.active2.keyName,
|
|
|
|
|
|
|
|
Assets.images.signpost.active3.keyName,
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
final flameTester = FlameTester(() => TestGame(assets));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('Signpost', () {
|
|
|
|
group('Signpost', () {
|
|
|
|
const goldenPath = '../golden/signpost/';
|
|
|
|
const goldenPath = '../golden/signpost/';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('can be instantiated', () {
|
|
|
|
|
|
|
|
expect(Signpost(), isA<Signpost>());
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'loads correctly',
|
|
|
|
'can be added',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
final signpost = Signpost();
|
|
|
|
final signpost = Signpost();
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
await game.pump(signpost);
|
|
|
|
expect(game.contains(signpost), isTrue);
|
|
|
|
expect(game.descendants().contains(signpost), isTrue);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -37,13 +74,12 @@ void main() {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
'inactive sprite',
|
|
|
|
'inactive sprite',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
final signpost = Signpost();
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
await game.pump(signpost);
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
signpost.bloc.state,
|
|
|
|
signpost.firstChild<SpriteGroupComponent>()!.current,
|
|
|
|
equals(SignpostState.inactive),
|
|
|
|
equals(SignpostState.inactive),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -51,7 +87,7 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
verify: (game, tester) async {
|
|
|
|
verify: (game, tester) async {
|
|
|
|
await expectLater(
|
|
|
|
await expectLater(
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
find.byGame<_TestGame>(),
|
|
|
|
matchesGoldenFile('${goldenPath}inactive.png'),
|
|
|
|
matchesGoldenFile('${goldenPath}inactive.png'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -60,14 +96,14 @@ void main() {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
'active1 sprite',
|
|
|
|
'active1 sprite',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
final signpost = Signpost();
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
final bloc = SignpostCubit();
|
|
|
|
signpost.bloc.onProgressed();
|
|
|
|
await game.pump(signpost, signpostBloc: bloc);
|
|
|
|
|
|
|
|
bloc.onProgressed();
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
signpost.bloc.state,
|
|
|
|
signpost.firstChild<SpriteGroupComponent>()!.current,
|
|
|
|
equals(SignpostState.active1),
|
|
|
|
equals(SignpostState.active1),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -75,7 +111,7 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
verify: (game, tester) async {
|
|
|
|
verify: (game, tester) async {
|
|
|
|
await expectLater(
|
|
|
|
await expectLater(
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
find.byGame<_TestGame>(),
|
|
|
|
matchesGoldenFile('${goldenPath}active1.png'),
|
|
|
|
matchesGoldenFile('${goldenPath}active1.png'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -84,16 +120,16 @@ void main() {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
'active2 sprite',
|
|
|
|
'active2 sprite',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
final signpost = Signpost();
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
final bloc = SignpostCubit();
|
|
|
|
signpost.bloc
|
|
|
|
await game.pump(signpost, signpostBloc: bloc);
|
|
|
|
|
|
|
|
bloc
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed();
|
|
|
|
..onProgressed();
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
signpost.bloc.state,
|
|
|
|
signpost.firstChild<SpriteGroupComponent>()!.current,
|
|
|
|
equals(SignpostState.active2),
|
|
|
|
equals(SignpostState.active2),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -101,7 +137,7 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
verify: (game, tester) async {
|
|
|
|
verify: (game, tester) async {
|
|
|
|
await expectLater(
|
|
|
|
await expectLater(
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
find.byGame<_TestGame>(),
|
|
|
|
matchesGoldenFile('${goldenPath}active2.png'),
|
|
|
|
matchesGoldenFile('${goldenPath}active2.png'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -110,18 +146,17 @@ void main() {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
'active3 sprite',
|
|
|
|
'active3 sprite',
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
final signpost = Signpost();
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
final bloc = SignpostCubit();
|
|
|
|
|
|
|
|
await game.pump(signpost, signpostBloc: bloc);
|
|
|
|
signpost.bloc
|
|
|
|
bloc
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed()
|
|
|
|
..onProgressed();
|
|
|
|
..onProgressed();
|
|
|
|
await tester.pump();
|
|
|
|
await tester.pump();
|
|
|
|
|
|
|
|
|
|
|
|
expect(
|
|
|
|
expect(
|
|
|
|
signpost.bloc.state,
|
|
|
|
signpost.firstChild<SpriteGroupComponent>()!.current,
|
|
|
|
equals(SignpostState.active3),
|
|
|
|
equals(SignpostState.active3),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
@ -129,37 +164,83 @@ void main() {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
verify: (game, tester) async {
|
|
|
|
verify: (game, tester) async {
|
|
|
|
await expectLater(
|
|
|
|
await expectLater(
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
find.byGame<_TestGame>(),
|
|
|
|
matchesGoldenFile('${goldenPath}active3.png'),
|
|
|
|
matchesGoldenFile('${goldenPath}active3.png'),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test('adds new children', (game) async {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
final component = Component();
|
|
|
|
'listenWhen is true when all dash bumpers are activated',
|
|
|
|
final signpost = Signpost(
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
children: [component],
|
|
|
|
final activatedBumpersState = DashBumpersState(
|
|
|
|
|
|
|
|
bumperSpriteStates: {
|
|
|
|
|
|
|
|
for (var id in DashBumperId.values) id: DashBumperSpriteState.active
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
|
|
|
|
final dashBumpersBloc = _MockDashBumpersCubit();
|
|
|
|
|
|
|
|
whenListen(
|
|
|
|
|
|
|
|
dashBumpersBloc,
|
|
|
|
|
|
|
|
const Stream<DashBumpersState>.empty(),
|
|
|
|
|
|
|
|
initialState: DashBumpersState.initial(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await game.pump(signpost, dashBumpersBloc: dashBumpersBloc);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final signpostListener = game
|
|
|
|
|
|
|
|
.descendants()
|
|
|
|
|
|
|
|
.whereType<FlameBlocListener<DashBumpersCubit, DashBumpersState>>()
|
|
|
|
|
|
|
|
.single;
|
|
|
|
|
|
|
|
final listenWhen = signpostListener.listenWhen(
|
|
|
|
|
|
|
|
DashBumpersState.initial(),
|
|
|
|
|
|
|
|
activatedBumpersState,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
await game.ensureAdd(signpost);
|
|
|
|
|
|
|
|
expect(signpost.children, contains(component));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test('closes bloc when removed', (game) async {
|
|
|
|
expect(listenWhen, isTrue);
|
|
|
|
final bloc = _MockSignpostCubit();
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
|
|
|
'onNewState calls onProgressed and onReset',
|
|
|
|
|
|
|
|
(game) async {
|
|
|
|
|
|
|
|
final signpost = Signpost();
|
|
|
|
|
|
|
|
final signpostBloc = _MockSignpostCubit();
|
|
|
|
whenListen(
|
|
|
|
whenListen(
|
|
|
|
bloc,
|
|
|
|
signpostBloc,
|
|
|
|
const Stream<SignpostCubit>.empty(),
|
|
|
|
const Stream<SignpostState>.empty(),
|
|
|
|
initialState: SignpostState.inactive,
|
|
|
|
initialState: SignpostState.inactive,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
when(bloc.close).thenAnswer((_) async {});
|
|
|
|
final dashBumpersBloc = _MockDashBumpersCubit();
|
|
|
|
final component = Signpost.test(bloc: bloc);
|
|
|
|
whenListen(
|
|
|
|
|
|
|
|
dashBumpersBloc,
|
|
|
|
|
|
|
|
const Stream<DashBumpersState>.empty(),
|
|
|
|
|
|
|
|
initialState: DashBumpersState.initial(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await game.pump(
|
|
|
|
|
|
|
|
signpost,
|
|
|
|
|
|
|
|
signpostBloc: signpostBloc,
|
|
|
|
|
|
|
|
dashBumpersBloc: dashBumpersBloc,
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
await game.ensureAdd(component);
|
|
|
|
game
|
|
|
|
game.remove(component);
|
|
|
|
.descendants()
|
|
|
|
await game.ready();
|
|
|
|
.whereType<FlameBlocListener<DashBumpersCubit, DashBumpersState>>()
|
|
|
|
|
|
|
|
.single
|
|
|
|
|
|
|
|
.onNewState(DashBumpersState.initial());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(signpostBloc.onProgressed).called(1);
|
|
|
|
|
|
|
|
verify(dashBumpersBloc.onReset).called(1);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
verify(bloc.close).called(1);
|
|
|
|
flameTester.test('adds new children', (game) async {
|
|
|
|
|
|
|
|
final component = Component();
|
|
|
|
|
|
|
|
final signpost = Signpost(
|
|
|
|
|
|
|
|
children: [component],
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
await game.pump(signpost);
|
|
|
|
|
|
|
|
expect(signpost.children, contains(component));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|