diff --git a/lib/game/components/plunger.dart b/lib/game/components/plunger.dart index d9137457..5703e525 100644 --- a/lib/game/components/plunger.dart +++ b/lib/game/components/plunger.dart @@ -85,7 +85,7 @@ class Plunger extends BodyComponent with KeyboardHandler, InitialPosition { plunger: this, anchor: anchor, ); - world.createJoint(jointDef); + world.createJoint(PrismaticJoint(jointDef)); } @override diff --git a/packages/pinball_components/pubspec.yaml b/packages/pinball_components/pubspec.yaml index 849469cc..aa1eb224 100644 --- a/packages/pinball_components/pubspec.yaml +++ b/packages/pinball_components/pubspec.yaml @@ -7,8 +7,8 @@ environment: sdk: ">=2.16.0 <3.0.0" dependencies: - flame: ^1.1.0-releasecandidate.6 - flame_forge2d: ^0.9.0-releasecandidate.6 + flame: ^1.1.0 + flame_forge2d: ^0.10.0 flutter: sdk: flutter geometry: @@ -16,7 +16,7 @@ dependencies: dev_dependencies: - flame_test: ^1.1.0 + flame_test: ^1.3.0 flutter_test: sdk: flutter mocktail: ^0.2.0 diff --git a/packages/pinball_components/sandbox/pubspec.lock b/packages/pinball_components/sandbox/pubspec.lock index bb132da7..b0de4903 100644 --- a/packages/pinball_components/sandbox/pubspec.lock +++ b/packages/pinball_components/sandbox/pubspec.lock @@ -91,14 +91,14 @@ packages: name: flame url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-releasecandidate.6" + version: "1.1.0" flame_forge2d: dependency: "direct main" description: name: flame_forge2d url: "https://pub.dartlang.org" source: hosted - version: "0.9.0-releasecandidate.6" + version: "0.10.0" flutter: dependency: "direct main" description: flutter @@ -134,7 +134,7 @@ packages: name: forge2d url: "https://pub.dartlang.org" source: hosted - version: "0.9.0" + version: "0.10.0" freezed_annotation: dependency: transitive description: diff --git a/packages/pinball_components/sandbox/pubspec.yaml b/packages/pinball_components/sandbox/pubspec.yaml index 0c8267a8..94c0479b 100644 --- a/packages/pinball_components/sandbox/pubspec.yaml +++ b/packages/pinball_components/sandbox/pubspec.yaml @@ -8,8 +8,8 @@ environment: dependencies: dashbook: ^0.1.7 - flame: ^1.1.0-releasecandidate.6 - flame_forge2d: ^0.9.0-releasecandidate.6 + flame: ^1.1.0 + flame_forge2d: ^0.10.0 flutter: sdk: flutter pinball_components: diff --git a/packages/pinball_components/test/src/components/golden/spaceship.png b/packages/pinball_components/test/src/components/golden/spaceship.png index 579d955f..da665718 100644 Binary files a/packages/pinball_components/test/src/components/golden/spaceship.png and b/packages/pinball_components/test/src/components/golden/spaceship.png differ diff --git a/packages/pinball_components/test/src/components/spaceship_test.dart b/packages/pinball_components/test/src/components/spaceship_test.dart index 005b41d3..4c185675 100644 --- a/packages/pinball_components/test/src/components/spaceship_test.dart +++ b/packages/pinball_components/test/src/components/spaceship_test.dart @@ -1,6 +1,5 @@ // ignore_for_file: cascade_invocations -import 'package:flame/game.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -39,24 +38,22 @@ void main() { }); group('Spaceship', () { - testWidgets('renders correctly', (tester) async { - final game = TestGame(); + final tester = FlameTester(TestGame.new); - // TODO(erickzanardo): This should be handled by flame test. - // refctor it when https://github.com/flame-engine/flame/pull/1501 is merged - await tester.runAsync(() async { - await tester.pumpWidget(GameWidget(game: game)); - await game.ready(); + tester.testGameWidget( + 'renders correctly', + setUp: (game, tester) async { await game.addFromBlueprint(Spaceship(position: Vector2(30, -30))); await game.ready(); await tester.pump(); - }); - - await expectLater( - find.byGame(), - matchesGoldenFile('golden/spaceship.png'), - ); - }); + }, + verify: (game, tester) async { + await expectLater( + find.byGame(), + matchesGoldenFile('golden/spaceship.png'), + ); + }, + ); }); group('SpaceshipEntranceBallContactCallback', () { diff --git a/pubspec.lock b/pubspec.lock index 067559c4..ada9db4e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -182,28 +182,28 @@ packages: name: flame url: "https://pub.dartlang.org" source: hosted - version: "1.1.0-releasecandidate.6" + version: "1.1.0" flame_bloc: dependency: "direct main" description: name: flame_bloc url: "https://pub.dartlang.org" source: hosted - version: "1.2.0-releasecandidate.6" + version: "1.2.0" flame_forge2d: dependency: "direct main" description: name: flame_forge2d url: "https://pub.dartlang.org" source: hosted - version: "0.9.0-releasecandidate.6" + version: "0.10.0" flame_test: dependency: "direct dev" description: name: flame_test url: "https://pub.dartlang.org" source: hosted - version: "1.1.0" + version: "1.3.0" flutter: dependency: "direct main" description: flutter @@ -237,7 +237,7 @@ packages: name: forge2d url: "https://pub.dartlang.org" source: hosted - version: "0.9.0" + version: "0.10.0" frontend_server_client: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index d2b520a9..a0cca553 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -10,9 +10,9 @@ dependencies: bloc: ^8.0.2 cloud_firestore: ^3.1.10 equatable: ^2.0.3 - flame: ^1.1.0-releasecandidate.6 - flame_bloc: ^1.2.0-releasecandidate.6 - flame_forge2d: ^0.9.0-releasecandidate.6 + flame: ^1.1.0 + flame_bloc: ^1.2.0 + flame_forge2d: ^0.10.0 flutter: sdk: flutter flutter_bloc: ^8.0.1 @@ -30,7 +30,7 @@ dependencies: dev_dependencies: bloc_test: ^9.0.2 - flame_test: ^1.1.0 + flame_test: ^1.3.0 flutter_test: sdk: flutter mockingjay: ^0.2.0 diff --git a/test/game/components/ball_test.dart b/test/game/components/ball_test.dart index a872dc1f..f12b3569 100644 --- a/test/game/components/ball_test.dart +++ b/test/game/components/ball_test.dart @@ -27,11 +27,12 @@ void main() { final tester = flameBlocTester(gameBloc: () => gameBloc); - tester.widgetTest( + tester.testGameWidget( 'adds BallLost to GameBloc', - (game, tester) async { + setUp: (game, tester) async { await game.ready(); - + }, + verify: (game, tester) async { game.children.whereType().first.controller.lost(); await tester.pump(); @@ -39,14 +40,15 @@ void main() { }, ); - tester.widgetTest( + tester.testGameWidget( 'resets the ball if the game is not over', - (game, tester) async { + setUp: (game, tester) async { await game.ready(); game.children.whereType().first.controller.lost(); await game.ready(); // Making sure that all additions are done - + }, + verify: (game, tester) async { expect( game.children.whereType().length, equals(1), @@ -54,9 +56,9 @@ void main() { }, ); - tester.widgetTest( + tester.testGameWidget( 'no ball is added on game over', - (game, tester) async { + setUp: (game, tester) async { whenListen( gameBloc, const Stream.empty(), @@ -72,7 +74,8 @@ void main() { game.children.whereType().first.controller.lost(); await tester.pump(); - + }, + verify: (game, tester) async { expect( game.children.whereType().length, equals(0), diff --git a/test/game/components/bonus_word_test.dart b/test/game/components/bonus_word_test.dart index 001ccd46..42cf19c4 100644 --- a/test/game/components/bonus_word_test.dart +++ b/test/game/components/bonus_word_test.dart @@ -205,22 +205,24 @@ void main() { ); }); - tester.widgetTest( + tester.testGameWidget( 'adds BonusLetterActivated to GameBloc when not activated', - (game, tester) async { + setUp: (game, tester) async { await game.ready(); final bonusLetter = game.descendants().whereType().first; bonusLetter.activate(); await game.ready(); await tester.pump(); + }, + verify: (game, tester) async { verify(() => gameBloc.add(const BonusLetterActivated(0))).called(1); }, ); - tester.widgetTest( + tester.testGameWidget( "doesn't add BonusLetterActivated to GameBloc when already activated", - (game, tester) async { + setUp: (game, tester) async { const state = GameState( score: 0, balls: 2, @@ -238,14 +240,15 @@ void main() { final bonusLetter = game.descendants().whereType().first; bonusLetter.activate(); await game.ready(); - + }, + verify: (game, tester) async { verifyNever(() => gameBloc.add(const BonusLetterActivated(0))); }, ); - tester.widgetTest( + tester.testGameWidget( 'adds a ColorEffect', - (game, tester) async { + setUp: (game, tester) async { const state = GameState( score: 0, balls: 2, @@ -260,7 +263,9 @@ void main() { bonusLetter.onNewState(state); await tester.pump(); - + }, + verify: (game, tester) async { + final bonusLetter = game.descendants().whereType().first; expect( bonusLetter.children.whereType().length, equals(1), @@ -268,9 +273,14 @@ void main() { }, ); - tester.widgetTest( + tester.testGameWidget( 'only listens when there is a change on the letter status', - (game, tester) async { + setUp: (game, tester) async { + await game.ready(); + final bonusLetter = game.descendants().whereType().first; + bonusLetter.activate(); + }, + verify: (game, tester) async { const state = GameState( score: 0, balls: 2, @@ -278,11 +288,7 @@ void main() { activatedDashNests: {}, bonusHistory: [], ); - - await game.ready(); final bonusLetter = game.descendants().whereType().first; - bonusLetter.activate(); - expect( bonusLetter.listenWhen(const GameState.initial(), state), isTrue, diff --git a/test/game/components/flutter_forest_test.dart b/test/game/components/flutter_forest_test.dart index 659a4f13..3f4db6ff 100644 --- a/test/game/components/flutter_forest_test.dart +++ b/test/game/components/flutter_forest_test.dart @@ -30,8 +30,6 @@ void main() { 'a FlutterSignPost', (game) async { await game.ready(); - final flutterForest = FlutterForest(); - await game.ensureAdd(flutterForest); expect( game.descendants().whereType().length, @@ -71,10 +69,12 @@ void main() { ); }); - tester.widgetTest( + tester.testGameWidget( 'listens when a Bonus.dashNest is added', - (game, tester) async { + setUp: (game, tester) async { await game.ready(); + }, + verify: (game, tester) async { final flutterForest = game.descendants().whereType().first; @@ -85,7 +85,6 @@ void main() { activatedDashNests: {}, bonusHistory: [GameBonus.dashNest], ); - expect( flutterForest.listenWhen(const GameState.initial(), state), isTrue, @@ -107,15 +106,16 @@ void main() { ); }); - tester.widgetTest( + final dashNestBumper = MockDashNestBumper(); + tester.testGameWidget( 'adds a DashNestActivated event with DashNestBumper.id', - (game, tester) async { - final contactCallback = DashNestBumperBallContactCallback(); + setUp: (game, tester) async { const id = '0'; - final dashNestBumper = MockDashNestBumper(); when(() => dashNestBumper.id).thenReturn(id); when(() => dashNestBumper.gameRef).thenReturn(game); - + }, + verify: (game, tester) async { + final contactCallback = DashNestBumperBallContactCallback(); contactCallback.begin(dashNestBumper, MockBall(), MockContact()); verify(() => gameBloc.add(DashNestActivated(dashNestBumper.id))) diff --git a/test/game/components/plunger_test.dart b/test/game/components/plunger_test.dart index 1cec7e0c..c6787be6 100644 --- a/test/game/components/plunger_test.dart +++ b/test/game/components/plunger_test.dart @@ -233,7 +233,7 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); expect(jointDef.bodyB, equals(anchor.body)); }, @@ -250,7 +250,7 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); expect(jointDef.enableLimit, isTrue); }, @@ -267,7 +267,7 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); expect(jointDef.lowerTranslation, equals(double.negativeInfinity)); }, @@ -284,7 +284,7 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); expect(jointDef.collideConnected, isTrue); }, @@ -292,11 +292,11 @@ void main() { }); testRawKeyUpEvents([LogicalKeyboardKey.space], (event) { - flameTester.widgetTest( + late final anchor = PlungerAnchor(plunger: plunger); + flameTester.testGameWidget( 'plunger cannot go below anchor', - (game, tester) async { + setUp: (game, tester) async { await game.ensureAdd(plunger); - final anchor = PlungerAnchor(plunger: plunger); await game.ensureAdd(anchor); // Giving anchor a shape for the plunger to collide with. @@ -306,19 +306,20 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); await tester.pump(const Duration(seconds: 1)); - + }, + verify: (game, tester) async { expect(plunger.body.position.y > anchor.body.position.y, isTrue); }, ); }); testRawKeyUpEvents([LogicalKeyboardKey.space], (event) { - flameTester.widgetTest( + flameTester.testGameWidget( 'plunger cannot excessively exceed starting position', - (game, tester) async { + setUp: (game, tester) async { await game.ensureAdd(plunger); final anchor = PlungerAnchor(plunger: plunger); await game.ensureAdd(anchor); @@ -327,12 +328,13 @@ void main() { plunger: plunger, anchor: anchor, ); - game.world.createJoint(jointDef); + game.world.createJoint(PrismaticJoint(jointDef)); plunger.body.setTransform(Vector2(0, -1), 0); await tester.pump(const Duration(seconds: 1)); - + }, + verify: (game, tester) async { expect(plunger.body.position.y < 1, isTrue); }, );