mirror of https://github.com/flutter/pinball.git
refactor: move spaceship exit rail (#130)
* refactor: moved SpaceshipExitRail to pinball components * test: refactor tests and coverage * chore: ignore cascade invocations on tests * refactor: renamed SpaceshipExitRail to SpaceshipRailpull/138/head
parent
61c347c72d
commit
b40dccb6bf
Before Width: | Height: | Size: 63 KiB After Width: | Height: | Size: 63 KiB |
@ -0,0 +1,82 @@
|
|||||||
|
// 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:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group('SpaceshipRail', () {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final spaceshipRail = SpaceshipRail();
|
||||||
|
await game.addFromBlueprint(spaceshipRail);
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
for (final element in spaceshipRail.components) {
|
||||||
|
expect(game.contains(element), isTrue);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO(alestiago): Make ContactCallback private and use `beginContact`
|
||||||
|
// instead.
|
||||||
|
group('SpaceshipRailExitBallContactCallback', () {
|
||||||
|
late Forge2DGame game;
|
||||||
|
late SpaceshipRailExit railExit;
|
||||||
|
late Ball ball;
|
||||||
|
late Body body;
|
||||||
|
late Fixture fixture;
|
||||||
|
late Filter filterData;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
game = MockGame();
|
||||||
|
|
||||||
|
railExit = MockSpaceshipRailExit();
|
||||||
|
|
||||||
|
ball = MockBall();
|
||||||
|
body = MockBody();
|
||||||
|
when(() => ball.gameRef).thenReturn(game);
|
||||||
|
when(() => ball.body).thenReturn(body);
|
||||||
|
|
||||||
|
fixture = MockFixture();
|
||||||
|
filterData = MockFilter();
|
||||||
|
when(() => body.fixtures).thenReturn([fixture]);
|
||||||
|
when(() => fixture.filterData).thenReturn(filterData);
|
||||||
|
});
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
when(() => ball.priority).thenReturn(1);
|
||||||
|
when(() => railExit.outsideLayer).thenReturn(Layer.board);
|
||||||
|
when(() => railExit.outsidePriority).thenReturn(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changes the ball priority on contact', () {
|
||||||
|
SpaceshipRailExitBallContactCallback().begin(
|
||||||
|
railExit,
|
||||||
|
ball,
|
||||||
|
MockContact(),
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(() => ball.sendTo(railExit.outsidePriority)).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('changes the ball layer on contact', () {
|
||||||
|
SpaceshipRailExitBallContactCallback().begin(
|
||||||
|
railExit,
|
||||||
|
ball,
|
||||||
|
MockContact(),
|
||||||
|
);
|
||||||
|
|
||||||
|
verify(() => ball.layer = railExit.outsideLayer).called(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,64 +0,0 @@
|
|||||||
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 'package:pinball_components/pinball_components.dart';
|
|
||||||
|
|
||||||
import '../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
group('SpaceshipExitRail', () {
|
|
||||||
late PinballGame game;
|
|
||||||
late SpaceshipExitRailEnd exitRailEnd;
|
|
||||||
late Ball ball;
|
|
||||||
late Body body;
|
|
||||||
late Fixture fixture;
|
|
||||||
late Filter filterData;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
game = MockPinballGame();
|
|
||||||
|
|
||||||
exitRailEnd = MockSpaceshipExitRailEnd();
|
|
||||||
|
|
||||||
ball = MockBall();
|
|
||||||
body = MockBody();
|
|
||||||
when(() => ball.gameRef).thenReturn(game);
|
|
||||||
when(() => ball.body).thenReturn(body);
|
|
||||||
|
|
||||||
fixture = MockFixture();
|
|
||||||
filterData = MockFilter();
|
|
||||||
when(() => body.fixtures).thenReturn([fixture]);
|
|
||||||
when(() => fixture.filterData).thenReturn(filterData);
|
|
||||||
});
|
|
||||||
|
|
||||||
// TODO(alestiago): Make ContactCallback private and use `beginContact`
|
|
||||||
// instead.
|
|
||||||
group('SpaceshipExitHoleBallContactCallback', () {
|
|
||||||
setUp(() {
|
|
||||||
when(() => ball.priority).thenReturn(1);
|
|
||||||
when(() => exitRailEnd.outsideLayer).thenReturn(Layer.board);
|
|
||||||
when(() => exitRailEnd.outsidePriority).thenReturn(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('changes the ball priority on contact', () {
|
|
||||||
SpaceshipExitRailEndBallContactCallback().begin(
|
|
||||||
exitRailEnd,
|
|
||||||
ball,
|
|
||||||
MockContact(),
|
|
||||||
);
|
|
||||||
|
|
||||||
verify(() => ball.sendTo(exitRailEnd.outsidePriority)).called(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('changes the ball layer on contact', () {
|
|
||||||
SpaceshipExitRailEndBallContactCallback().begin(
|
|
||||||
exitRailEnd,
|
|
||||||
ball,
|
|
||||||
MockContact(),
|
|
||||||
);
|
|
||||||
|
|
||||||
verify(() => ball.layer = exitRailEnd.outsideLayer).called(1);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in new issue