Before Width: | Height: | Size: 8.1 KiB |
Before Width: | Height: | Size: 9.5 KiB |
Before Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 9.8 KiB |
Before Width: | Height: | Size: 6.3 KiB |
Before Width: | Height: | Size: 7.7 KiB |
@ -1,17 +1,13 @@
|
|||||||
export 'ball.dart';
|
export 'ball.dart';
|
||||||
export 'baseboard.dart';
|
export 'baseboard.dart';
|
||||||
export 'board.dart';
|
export 'board.dart';
|
||||||
export 'board_side.dart';
|
|
||||||
export 'bonus_word.dart';
|
export 'bonus_word.dart';
|
||||||
export 'chrome_dino.dart';
|
export 'chrome_dino.dart';
|
||||||
export 'flipper.dart';
|
export 'flipper_controller.dart';
|
||||||
export 'flutter_forest.dart';
|
export 'flutter_forest.dart';
|
||||||
export 'jetpack_ramp.dart';
|
export 'jetpack_ramp.dart';
|
||||||
export 'joint_anchor.dart';
|
|
||||||
export 'kicker.dart';
|
export 'kicker.dart';
|
||||||
export 'launcher_ramp.dart';
|
export 'launcher_ramp.dart';
|
||||||
export 'plunger.dart';
|
export 'plunger.dart';
|
||||||
export 'ramp_opening.dart';
|
|
||||||
export 'score_points.dart';
|
export 'score_points.dart';
|
||||||
export 'spaceship.dart';
|
|
||||||
export 'wall.dart';
|
export 'wall.dart';
|
||||||
|
@ -0,0 +1,52 @@
|
|||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
/// {@template flipper_controller}
|
||||||
|
/// A [Component] that controls the [Flipper]s movement.
|
||||||
|
/// {@endtemplate}
|
||||||
|
class FlipperController extends Component with KeyboardHandler {
|
||||||
|
/// {@macro flipper_controller}
|
||||||
|
FlipperController(this.flipper) : _keys = flipper.side.flipperKeys;
|
||||||
|
|
||||||
|
/// The [Flipper] this controller is controlling.
|
||||||
|
final Flipper flipper;
|
||||||
|
|
||||||
|
/// The [LogicalKeyboardKey]s that will control the [Flipper].
|
||||||
|
///
|
||||||
|
/// [onKeyEvent] method listens to when one of these keys is pressed.
|
||||||
|
final List<LogicalKeyboardKey> _keys;
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool onKeyEvent(
|
||||||
|
RawKeyEvent event,
|
||||||
|
Set<LogicalKeyboardKey> keysPressed,
|
||||||
|
) {
|
||||||
|
if (!_keys.contains(event.logicalKey)) return true;
|
||||||
|
|
||||||
|
if (event is RawKeyDownEvent) {
|
||||||
|
flipper.moveUp();
|
||||||
|
} else if (event is RawKeyUpEvent) {
|
||||||
|
flipper.moveDown();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension on BoardSide {
|
||||||
|
List<LogicalKeyboardKey> get flipperKeys {
|
||||||
|
switch (this) {
|
||||||
|
case BoardSide.left:
|
||||||
|
return [
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
];
|
||||||
|
case BoardSide.right:
|
||||||
|
return [
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
After Width: | Height: | Size: 3.7 KiB |
After Width: | Height: | Size: 3.6 KiB |
After Width: | Height: | Size: 231 KiB |
After Width: | Height: | Size: 38 KiB |
@ -1,4 +1,8 @@
|
|||||||
import 'package:pinball/game/game.dart';
|
// ignore_for_file: comment_references
|
||||||
|
// TODO(alestiago): Revisit ignore lint rule once Kicker is moved to this
|
||||||
|
// package.
|
||||||
|
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
/// Indicates a side of the board.
|
/// Indicates a side of the board.
|
||||||
///
|
///
|
@ -1,5 +1,10 @@
|
|||||||
export 'ball.dart';
|
export 'ball.dart';
|
||||||
|
export 'board_side.dart';
|
||||||
export 'fire_effect.dart';
|
export 'fire_effect.dart';
|
||||||
|
export 'flipper.dart';
|
||||||
export 'initial_position.dart';
|
export 'initial_position.dart';
|
||||||
|
export 'joint_anchor.dart';
|
||||||
export 'layer.dart';
|
export 'layer.dart';
|
||||||
|
export 'ramp_opening.dart';
|
||||||
export 'shapes/shapes.dart';
|
export 'shapes/shapes.dart';
|
||||||
|
export 'spaceship.dart';
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
// ignore_for_file: avoid_renaming_method_parameters
|
// ignore_for_file: avoid_renaming_method_parameters
|
||||||
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
/// {@template ramp_orientation}
|
/// {@template ramp_orientation}
|
||||||
/// Determines if a ramp is facing [up] or [down] on the [Board].
|
/// Determines if a ramp is facing [up] or [down] on the Board.
|
||||||
/// {@endtemplate}
|
/// {@endtemplate}
|
||||||
enum RampOrientation {
|
enum RampOrientation {
|
||||||
/// Facing up on the [Board].
|
/// Facing up on the Board.
|
||||||
up,
|
up,
|
||||||
|
|
||||||
/// Facing down on the [Board].
|
/// Facing down on the Board.
|
||||||
down,
|
down,
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1 @@
|
|||||||
|
export 'blueprint.dart';
|
@ -1 +1,2 @@
|
|||||||
export 'components/components.dart';
|
export 'components/components.dart';
|
||||||
|
export 'flame/flame.dart';
|
||||||
|
@ -0,0 +1,26 @@
|
|||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
|
||||||
|
class BasicFlipperGame extends BasicGame {
|
||||||
|
static const info = '''
|
||||||
|
Basic example of how a Flipper works.
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||||
|
|
||||||
|
final leftFlipper = Flipper(side: BoardSide.left)
|
||||||
|
..initialPosition = center - Vector2(Flipper.size.x, 0);
|
||||||
|
final rightFlipper = Flipper(side: BoardSide.right)
|
||||||
|
..initialPosition = center + Vector2(Flipper.size.x, 0);
|
||||||
|
|
||||||
|
await addAll([
|
||||||
|
leftFlipper,
|
||||||
|
rightFlipper,
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/flipper/basic.dart';
|
||||||
|
import 'package:sandbox/stories/flipper/tracing.dart';
|
||||||
|
|
||||||
|
void addFlipperStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('Flipper')
|
||||||
|
..add(
|
||||||
|
'Basic',
|
||||||
|
(context) => GameWidget(
|
||||||
|
game: BasicFlipperGame(),
|
||||||
|
),
|
||||||
|
codeLink: buildSourceLink('flipper/basic.dart'),
|
||||||
|
info: BasicFlipperGame.info,
|
||||||
|
)
|
||||||
|
..add(
|
||||||
|
'Tracing',
|
||||||
|
(context) => GameWidget(
|
||||||
|
game: FlipperTracingGame(),
|
||||||
|
),
|
||||||
|
codeLink: buildSourceLink('flipper/tracing.dart'),
|
||||||
|
info: FlipperTracingGame.info,
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame/components.dart';
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
|
||||||
|
class FlipperTracingGame extends BasicGame {
|
||||||
|
static const info = '''
|
||||||
|
Basic example of how the Flipper body overlays the sprite.
|
||||||
|
''';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
final center = screenToWorld(camera.viewport.canvasSize! / 2);
|
||||||
|
|
||||||
|
final leftFlipper = Flipper(side: BoardSide.left)
|
||||||
|
..initialPosition = center - Vector2(Flipper.size.x, 0);
|
||||||
|
final rightFlipper = Flipper(side: BoardSide.right)
|
||||||
|
..initialPosition = center + Vector2(Flipper.size.x, 0);
|
||||||
|
|
||||||
|
await addAll([
|
||||||
|
leftFlipper,
|
||||||
|
rightFlipper,
|
||||||
|
]);
|
||||||
|
leftFlipper.trace();
|
||||||
|
rightFlipper.trace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension on BodyComponent {
|
||||||
|
void trace({Color color = Colors.red}) {
|
||||||
|
paint = Paint()..color = color;
|
||||||
|
renderBody = true;
|
||||||
|
body.joints.whereType<RevoluteJoint>().forEach(
|
||||||
|
(joint) => joint.setLimits(0, 0),
|
||||||
|
);
|
||||||
|
body.setType(BodyType.static);
|
||||||
|
|
||||||
|
unawaited(
|
||||||
|
mounted.whenComplete(() {
|
||||||
|
final sprite = children.whereType<SpriteComponent>().first;
|
||||||
|
sprite.paint.color = sprite.paint.color.withOpacity(0.5);
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:flame/input.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
|
||||||
|
class BasicSpaceship extends BasicGame with TapDetector {
|
||||||
|
static String info = 'Renders a spaceship and allows balls to be '
|
||||||
|
'spawned upon click to test their interactions';
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onLoad() async {
|
||||||
|
await super.onLoad();
|
||||||
|
|
||||||
|
camera.followVector2(Vector2.zero());
|
||||||
|
|
||||||
|
unawaited(
|
||||||
|
addFromBlueprint(Spaceship(position: Vector2.zero())),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onTapUp(TapUpInfo info) {
|
||||||
|
add(
|
||||||
|
Ball(baseColor: Colors.blue)
|
||||||
|
..initialPosition = info.eventPosition.game
|
||||||
|
..layer = Layer.jetpack,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
import 'package:dashbook/dashbook.dart';
|
||||||
|
import 'package:flame/game.dart';
|
||||||
|
import 'package:sandbox/common/common.dart';
|
||||||
|
import 'package:sandbox/stories/spaceship/basic.dart';
|
||||||
|
|
||||||
|
void addSpaceshipStories(Dashbook dashbook) {
|
||||||
|
dashbook.storiesOf('Spaceship').add(
|
||||||
|
'Basic',
|
||||||
|
(context) => GameWidget(game: BasicSpaceship()),
|
||||||
|
codeLink: buildSourceLink('spaceship/basic.dart'),
|
||||||
|
info: BasicSpaceship.info,
|
||||||
|
);
|
||||||
|
}
|
@ -1,2 +1,3 @@
|
|||||||
export 'ball/ball.dart';
|
export 'ball/ball.dart';
|
||||||
|
export 'flipper/flipper.dart';
|
||||||
export 'layer/layer.dart';
|
export 'layer/layer.dart';
|
||||||
|
@ -1,5 +1,26 @@
|
|||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
import 'package:mocktail/mocktail.dart';
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
class MockCanvas extends Mock implements Canvas {}
|
class MockCanvas extends Mock implements Canvas {}
|
||||||
|
|
||||||
|
class MockFilter extends Mock implements Filter {}
|
||||||
|
|
||||||
|
class MockFixture extends Mock implements Fixture {}
|
||||||
|
|
||||||
|
class MockBody extends Mock implements Body {}
|
||||||
|
|
||||||
|
class MockBall extends Mock implements Ball {}
|
||||||
|
|
||||||
|
class MockGame extends Mock implements Forge2DGame {}
|
||||||
|
|
||||||
|
class MockSpaceshipEntrance extends Mock implements SpaceshipEntrance {}
|
||||||
|
|
||||||
|
class MockSpaceshipHole extends Mock implements SpaceshipHole {}
|
||||||
|
|
||||||
|
class MockContact extends Mock implements Contact {}
|
||||||
|
|
||||||
|
class MockContactCallback extends Mock
|
||||||
|
implements ContactCallback<Object, Object> {}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group(
|
group(
|
@ -0,0 +1,133 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:flame_forge2d/flame_forge2d.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group('Flipper', () {
|
||||||
|
// TODO(alestiago): Add golden tests.
|
||||||
|
// TODO(alestiago): Consider testing always both left and right Flipper.
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'loads correctly',
|
||||||
|
(game) async {
|
||||||
|
final leftFlipper = Flipper(side: BoardSide.left);
|
||||||
|
final rightFlipper = Flipper(side: BoardSide.right);
|
||||||
|
await game.ready();
|
||||||
|
await game.ensureAddAll([leftFlipper, rightFlipper]);
|
||||||
|
|
||||||
|
expect(game.contains(leftFlipper), isTrue);
|
||||||
|
expect(game.contains(rightFlipper), isTrue);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
group('constructor', () {
|
||||||
|
test('sets BoardSide', () {
|
||||||
|
final leftFlipper = Flipper(side: BoardSide.left);
|
||||||
|
expect(leftFlipper.side, equals(leftFlipper.side));
|
||||||
|
|
||||||
|
final rightFlipper = Flipper(side: BoardSide.right);
|
||||||
|
expect(rightFlipper.side, equals(rightFlipper.side));
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('body', () {
|
||||||
|
flameTester.test(
|
||||||
|
'is dynamic',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
expect(flipper.body.bodyType, equals(BodyType.dynamic));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'ignores gravity',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
|
||||||
|
expect(flipper.body.gravityScale, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'has greater mass than Ball',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
final ball = Ball(baseColor: Colors.white);
|
||||||
|
|
||||||
|
await game.ready();
|
||||||
|
await game.ensureAddAll([flipper, ball]);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
flipper.body.getMassData().mass,
|
||||||
|
greaterThan(ball.body.getMassData().mass),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group('fixtures', () {
|
||||||
|
flameTester.test(
|
||||||
|
'has three',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
|
||||||
|
expect(flipper.body.fixtures.length, equals(3));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'has density',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
|
||||||
|
final fixtures = flipper.body.fixtures;
|
||||||
|
final density = fixtures.fold<double>(
|
||||||
|
0,
|
||||||
|
(sum, fixture) => sum + fixture.density,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(density, greaterThan(0));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moveDown applies downward velocity',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity, equals(Vector2.zero()));
|
||||||
|
flipper.moveDown();
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, lessThan(0));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'moveUp applies upward velocity',
|
||||||
|
(game) async {
|
||||||
|
final flipper = Flipper(side: BoardSide.left);
|
||||||
|
await game.ensureAdd(flipper);
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity, equals(Vector2.zero()));
|
||||||
|
flipper.moveUp();
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, greaterThan(0));
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
After Width: | Height: | Size: 79 KiB |
@ -0,0 +1,169 @@
|
|||||||
|
import 'dart:collection';
|
||||||
|
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball/game/game.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
import '../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(PinballGameTest.create);
|
||||||
|
|
||||||
|
group('FlipperController', () {
|
||||||
|
group('onKeyEvent', () {
|
||||||
|
final leftKeys = UnmodifiableListView([
|
||||||
|
LogicalKeyboardKey.arrowLeft,
|
||||||
|
LogicalKeyboardKey.keyA,
|
||||||
|
]);
|
||||||
|
final rightKeys = UnmodifiableListView([
|
||||||
|
LogicalKeyboardKey.arrowRight,
|
||||||
|
LogicalKeyboardKey.keyD,
|
||||||
|
]);
|
||||||
|
|
||||||
|
group('and Flipper is left', () {
|
||||||
|
late Flipper flipper;
|
||||||
|
late FlipperController controller;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
flipper = Flipper(side: BoardSide.left);
|
||||||
|
controller = FlipperController(flipper);
|
||||||
|
flipper.add(controller);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyDownEvents(leftKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards '
|
||||||
|
'when ${event.logicalKey.keyLabel} is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyUpEvents(leftKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards '
|
||||||
|
'when ${event.logicalKey.keyLabel} is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyUpEvents(rightKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'does nothing '
|
||||||
|
'when ${event.logicalKey.keyLabel} is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyDownEvents(rightKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'does nothing '
|
||||||
|
'when ${event.logicalKey.keyLabel} is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group('and Flipper is right', () {
|
||||||
|
late Flipper flipper;
|
||||||
|
late FlipperController controller;
|
||||||
|
|
||||||
|
setUp(() {
|
||||||
|
flipper = Flipper(side: BoardSide.right);
|
||||||
|
controller = FlipperController(flipper);
|
||||||
|
flipper.add(controller);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyDownEvents(rightKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'moves upwards '
|
||||||
|
'when ${event.logicalKey.keyLabel} is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isPositive);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyUpEvents(rightKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'moves downwards '
|
||||||
|
'when ${event.logicalKey.keyLabel} is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isNegative);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyUpEvents(leftKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'does nothing '
|
||||||
|
'when ${event.logicalKey.keyLabel} is released',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testRawKeyDownEvents(leftKeys, (event) {
|
||||||
|
flameTester.test(
|
||||||
|
'does nothing '
|
||||||
|
'when ${event.logicalKey.keyLabel} is pressed',
|
||||||
|
(game) async {
|
||||||
|
await game.ready();
|
||||||
|
await game.add(flipper);
|
||||||
|
controller.onKeyEvent(event, {});
|
||||||
|
|
||||||
|
expect(flipper.body.linearVelocity.y, isZero);
|
||||||
|
expect(flipper.body.linearVelocity.x, isZero);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,275 +0,0 @@
|
|||||||
// ignore_for_file: cascade_invocations
|
|
||||||
|
|
||||||
import 'dart:collection';
|
|
||||||
|
|
||||||
import 'package:flame_forge2d/flame_forge2d.dart';
|
|
||||||
import 'package:flame_test/flame_test.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
import 'package:pinball/game/game.dart';
|
|
||||||
import 'package:pinball_components/pinball_components.dart';
|
|
||||||
|
|
||||||
import '../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
final flameTester = FlameTester(PinballGameTest.create);
|
|
||||||
|
|
||||||
group(
|
|
||||||
'Flipper',
|
|
||||||
() {
|
|
||||||
// TODO(alestiago): Add golden tests.
|
|
||||||
flameTester.test(
|
|
||||||
'loads correctly',
|
|
||||||
(game) async {
|
|
||||||
final leftFlipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
final rightFlipper = Flipper(
|
|
||||||
side: BoardSide.right,
|
|
||||||
);
|
|
||||||
await game.ready();
|
|
||||||
await game.ensureAddAll([leftFlipper, rightFlipper]);
|
|
||||||
|
|
||||||
expect(game.contains(leftFlipper), isTrue);
|
|
||||||
expect(game.contains(rightFlipper), isTrue);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
group('constructor', () {
|
|
||||||
test('sets BoardSide', () {
|
|
||||||
final leftFlipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(leftFlipper.side, equals(leftFlipper.side));
|
|
||||||
|
|
||||||
final rightFlipper = Flipper(
|
|
||||||
side: BoardSide.right,
|
|
||||||
);
|
|
||||||
expect(rightFlipper.side, equals(rightFlipper.side));
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('body', () {
|
|
||||||
flameTester.test(
|
|
||||||
'is dynamic',
|
|
||||||
(game) async {
|
|
||||||
final flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
|
|
||||||
expect(flipper.body.bodyType, equals(BodyType.dynamic));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
flameTester.test(
|
|
||||||
'ignores gravity',
|
|
||||||
(game) async {
|
|
||||||
final flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
|
|
||||||
expect(flipper.body.gravityScale, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
flameTester.test(
|
|
||||||
'has greater mass than Ball',
|
|
||||||
(game) async {
|
|
||||||
final flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
final ball = Ball(baseColor: Colors.white);
|
|
||||||
|
|
||||||
await game.ready();
|
|
||||||
await game.ensureAddAll([flipper, ball]);
|
|
||||||
|
|
||||||
expect(
|
|
||||||
flipper.body.getMassData().mass,
|
|
||||||
greaterThan(ball.body.getMassData().mass),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('fixtures', () {
|
|
||||||
flameTester.test(
|
|
||||||
'has three',
|
|
||||||
(game) async {
|
|
||||||
final flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
|
|
||||||
expect(flipper.body.fixtures.length, equals(3));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
flameTester.test(
|
|
||||||
'has density',
|
|
||||||
(game) async {
|
|
||||||
final flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
|
|
||||||
final fixtures = flipper.body.fixtures;
|
|
||||||
final density = fixtures.fold<double>(
|
|
||||||
0,
|
|
||||||
(sum, fixture) => sum + fixture.density,
|
|
||||||
);
|
|
||||||
|
|
||||||
expect(density, greaterThan(0));
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group('onKeyEvent', () {
|
|
||||||
final leftKeys = UnmodifiableListView([
|
|
||||||
LogicalKeyboardKey.arrowLeft,
|
|
||||||
LogicalKeyboardKey.keyA,
|
|
||||||
]);
|
|
||||||
final rightKeys = UnmodifiableListView([
|
|
||||||
LogicalKeyboardKey.arrowRight,
|
|
||||||
LogicalKeyboardKey.keyD,
|
|
||||||
]);
|
|
||||||
|
|
||||||
group('and Flipper is left', () {
|
|
||||||
late Flipper flipper;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
flipper = Flipper(
|
|
||||||
side: BoardSide.left,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves upwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isPositive);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves downwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isNegative);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group('and Flipper is right', () {
|
|
||||||
late Flipper flipper;
|
|
||||||
|
|
||||||
setUp(() {
|
|
||||||
flipper = Flipper(
|
|
||||||
side: BoardSide.right,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves upwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isPositive);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(rightKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'moves downwards '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isNegative);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyUpEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is released',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
testRawKeyDownEvents(leftKeys, (event) {
|
|
||||||
flameTester.test(
|
|
||||||
'does nothing '
|
|
||||||
'when ${event.logicalKey.keyLabel} is pressed',
|
|
||||||
(game) async {
|
|
||||||
await game.ensureAdd(flipper);
|
|
||||||
flipper.onKeyEvent(event, {});
|
|
||||||
|
|
||||||
expect(flipper.body.linearVelocity.y, isZero);
|
|
||||||
expect(flipper.body.linearVelocity.x, isZero);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
@ -1,44 +1,195 @@
|
|||||||
// ignore_for_file: prefer_const_constructors
|
// ignore_for_file: prefer_const_constructors
|
||||||
|
|
||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:leaderboard_repository/leaderboard_repository.dart';
|
||||||
import 'package:mockingjay/mockingjay.dart';
|
import 'package:mockingjay/mockingjay.dart';
|
||||||
import 'package:pinball/game/game.dart';
|
import 'package:pinball/game/game.dart';
|
||||||
import 'package:pinball/l10n/l10n.dart';
|
import 'package:pinball/l10n/l10n.dart';
|
||||||
|
import 'package:pinball/leaderboard/leaderboard.dart';
|
||||||
import 'package:pinball_theme/pinball_theme.dart';
|
import 'package:pinball_theme/pinball_theme.dart';
|
||||||
|
|
||||||
import '../../../helpers/helpers.dart';
|
import '../../../helpers/helpers.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('GameOverDialog', () {
|
group('GameOverDialog', () {
|
||||||
testWidgets('renders correctly', (tester) async {
|
testWidgets('renders GameOverDialogView', (tester) async {
|
||||||
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
|
||||||
await tester.pumpApp(
|
await tester.pumpApp(
|
||||||
const GameOverDialog(
|
GameOverDialog(
|
||||||
|
score: 1000,
|
||||||
theme: DashTheme(),
|
theme: DashTheme(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
expect(find.text(l10n.gameOver), findsOneWidget);
|
expect(find.byType(GameOverDialogView), findsOneWidget);
|
||||||
expect(find.text(l10n.leaderboard), findsOneWidget);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
testWidgets('tapping on leaderboard button navigates to LeaderBoardPage',
|
group('GameOverDialogView', () {
|
||||||
(tester) async {
|
late LeaderboardBloc leaderboardBloc;
|
||||||
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
|
||||||
final navigator = MockNavigator();
|
|
||||||
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
|
|
||||||
|
|
||||||
await tester.pumpApp(
|
final leaderboard = [
|
||||||
const GameOverDialog(
|
LeaderboardEntry(
|
||||||
theme: DashTheme(),
|
rank: '1',
|
||||||
|
playerInitials: 'ABC',
|
||||||
|
score: 5000,
|
||||||
|
character: DashTheme().characterAsset,
|
||||||
),
|
),
|
||||||
navigator: navigator,
|
];
|
||||||
|
final entryData = LeaderboardEntryData(
|
||||||
|
playerInitials: 'VGV',
|
||||||
|
score: 10000,
|
||||||
|
character: CharacterType.dash,
|
||||||
);
|
);
|
||||||
|
|
||||||
await tester.tap(find.widgetWithText(TextButton, l10n.leaderboard));
|
setUp(() {
|
||||||
|
leaderboardBloc = MockLeaderboardBloc();
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: const LeaderboardState.initial(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders input text view when bloc emits [loading]',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.widgetWithText(TextButton, l10n.addUser), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders error view when bloc emits [error]', (tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState.initial()
|
||||||
|
.copyWith(status: LeaderboardStatus.error),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(find.text(l10n.error), findsOneWidget);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('renders success view when bloc emits [success]',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState(
|
||||||
|
status: LeaderboardStatus.success,
|
||||||
|
ranking: LeaderboardRanking(ranking: 1, outOf: 2),
|
||||||
|
leaderboard: leaderboard,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(
|
||||||
|
find.widgetWithText(TextButton, l10n.leaderboard),
|
||||||
|
findsOneWidget,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('adds LeaderboardEntryAdded when tap on add user button',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState.initial(),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.enterText(
|
||||||
|
find.byKey(const Key('player_initials_text_field')),
|
||||||
|
entryData.playerInitials,
|
||||||
|
);
|
||||||
|
|
||||||
|
final button = find.widgetWithText(TextButton, l10n.addUser);
|
||||||
|
await tester.ensureVisible(button);
|
||||||
|
await tester.tap(button);
|
||||||
|
|
||||||
|
verify(
|
||||||
|
() => leaderboardBloc.add(LeaderboardEntryAdded(entry: entryData)),
|
||||||
|
).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
testWidgets('navigates to LeaderboardPage when tap on leaderboard button',
|
||||||
|
(tester) async {
|
||||||
|
final l10n = await AppLocalizations.delegate.load(Locale('en'));
|
||||||
|
final navigator = MockNavigator();
|
||||||
|
when(() => navigator.push<void>(any())).thenAnswer((_) async {});
|
||||||
|
whenListen(
|
||||||
|
leaderboardBloc,
|
||||||
|
const Stream<LeaderboardState>.empty(),
|
||||||
|
initialState: LeaderboardState(
|
||||||
|
status: LeaderboardStatus.success,
|
||||||
|
ranking: LeaderboardRanking(ranking: 1, outOf: 2),
|
||||||
|
leaderboard: leaderboard,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
await tester.pumpApp(
|
||||||
|
BlocProvider.value(
|
||||||
|
value: leaderboardBloc,
|
||||||
|
child: GameOverDialogView(
|
||||||
|
score: entryData.score,
|
||||||
|
theme: entryData.character.toTheme,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
navigator: navigator,
|
||||||
|
);
|
||||||
|
|
||||||
|
final button = find.widgetWithText(TextButton, l10n.leaderboard);
|
||||||
|
await tester.ensureVisible(button);
|
||||||
|
await tester.tap(button);
|
||||||
|
|
||||||
verify(() => navigator.push<void>(any())).called(1);
|
verify(() => navigator.push<void>(any())).called(1);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|