mirror of https://github.com/flutter/pinball.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.3 KiB
114 lines
3.3 KiB
3 years ago
|
// ignore_for_file: cascade_invocations
|
||
|
|
||
|
import 'package:flame_test/flame_test.dart';
|
||
|
import 'package:flutter_test/flutter_test.dart';
|
||
3 years ago
|
import 'package:mocktail/mocktail.dart';
|
||
3 years ago
|
import 'package:pinball/game/game.dart';
|
||
3 years ago
|
import 'package:pinball_components/pinball_components.dart';
|
||
3 years ago
|
import 'package:pinball_flame/pinball_flame.dart';
|
||
3 years ago
|
|
||
|
import '../../helpers/helpers.dart';
|
||
|
|
||
|
void main() {
|
||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||
3 years ago
|
final assets = [
|
||
3 years ago
|
Assets.images.sparky.computer.top.keyName,
|
||
|
Assets.images.sparky.computer.base.keyName,
|
||
|
Assets.images.sparky.computer.glow.keyName,
|
||
3 years ago
|
Assets.images.sparky.animatronic.keyName,
|
||
3 years ago
|
Assets.images.sparky.bumper.a.lit.keyName,
|
||
|
Assets.images.sparky.bumper.a.dimmed.keyName,
|
||
|
Assets.images.sparky.bumper.b.lit.keyName,
|
||
|
Assets.images.sparky.bumper.b.dimmed.keyName,
|
||
|
Assets.images.sparky.bumper.c.lit.keyName,
|
||
|
Assets.images.sparky.bumper.c.dimmed.keyName,
|
||
3 years ago
|
];
|
||
3 years ago
|
|
||
|
final flameTester = FlameTester(
|
||
|
() => EmptyPinballTestGame(assets: assets),
|
||
|
);
|
||
3 years ago
|
|
||
3 years ago
|
group('SparkyScorch', () {
|
||
3 years ago
|
flameTester.test('loads correctly', (game) async {
|
||
3 years ago
|
await game.addFromBlueprint(SparkyScorch());
|
||
3 years ago
|
await game.ready();
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
|
group('loads', () {
|
||
3 years ago
|
flameTester.test(
|
||
|
'a SparkyComputer',
|
||
|
(game) async {
|
||
|
expect(
|
||
3 years ago
|
SparkyScorch().blueprints.whereType<SparkyComputer>().single,
|
||
3 years ago
|
isNotNull,
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
|
||
|
flameTester.test(
|
||
|
'a SparkyAnimatronic',
|
||
|
(game) async {
|
||
3 years ago
|
final sparkysScorch = SparkyScorch();
|
||
|
await game.addFromBlueprint(sparkysScorch);
|
||
3 years ago
|
await game.ready();
|
||
|
|
||
|
expect(
|
||
|
game.descendants().whereType<SparkyAnimatronic>().single,
|
||
|
isNotNull,
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
|
||
3 years ago
|
flameTester.test(
|
||
|
'three SparkyBumper',
|
||
|
(game) async {
|
||
3 years ago
|
final sparkysScorch = SparkyScorch();
|
||
|
await game.addFromBlueprint(sparkysScorch);
|
||
3 years ago
|
await game.ready();
|
||
3 years ago
|
|
||
|
expect(
|
||
3 years ago
|
game.descendants().whereType<SparkyBumper>().length,
|
||
3 years ago
|
equals(3),
|
||
|
);
|
||
|
},
|
||
|
);
|
||
|
});
|
||
3 years ago
|
});
|
||
3 years ago
|
|
||
3 years ago
|
group('SparkyComputerSensor', () {
|
||
3 years ago
|
flameTester.test('calls turboCharge', (game) async {
|
||
3 years ago
|
final sensor = SparkyComputerSensor();
|
||
3 years ago
|
final ball = MockControlledBall();
|
||
|
final controller = MockBallController();
|
||
|
when(() => ball.controller).thenReturn(controller);
|
||
|
when(controller.turboCharge).thenAnswer((_) async {});
|
||
|
|
||
3 years ago
|
await game.ensureAddAll([
|
||
|
sensor,
|
||
|
SparkyAnimatronic(),
|
||
|
]);
|
||
|
|
||
|
sensor.beginContact(ball, MockContact());
|
||
3 years ago
|
|
||
|
verify(() => ball.controller.turboCharge()).called(1);
|
||
|
});
|
||
|
|
||
|
flameTester.test('plays SparkyAnimatronic', (game) async {
|
||
3 years ago
|
final sensor = SparkyComputerSensor();
|
||
|
final sparkyAnimatronic = SparkyAnimatronic();
|
||
3 years ago
|
final ball = MockControlledBall();
|
||
|
final controller = MockBallController();
|
||
|
when(() => ball.controller).thenReturn(controller);
|
||
|
when(controller.turboCharge).thenAnswer((_) async {});
|
||
3 years ago
|
await game.ensureAddAll([
|
||
|
sensor,
|
||
|
sparkyAnimatronic,
|
||
|
]);
|
||
3 years ago
|
|
||
|
expect(sparkyAnimatronic.playing, isFalse);
|
||
3 years ago
|
sensor.beginContact(ball, MockContact());
|
||
3 years ago
|
expect(sparkyAnimatronic.playing, isTrue);
|
||
|
});
|
||
|
});
|
||
3 years ago
|
}
|