// ignore_for_file: cascade_invocations import 'package:flame_bloc/flame_bloc.dart'; import 'package:flame_forge2d/flame_forge2d.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:mocktail/mocktail.dart'; import 'package:pinball/game/behaviors/behaviors.dart'; import 'package:pinball/game/components/dino_desert/behaviors/behaviors.dart'; import 'package:pinball/game/game.dart'; import 'package:pinball_components/pinball_components.dart'; class _TestGame extends Forge2DGame { @override Future onLoad() async { images.prefix = ''; await images.loadAll([ Assets.images.dino.animatronic.head.keyName, Assets.images.dino.animatronic.mouth.keyName, Assets.images.dino.topWall.keyName, Assets.images.dino.topWallTunnel.keyName, Assets.images.dino.bottomWall.keyName, Assets.images.slingshot.upper.keyName, Assets.images.slingshot.lower.keyName, ]); } Future pump(DinoDesert child) async { await ensureAdd( FlameBlocProvider.value( value: _MockGameBloc(), children: [child], ), ); } } class _MockGameBloc extends Mock implements GameBloc {} void main() { TestWidgetsFlutterBinding.ensureInitialized(); final flameTester = FlameTester(_TestGame.new); group('DinoDesert', () { flameTester.testGameWidget( 'loads correctly', setUp: (game, _) async { final component = DinoDesert(); await game.pump(component); }, verify: (game, _) async { expect(game.descendants().whereType(), isNotEmpty); }, ); group('loads', () { flameTester.testGameWidget( 'a ChromeDino', setUp: (game, _) async { await game.pump(DinoDesert()); }, verify: (game, _) async { expect( game.descendants().whereType().length, equals(1), ); }, ); flameTester.testGameWidget( 'DinoWalls', setUp: (game, _) async { await game.pump(DinoDesert()); }, verify: (game, _) async { expect( game.descendants().whereType().length, equals(1), ); }, ); flameTester.testGameWidget( 'Slingshots', setUp: (game, _) async { await game.pump(DinoDesert()); }, verify: (game, _) async { expect( game.descendants().whereType().length, equals(1), ); }, ); }); group('adds', () { flameTester.testGameWidget( 'ScoringContactBehavior to ChromeDino', setUp: (game, _) async { await game.pump(DinoDesert()); }, verify: (game, _) async { final chromeDino = game.descendants().whereType().single; expect( chromeDino.firstChild(), isNotNull, ); }, ); flameTester.testGameWidget( 'a ChromeDinoBonusBehavior', setUp: (game, _) async { await game.pump(DinoDesert()); }, verify: (game, _) async { final chromeDino = game.descendants().whereType().single; expect( chromeDino.children.whereType().single, isNotNull, ); }, ); }); }); }