test: refactor test with cached images

pull/207/head
RuiAlonso 3 years ago
parent b0773aef84
commit cf601e2f32

@ -11,7 +11,19 @@ import '../../helpers/helpers.dart';
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final flameTester = FlameTester(TestGame.new); final assets = [
Assets.images.spaceship.ramp.railingBackground.keyName,
Assets.images.spaceship.ramp.main.keyName,
Assets.images.spaceship.ramp.boardOpening.keyName,
Assets.images.spaceship.ramp.railingForeground.keyName,
Assets.images.spaceship.ramp.arrow.inactive.keyName,
Assets.images.spaceship.ramp.arrow.active1.keyName,
Assets.images.spaceship.ramp.arrow.active2.keyName,
Assets.images.spaceship.ramp.arrow.active3.keyName,
Assets.images.spaceship.ramp.arrow.active4.keyName,
Assets.images.spaceship.ramp.arrow.active5.keyName,
];
final flameTester = FlameTester(() => TestGame(assets));
group('SpaceshipRamp', () { group('SpaceshipRamp', () {
flameTester.test( flameTester.test(
@ -30,9 +42,11 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'inactive sprite', 'inactive sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,
@ -52,10 +66,12 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active1 sprite', 'active1 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
spaceshipRamp.progress(); spaceshipRamp.progress();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,
@ -75,12 +91,14 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active2 sprite', 'active2 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
spaceshipRamp spaceshipRamp
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,
@ -100,6 +118,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active3 sprite', 'active3 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
@ -107,6 +126,7 @@ void main() {
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,
@ -126,6 +146,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active4 sprite', 'active4 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
@ -134,6 +155,7 @@ void main() {
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,
@ -153,6 +175,7 @@ void main() {
flameTester.testGameWidget( flameTester.testGameWidget(
'active5 sprite', 'active5 sprite',
setUp: (game, tester) async { setUp: (game, tester) async {
await game.images.loadAll(assets);
final spaceshipRamp = SpaceshipRamp(); final spaceshipRamp = SpaceshipRamp();
await game.addFromBlueprint(spaceshipRamp); await game.addFromBlueprint(spaceshipRamp);
await game.ready(); await game.ready();
@ -162,6 +185,7 @@ void main() {
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.spaceshipRampArrow.current, spaceshipRamp.spaceshipRampArrow.current,

Loading…
Cancel
Save