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.
106 lines
2.8 KiB
106 lines
2.8 KiB
// ignore_for_file: cascade_invocations
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
import 'package:flame_test/flame_test.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
void main() {
|
|
group('Baseboard', () {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
final assets = [
|
|
Assets.images.baseboard.left.keyName,
|
|
Assets.images.baseboard.right.keyName,
|
|
];
|
|
final flameTester = FlameTester(() => TestGame(assets));
|
|
|
|
flameTester.testGameWidget(
|
|
'renders correctly',
|
|
setUp: (game, tester) async {
|
|
await game.images.loadAll(assets);
|
|
final leftBaseboard = Baseboard(
|
|
side: BoardSide.left,
|
|
)..initialPosition = Vector2(-20, 0);
|
|
final rightBaseboard = Baseboard(
|
|
side: BoardSide.right,
|
|
)..initialPosition = Vector2(20, 0);
|
|
|
|
await game.ensureAddAll([leftBaseboard, rightBaseboard]);
|
|
game.camera.followVector2(Vector2.zero());
|
|
await tester.pump();
|
|
},
|
|
verify: (game, tester) async {
|
|
await expectLater(
|
|
find.byGame<TestGame>(),
|
|
matchesGoldenFile('golden/baseboard.png'),
|
|
);
|
|
},
|
|
);
|
|
|
|
flameTester.test(
|
|
'loads correctly',
|
|
(game) async {
|
|
await game.ready();
|
|
final leftBaseboard = Baseboard(
|
|
side: BoardSide.left,
|
|
);
|
|
final rightBaseboard = Baseboard(
|
|
side: BoardSide.right,
|
|
);
|
|
|
|
await game.ensureAddAll([leftBaseboard, rightBaseboard]);
|
|
|
|
expect(game.contains(leftBaseboard), isTrue);
|
|
expect(game.contains(rightBaseboard), isTrue);
|
|
},
|
|
);
|
|
|
|
group('body', () {
|
|
flameTester.test(
|
|
'is static',
|
|
(game) async {
|
|
final baseboard = Baseboard(
|
|
side: BoardSide.left,
|
|
);
|
|
|
|
await game.ensureAdd(baseboard);
|
|
|
|
expect(baseboard.body.bodyType, equals(BodyType.static));
|
|
},
|
|
);
|
|
|
|
flameTester.test(
|
|
'is at an angle',
|
|
(game) async {
|
|
final leftBaseboard = Baseboard(
|
|
side: BoardSide.left,
|
|
);
|
|
final rightBaseboard = Baseboard(
|
|
side: BoardSide.right,
|
|
);
|
|
await game.ensureAddAll([leftBaseboard, rightBaseboard]);
|
|
|
|
expect(leftBaseboard.body.angle, isPositive);
|
|
expect(rightBaseboard.body.angle, isNegative);
|
|
},
|
|
);
|
|
});
|
|
|
|
group('fixtures', () {
|
|
flameTester.test(
|
|
'has seven',
|
|
(game) async {
|
|
final baseboard = Baseboard(
|
|
side: BoardSide.left,
|
|
);
|
|
await game.ensureAdd(baseboard);
|
|
|
|
expect(baseboard.body.fixtures.length, equals(7));
|
|
},
|
|
);
|
|
});
|
|
});
|
|
}
|