diff --git a/test/game/components/jetpack_ramp_test.dart b/test/game/components/jetpack_ramp_test.dart index 6d769812..24089496 100644 --- a/test/game/components/jetpack_ramp_test.dart +++ b/test/game/components/jetpack_ramp_test.dart @@ -1,5 +1,6 @@ // ignore_for_file: cascade_invocations +import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -16,17 +17,43 @@ void main() { group('JetpackRamp', () { group('body', () { + bool Function(Component) pathwaySelector(Vector2 position) => + (component) => + component is Pathway && component.body.position == position; + flameTester.test( 'has a Pathway.arc at position', (game) async { + final position = Vector2.all(10); final jetpackRamp = JetpackRamp( - position: Vector2.zero(), + position: position, + ); + await game.ready(); + await game.ensureAdd(jetpackRamp); + + expect( + () => jetpackRamp.children.singleWhere( + pathwaySelector(position), + ), + returnsNormally, + ); + }, + ); + + flameTester.test( + 'path is static', + (game) async { + final position = Vector2.all(10); + final jetpackRamp = JetpackRamp( + position: position, ); await game.ready(); await game.ensureAdd(jetpackRamp); - final pathways = game.children.whereType().toList(); - expect(pathways.length, 1); + final pathways = jetpackRamp.children.whereType().toList(); + for (final pathway in pathways) { + expect(pathway.body.bodyType, equals(BodyType.static)); + } }, ); @@ -45,7 +72,7 @@ void main() { ); flameTester.test( - 'sensors and ramp are static', + 'sensors are static', (game) async { final jetpackRamp = JetpackRamp( position: Vector2.zero(), @@ -53,7 +80,10 @@ void main() { await game.ready(); await game.ensureAdd(jetpackRamp); - game.contains(jetpackRamp); + final rampAreas = game.children.whereType().toList(); + for (final rampArea in rampAreas) { + expect(rampArea.body.bodyType, equals(BodyType.static)); + } }, ); }); @@ -67,6 +97,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(game.contains(ramp), isTrue); @@ -81,9 +112,9 @@ void main() { position: position, orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); - game.contains(ramp); expect(ramp.orientation, RampOrientation.down); }, ); @@ -97,9 +128,9 @@ void main() { position: position, orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); - game.contains(ramp); expect(ramp.body.position, position); }, ); @@ -111,6 +142,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(ramp.body.bodyType, equals(BodyType.static)); @@ -125,6 +157,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(ramp.body.fixtures.length, 1); @@ -142,6 +175,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); final fixture = ramp.body.fixtures.first; diff --git a/test/game/components/sparky_ramp_test.dart b/test/game/components/sparky_ramp_test.dart index e82190a4..eb0c8b77 100644 --- a/test/game/components/sparky_ramp_test.dart +++ b/test/game/components/sparky_ramp_test.dart @@ -1,5 +1,6 @@ // ignore_for_file: cascade_invocations +import 'package:flame/components.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; @@ -16,17 +17,43 @@ void main() { group('SparkyRamp', () { group('body', () { + bool Function(Component) pathwaySelector(Vector2 position) => + (component) => + component is Pathway && component.body.position == position; + flameTester.test( 'has a Pathway.arc at position', (game) async { + final position = Vector2.all(10); final sparkyRamp = SparkyRamp( - position: Vector2.zero(), + position: position, + ); + await game.ready(); + await game.ensureAdd(sparkyRamp); + + expect( + () => game.children.singleWhere( + pathwaySelector(position), + ), + returnsNormally, + ); + }, + ); + + flameTester.test( + 'path is static', + (game) async { + final position = Vector2.all(10); + final sparkyRamp = SparkyRamp( + position: position, ); await game.ready(); await game.ensureAdd(sparkyRamp); final pathways = game.children.whereType().toList(); - expect(pathways.length, 1); + for (final pathway in pathways) { + expect(pathway.body.bodyType, equals(BodyType.static)); + } }, ); @@ -45,7 +72,7 @@ void main() { ); flameTester.test( - 'sensors and ramp are static', + 'sensors are static', (game) async { final sparkyRamp = SparkyRamp( position: Vector2.zero(), @@ -53,7 +80,10 @@ void main() { await game.ready(); await game.ensureAdd(sparkyRamp); - game.contains(sparkyRamp); + final rampAreas = game.children.whereType().toList(); + for (final rampArea in rampAreas) { + expect(rampArea.body.bodyType, equals(BodyType.static)); + } }, ); }); @@ -67,6 +97,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(game.contains(ramp), isTrue); @@ -81,9 +112,9 @@ void main() { position: position, orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); - game.contains(ramp); expect(ramp.orientation, RampOrientation.down); }, ); @@ -97,9 +128,9 @@ void main() { position: position, orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); - game.contains(ramp); expect(ramp.body.position, position); }, ); @@ -111,6 +142,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(ramp.body.bodyType, equals(BodyType.static)); @@ -125,6 +157,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); expect(ramp.body.fixtures.length, 1); @@ -142,6 +175,7 @@ void main() { position: Vector2.zero(), orientation: RampOrientation.down, ); + await game.ready(); await game.ensureAdd(ramp); final fixture = ramp.body.fixtures.first; diff --git a/test/game/pinball_game_test.dart b/test/game/pinball_game_test.dart index d980578d..64f89353 100644 --- a/test/game/pinball_game_test.dart +++ b/test/game/pinball_game_test.dart @@ -98,19 +98,13 @@ void main() { }); group('Paths', () { - bool Function(Component) rampSelector() => - (component) => component is T; flameTester.test( 'has only one JetpackRamp', (game) async { await game.ready(); - expect( - () => game.children.singleWhere( - rampSelector(), - ), - returnsNormally, - ); + final rampAreas = game.children.whereType().toList(); + expect(rampAreas.length, 1); }, ); @@ -119,12 +113,8 @@ void main() { (game) async { await game.ready(); - expect( - () => game.children.singleWhere( - rampSelector(), - ), - returnsNormally, - ); + final rampAreas = game.children.whereType().toList(); + expect(rampAreas.length, 1); }, ); });