mirror of https://github.com/flutter/pinball.git
parent
06c737ca3c
commit
fefeb245d3
After Width: | Height: | Size: 49 KiB |
@ -0,0 +1,97 @@
|
||||
// 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('Slingshot', () {
|
||||
final flameTester = FlameTester(TestGame.new);
|
||||
const length = 2.0;
|
||||
const angle = 0.0;
|
||||
final spritePath = Assets.images.slingshot.leftUpper.keyName;
|
||||
|
||||
flameTester.testGameWidget(
|
||||
'renders correctly',
|
||||
setUp: (game, tester) async {
|
||||
await game.addFromBlueprint(Slingshots());
|
||||
await game.ready();
|
||||
game.camera.followVector2(Vector2.zero());
|
||||
},
|
||||
// TODO(allisonryan0002): enable test when workflows are fixed.
|
||||
// verify: (game, tester) async {
|
||||
// await expectLater(
|
||||
// find.byGame<Forge2DGame>(),
|
||||
// matchesGoldenFile('golden/slingshots.png'),
|
||||
// );
|
||||
// },
|
||||
);
|
||||
|
||||
flameTester.test(
|
||||
'loads correctly',
|
||||
(game) async {
|
||||
final slingshot = Slingshot(
|
||||
length: length,
|
||||
angle: angle,
|
||||
spritePath: spritePath,
|
||||
);
|
||||
await game.ensureAdd(slingshot);
|
||||
|
||||
expect(game.contains(slingshot), isTrue);
|
||||
},
|
||||
);
|
||||
|
||||
flameTester.test(
|
||||
'body is static',
|
||||
(game) async {
|
||||
final slingshot = Slingshot(
|
||||
length: length,
|
||||
angle: angle,
|
||||
spritePath: spritePath,
|
||||
);
|
||||
await game.ensureAdd(slingshot);
|
||||
|
||||
expect(slingshot.body.bodyType, equals(BodyType.static));
|
||||
},
|
||||
);
|
||||
|
||||
flameTester.test(
|
||||
'has restitution',
|
||||
(game) async {
|
||||
final slingshot = Slingshot(
|
||||
length: length,
|
||||
angle: angle,
|
||||
spritePath: spritePath,
|
||||
);
|
||||
await game.ensureAdd(slingshot);
|
||||
|
||||
final totalRestitution = slingshot.body.fixtures.fold<double>(
|
||||
0,
|
||||
(total, fixture) => total + fixture.restitution,
|
||||
);
|
||||
expect(totalRestitution, greaterThan(0));
|
||||
},
|
||||
);
|
||||
|
||||
flameTester.test(
|
||||
'has no friction',
|
||||
(game) async {
|
||||
final slingshot = Slingshot(
|
||||
length: length,
|
||||
angle: angle,
|
||||
spritePath: spritePath,
|
||||
);
|
||||
await game.ensureAdd(slingshot);
|
||||
|
||||
final totalFriction = slingshot.body.fixtures.fold<double>(
|
||||
0,
|
||||
(total, fixture) => total + fixture.friction,
|
||||
);
|
||||
expect(totalFriction, equals(0));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
Loading…
Reference in new issue