|
|
@ -1,18 +1,25 @@
|
|
|
|
|
|
|
|
// ignore_for_file: cascade_invocations
|
|
|
|
|
|
|
|
|
|
|
|
import 'dart:collection';
|
|
|
|
import 'dart:collection';
|
|
|
|
|
|
|
|
|
|
|
|
import 'package:bloc_test/bloc_test.dart';
|
|
|
|
import 'package:bloc_test/bloc_test.dart';
|
|
|
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
|
|
import 'package:flame/components.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flame_test/flame_test.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:mocktail/mocktail.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
import 'package:pinball/game/game.dart';
|
|
|
|
|
|
|
|
import 'package:pinball_audio/pinball_audio.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
import 'package:pinball_components/pinball_components.dart';
|
|
|
|
|
|
|
|
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
import '../../helpers/helpers.dart';
|
|
|
|
|
|
|
|
|
|
|
|
class _MockGameBloc extends Mock implements GameBloc {}
|
|
|
|
class _MockGameBloc extends Mock implements GameBloc {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockPinballPlayer extends Mock implements PinballPlayer {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _MockPinballGame extends Mock implements PinballGame {}
|
|
|
|
|
|
|
|
|
|
|
|
void main() {
|
|
|
|
void main() {
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
|
|
final flameTester = FlameTester(EmptyPinballTestGame.new);
|
|
|
|
final flameTester = FlameTester(EmptyPinballTestGame.new);
|
|
|
@ -20,31 +27,28 @@ void main() {
|
|
|
|
group('PlungerController', () {
|
|
|
|
group('PlungerController', () {
|
|
|
|
late GameBloc gameBloc;
|
|
|
|
late GameBloc gameBloc;
|
|
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
|
|
|
|
gameBloc = _MockGameBloc();
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
|
|
|
|
final flameBlocTester = FlameBlocTester<EmptyPinballTestGame, GameBloc>(
|
|
|
|
gameBuilder: EmptyPinballTestGame.new,
|
|
|
|
gameBuilder: EmptyPinballTestGame.new,
|
|
|
|
blocBuilder: () => gameBloc,
|
|
|
|
blocBuilder: () => gameBloc,
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
group('onKeyEvent', () {
|
|
|
|
|
|
|
|
final downKeys = UnmodifiableListView([
|
|
|
|
|
|
|
|
LogicalKeyboardKey.arrowDown,
|
|
|
|
|
|
|
|
LogicalKeyboardKey.space,
|
|
|
|
|
|
|
|
LogicalKeyboardKey.keyS,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
late Plunger plunger;
|
|
|
|
late Plunger plunger;
|
|
|
|
late PlungerController controller;
|
|
|
|
late PlungerController controller;
|
|
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
setUp(() {
|
|
|
|
plunger = Plunger(compressionDistance: 10);
|
|
|
|
gameBloc = _MockGameBloc();
|
|
|
|
|
|
|
|
plunger = ControlledPlunger(compressionDistance: 10);
|
|
|
|
controller = PlungerController(plunger);
|
|
|
|
controller = PlungerController(plunger);
|
|
|
|
plunger.add(controller);
|
|
|
|
plunger.add(controller);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('onKeyEvent', () {
|
|
|
|
|
|
|
|
final downKeys = UnmodifiableListView([
|
|
|
|
|
|
|
|
LogicalKeyboardKey.arrowDown,
|
|
|
|
|
|
|
|
LogicalKeyboardKey.space,
|
|
|
|
|
|
|
|
LogicalKeyboardKey.keyS,
|
|
|
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
|
|
testRawKeyDownEvents(downKeys, (event) {
|
|
|
|
testRawKeyDownEvents(downKeys, (event) {
|
|
|
|
flameTester.test(
|
|
|
|
flameTester.test(
|
|
|
|
'moves down '
|
|
|
|
'moves down '
|
|
|
@ -129,5 +133,50 @@ void main() {
|
|
|
|
);
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
flameTester.test(
|
|
|
|
|
|
|
|
'adds the PlungerNoisyBehavior plunger is released',
|
|
|
|
|
|
|
|
(game) async {
|
|
|
|
|
|
|
|
await game.ensureAdd(plunger);
|
|
|
|
|
|
|
|
plunger.body.setTransform(Vector2(0, 1), 0);
|
|
|
|
|
|
|
|
plunger.release();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await game.ready();
|
|
|
|
|
|
|
|
final count =
|
|
|
|
|
|
|
|
game.descendants().whereType<PlungerNoisyBehavior>().length;
|
|
|
|
|
|
|
|
expect(count, equals(1));
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
group('PlungerNoisyBehavior', () {
|
|
|
|
|
|
|
|
late PinballGame game;
|
|
|
|
|
|
|
|
late PinballPlayer player;
|
|
|
|
|
|
|
|
late PlungerNoisyBehavior behavior;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setUp(() {
|
|
|
|
|
|
|
|
game = _MockPinballGame();
|
|
|
|
|
|
|
|
player = _MockPinballPlayer();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
when(() => game.player).thenReturn(player);
|
|
|
|
|
|
|
|
behavior = PlungerNoisyBehavior();
|
|
|
|
|
|
|
|
behavior.mockGameRef(game);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('plays the correct sound on load', () async {
|
|
|
|
|
|
|
|
await behavior.onLoad();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
verify(() => player.play(PinballAudio.launcher)).called(1);
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
test('is removed on the first update', () {
|
|
|
|
|
|
|
|
final parent = Component();
|
|
|
|
|
|
|
|
parent.add(behavior);
|
|
|
|
|
|
|
|
parent.update(0); // Run a tick to ensure it is added
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
behavior.update(0); // Run its own update where the removal happens
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(behavior.shouldRemove, isTrue);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|