test: refactored tests for spaceshipramp

pull/207/head
RuiAlonso 3 years ago
parent 890d295117
commit c4b4cc672d

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 188 KiB

@ -11,19 +11,7 @@ import '../../helpers/helpers.dart';
void main() { void main() {
TestWidgetsFlutterBinding.ensureInitialized(); TestWidgetsFlutterBinding.ensureInitialized();
final assets = [ final flameTester = FlameTester(TestGame.new);
Assets.images.spaceship.ramp.main.keyName,
Assets.images.spaceship.ramp.boardOpening.keyName,
Assets.images.spaceship.ramp.railingBackground.keyName,
Assets.images.spaceship.ramp.railingForeground.keyName,
Assets.images.spaceship.ramp.arrow.inactive.keyName,
Assets.images.spaceship.ramp.arrow.oneActive.keyName,
Assets.images.spaceship.ramp.arrow.twoActive.keyName,
Assets.images.spaceship.ramp.arrow.threeActive.keyName,
Assets.images.spaceship.ramp.arrow.fourActive.keyName,
Assets.images.spaceship.ramp.arrow.fiveActive.keyName,
];
final flameTester = FlameTester(() => TestGame(assets));
group('SpaceshipRamp', () { group('SpaceshipRamp', () {
flameTester.test( flameTester.test(
@ -37,21 +25,22 @@ void main() {
); );
group('renders correctly', () { group('renders correctly', () {
final centerForSpaceshipRamp = Vector2(-13, -55);
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(); await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.inactive, SpaceshipRampArrowSpriteState.inactive,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(
@ -64,20 +53,18 @@ 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();
await tester.pump();
spaceshipRamp.progress(); spaceshipRamp.progress();
await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.active1, SpaceshipRampArrowSpriteState.active1,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(
@ -90,22 +77,20 @@ 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();
await tester.pump();
spaceshipRamp spaceshipRamp
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.active2, SpaceshipRampArrowSpriteState.active2,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(
@ -118,23 +103,21 @@ 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();
await tester.pump();
spaceshipRamp spaceshipRamp
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.active3, SpaceshipRampArrowSpriteState.active3,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(
@ -147,24 +130,22 @@ 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();
await tester.pump();
spaceshipRamp spaceshipRamp
..progress() ..progress()
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.active4, SpaceshipRampArrowSpriteState.active4,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(
@ -177,25 +158,23 @@ 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();
await tester.pump();
spaceshipRamp spaceshipRamp
..progress() ..progress()
..progress() ..progress()
..progress() ..progress()
..progress() ..progress()
..progress(); ..progress();
await tester.pump();
expect( expect(
spaceshipRamp.firstChild<SpriteGroupComponent>()!.current, spaceshipRamp.spaceshipRampArrow.current,
SpaceshipRampArrowSpriteState.active5, SpaceshipRampArrowSpriteState.active5,
); );
game.camera.followVector2(Vector2(-13, -55)); game.camera.followVector2(centerForSpaceshipRamp);
}, },
verify: (game, tester) async { verify: (game, tester) async {
await expectLater( await expectLater(

Loading…
Cancel
Save