refactor: simplified testing for components in tree

pull/46/head
alestiago 4 years ago
parent b0932799eb
commit 963b400c41

@ -18,18 +18,13 @@ void main() {
// [BallScorePointsCallback] once the following issue is resolved: // [BallScorePointsCallback] once the following issue is resolved:
// https://github.com/flame-engine/flame/issues/1416 // https://github.com/flame-engine/flame/issues/1416
group('components', () { group('components', () {
bool Function(Component) componentSelector<T>() =>
(component) => component is T;
flameTester.test( flameTester.test(
'has three Walls', 'has three Walls',
(game) async { (game) async {
await game.ready(); await game.ready();
final walls = game.children final walls = game.children.where(
.where( (component) => component is Wall && component is! BottomWall,
(component) => component is Wall && component is! BottomWall, );
)
.toList();
// TODO(allisonryan0002): expect 3 when launch track is added and // TODO(allisonryan0002): expect 3 when launch track is added and
// temporary wall is removed. // temporary wall is removed.
expect(walls.length, 4); expect(walls.length, 4);
@ -42,10 +37,8 @@ void main() {
await game.ready(); await game.ready();
expect( expect(
() => game.children.singleWhere( game.children.whereType<BottomWall>().length,
componentSelector<BottomWall>(), equals(1),
),
returnsNormally,
); );
}, },
); );
@ -54,24 +47,18 @@ void main() {
'has only one Plunger', 'has only one Plunger',
(game) async { (game) async {
await game.ready(); await game.ready();
expect( expect(
() => game.children.singleWhere( game.children.whereType<Plunger>().length,
(component) => component is Plunger, equals(1),
),
returnsNormally,
); );
}, },
); );
flameTester.test('has only one FlipperGroup', (game) async { flameTester.test('has only one FlipperGroup', (game) async {
await game.ready(); await game.ready();
expect( expect(
() => game.children.singleWhere( game.children.whereType<FlipperGroup>().length,
(component) => component is FlipperGroup, equals(1),
),
returnsNormally,
); );
}); });
@ -79,7 +66,7 @@ void main() {
'has two Baseboards', 'has two Baseboards',
(game) async { (game) async {
await game.ready(); await game.ready();
final baseboards = game.children.whereType<Baseboard>().toList(); final baseboards = game.children.whereType<Baseboard>();
expect(baseboards.length, 2); expect(baseboards.length, 2);
}, },
); );

Loading…
Cancel
Save