|
|
@ -1,34 +1,31 @@
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame/components.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:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// TODO(alisonryan): Refactor loading assets in test with
|
|
|
|
|
|
|
|
// https://github.com/VGVentures/pinball/pull/204
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final flameTester = FlameTester(TestGame.new);
|
|
|
|
final flameTester = FlameTester(TestGame.new);
|
|
|
|
|
|
|
|
|
|
|
|
group('FlutterSignPost', () {
|
|
|
|
group('FlutterSignPost', () {
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
final assets = [
|
|
|
|
'renders correctly',
|
|
|
|
Assets.images.signPost.inactive.keyName,
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
Assets.images.signPost.active1.keyName,
|
|
|
|
await game.ensureAdd(FlutterSignPost());
|
|
|
|
Assets.images.signPost.active2.keyName,
|
|
|
|
game.camera.followVector2(Vector2.zero());
|
|
|
|
Assets.images.signPost.active3.keyName,
|
|
|
|
},
|
|
|
|
];
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
|
|
|
|
matchesGoldenFile('golden/flutter-sign-post.png'),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'loads correctly',
|
|
|
|
'loads correctly',
|
|
|
|
(game) async {
|
|
|
|
(game) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
final flutterSignPost = FlutterSignPost();
|
|
|
|
final flutterSignPost = FlutterSignPost();
|
|
|
|
await game.ready();
|
|
|
|
await game.ready();
|
|
|
|
await game.ensureAdd(flutterSignPost);
|
|
|
|
await game.ensureAdd(flutterSignPost);
|
|
|
@ -36,5 +33,97 @@ void main() {
|
|
|
|
expect(game.contains(flutterSignPost), isTrue);
|
|
|
|
expect(game.contains(flutterSignPost), isTrue);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('renders correctly', () {
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
|
|
|
'inactive sprite',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
await game.ensureAdd(FlutterSignPost());
|
|
|
|
|
|
|
|
game.camera.followVector2(Vector2.zero());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
|
|
|
|
matchesGoldenFile('golden/flutter-sign-post__inactive.png'),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
|
|
|
'active1 sprite',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
await game.ensureAdd(FlutterSignPost()..progress());
|
|
|
|
|
|
|
|
game.camera.followVector2(Vector2.zero());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
|
|
|
|
matchesGoldenFile('golden/flutter-sign-post__active1.png'),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
|
|
|
'active2 sprite',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
await game.ensureAdd(
|
|
|
|
|
|
|
|
FlutterSignPost()
|
|
|
|
|
|
|
|
..progress()
|
|
|
|
|
|
|
|
..progress(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
game.camera.followVector2(Vector2.zero());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
|
|
|
|
matchesGoldenFile('golden/flutter-sign-post__active2.png'),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.testGameWidget(
|
|
|
|
|
|
|
|
'active3 sprite',
|
|
|
|
|
|
|
|
setUp: (game, tester) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
await game.ensureAdd(
|
|
|
|
|
|
|
|
FlutterSignPost()
|
|
|
|
|
|
|
|
..progress()
|
|
|
|
|
|
|
|
..progress()
|
|
|
|
|
|
|
|
..progress(),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
game.camera.followVector2(Vector2.zero());
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
verify: (game, tester) async {
|
|
|
|
|
|
|
|
await expectLater(
|
|
|
|
|
|
|
|
find.byGame<TestGame>(),
|
|
|
|
|
|
|
|
matchesGoldenFile('golden/flutter-sign-post__active3.png'),
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
|
|
|
'progress changes correctly between four sprites',
|
|
|
|
|
|
|
|
(game) async {
|
|
|
|
|
|
|
|
await game.images.loadAll(assets);
|
|
|
|
|
|
|
|
final flutterSignPost = FlutterSignPost();
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
await game.ensureAdd(flutterSignPost);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final spriteComponent =
|
|
|
|
|
|
|
|
flutterSignPost.firstChild<SpriteGroupComponent>()!;
|
|
|
|
|
|
|
|
final sprites = <Sprite>{};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (var i = 0; i < 4; i++) {
|
|
|
|
|
|
|
|
sprites.add(spriteComponent.sprite!);
|
|
|
|
|
|
|
|
flutterSignPost.progress();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(sprites.length, equals(4));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|