// ignore_for_file: cascade_invocations import 'package:flame/game.dart'; import 'package:flame/src/components/component.dart'; import 'package:flame_test/flame_test.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:pinball/flame/flame.dart'; class TestComponentController extends ComponentController { TestComponentController(Component component) : super(component); } class ControlledComponent extends Component with Controls { ControlledComponent() : super() { controller = TestComponentController(this); } } void main() { TestWidgetsFlutterBinding.ensureInitialized(); final flameTester = FlameTester(FlameGame.new); group('ComponentController', () { flameTester.test( 'can be instantiated', (game) async { expect( TestComponentController(Component()), isA(), ); }, ); flameTester.test( 'throws AssertionError when not attached to controlled component', (game) async { final component = Component(); final controller = TestComponentController(component); final anotherComponet = Component(); await expectLater( () async => await anotherComponet.add(controller), throwsAssertionError, ); }, ); }); group('Controls', () { flameTester.test( 'can be instantiated', (game) async { expect(ControlledComponent(), isA()); }, ); flameTester.test('adds controller', (game) async { final component = ControlledComponent(); await game.add(component); await game.ready(); expect(component.contains(component.controller), isTrue); }); }); }