diff --git a/test/game/components/spaceship_drop_ramp_test.dart b/test/game/components/spaceship_drop_ramp_test.dart new file mode 100644 index 00000000..3802c55b --- /dev/null +++ b/test/game/components/spaceship_drop_ramp_test.dart @@ -0,0 +1,61 @@ +import 'package:flame_forge2d/flame_forge2d.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:mocktail/mocktail.dart'; +import 'package:pinball/game/game.dart'; + +import '../../helpers/helpers.dart'; + +void main() { + group('Spaceship', () { + late Filter filterData; + late Fixture fixture; + late Body body; + late PinballGame game; + late Ball ball; + late SpaceshipDropHole hole; + + setUp(() { + filterData = MockFilter(); + + fixture = MockFixture(); + when(() => fixture.filterData).thenReturn(filterData); + + body = MockBody(); + when(() => body.fixtures).thenReturn([fixture]); + + game = MockPinballGame(); + + ball = MockBall(); + when(() => ball.gameRef).thenReturn(game); + when(() => ball.body).thenReturn(body); + + hole = MockSpaceshipDropHole(); + }); + + group('SpaceshipDropHoleBallContactCallback', () { + test('changes the ball priority on contact', () { + when(() => hole.outsideLayer).thenReturn(Layer.board); + + SpaceshipDropHoleBallContactCallback().begin( + hole, + ball, + MockContact(), + ); + + verify(() => ball.priority = 1).called(1); + }); + + test('re order the game children', () { + when(() => hole.outsideLayer).thenReturn(Layer.board); + + SpaceshipDropHoleBallContactCallback().begin( + hole, + ball, + MockContact(), + ); + + verify(game.reorderChildren).called(1); + }); + }); + }); +} diff --git a/test/game/components/spaceship_test.dart b/test/game/components/spaceship_test.dart index c7eb24b2..420b0088 100644 --- a/test/game/components/spaceship_test.dart +++ b/test/game/components/spaceship_test.dart @@ -58,6 +58,8 @@ void main() { group('SpaceshipHoleBallContactCallback', () { test('changes the ball priority on contact', () { + when(() => hole.outsideLayer).thenReturn(Layer.board); + SpaceshipHoleBallContactCallback().begin( hole, ball, @@ -68,6 +70,8 @@ void main() { }); test('re order the game children', () { + when(() => hole.outsideLayer).thenReturn(Layer.board); + SpaceshipHoleBallContactCallback().begin( hole, ball, diff --git a/test/helpers/mocks.dart b/test/helpers/mocks.dart index e1bd8a0c..6c807966 100644 --- a/test/helpers/mocks.dart +++ b/test/helpers/mocks.dart @@ -59,3 +59,5 @@ class MockFixture extends Mock implements Fixture {} class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {} class MockSpaceshipHole extends Mock implements SpaceshipHole {} + +class MockSpaceshipDropHole extends Mock implements SpaceshipDropHole {}