mirror of https://github.com/flutter/pinball.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
132 lines
4.0 KiB
132 lines
4.0 KiB
// ignore_for_file: cascade_invocations
|
|
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame_test/flame_test.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() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
final assets = [
|
|
Assets.images.spaceship.ramp.boardOpening.keyName,
|
|
Assets.images.spaceship.ramp.railingForeground.keyName,
|
|
Assets.images.spaceship.ramp.railingBackground.keyName,
|
|
Assets.images.spaceship.ramp.main.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(() => EmptyPinballTestGame(assets: assets));
|
|
|
|
group('ControlledSpaceshipRamp', () {
|
|
flameTester.test(
|
|
'loads correctly',
|
|
(game) async {
|
|
final controlledSpaceshipRamp = AndroidRamp();
|
|
await game.ensureAdd(controlledSpaceshipRamp);
|
|
|
|
expect(game.contains(controlledSpaceshipRamp), isTrue);
|
|
},
|
|
);
|
|
|
|
group('loads', () {
|
|
flameTester.test(
|
|
'four SpriteComponent (two rails, main and opening)',
|
|
(game) async {
|
|
final controlledSpaceshipRamp = AndroidRamp();
|
|
await game.ensureAdd(controlledSpaceshipRamp);
|
|
|
|
expect(
|
|
controlledSpaceshipRamp
|
|
.descendants()
|
|
.whereType<SpriteComponent>()
|
|
.length,
|
|
equals(4),
|
|
);
|
|
},
|
|
);
|
|
|
|
flameTester.test(
|
|
'a SpaceshipRampArrowSpriteComponent',
|
|
(game) async {
|
|
final controlledSpaceshipRamp = AndroidRamp();
|
|
await game.ensureAdd(controlledSpaceshipRamp);
|
|
|
|
expect(
|
|
controlledSpaceshipRamp
|
|
.descendants()
|
|
.whereType<SpaceshipRampArrowSpriteComponent>()
|
|
.length,
|
|
equals(1),
|
|
);
|
|
},
|
|
);
|
|
|
|
flameTester.test(
|
|
'two SpaceshipRampSensor',
|
|
(game) async {
|
|
final controlledSpaceshipRamp = AndroidRamp();
|
|
await game.ensureAdd(controlledSpaceshipRamp);
|
|
|
|
expect(
|
|
controlledSpaceshipRamp
|
|
.descendants()
|
|
.whereType<AndroidRampSensor>()
|
|
.length,
|
|
equals(2),
|
|
);
|
|
},
|
|
);
|
|
});
|
|
});
|
|
|
|
group('SpaceshipRampController', () {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
final flameTester = FlameTester(EmptyPinballTestGame.new);
|
|
|
|
late AndroidRamp controlledSpaceshipRamp;
|
|
|
|
setUp(() {
|
|
controlledSpaceshipRamp = AndroidRamp();
|
|
});
|
|
|
|
test('can be instantiated', () {
|
|
expect(
|
|
SpaceshipRampController(controlledSpaceshipRamp),
|
|
isA<SpaceshipRampController>(),
|
|
);
|
|
});
|
|
|
|
group('shot', () {});
|
|
|
|
flameTester.testGameWidget(
|
|
'SpaceshipRampSensorBallContactCallback turbo charges the ball',
|
|
setUp: (game, tester) async {
|
|
final controlledSpaceshipRamp = MockControlledSpaceshipRamp();
|
|
final controller = MockSpaceshipRampController();
|
|
final contactCallback = SpaceshipRampSensorBallContactCallback();
|
|
final spaceshipRampSensor = MockSpaceshipRampSensor();
|
|
final ball = MockControlledBall();
|
|
|
|
when(() => spaceshipRampSensor.type)
|
|
.thenReturn(AndroidRampSensorType.door);
|
|
when(() => spaceshipRampSensor.parent)
|
|
.thenReturn(controlledSpaceshipRamp);
|
|
when(() => controlledSpaceshipRamp.controller).thenReturn(controller);
|
|
when(controller.shot).thenAnswer((_) async {});
|
|
|
|
contactCallback.begin(spaceshipRampSensor, ball, MockContact());
|
|
|
|
verify(controller.shot).called(1);
|
|
},
|
|
);
|
|
});
|
|
}
|