mirror of https://github.com/flutter/pinball.git
parent
a346419694
commit
296add890f
Before Width: | Height: | Size: 59 KiB After Width: | Height: | Size: 70 KiB |
@ -0,0 +1,48 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_components/src/components/kicker/behaviors/behaviors.dart';
|
||||||
|
|
||||||
|
import '../../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'KickerBallContactBehavior',
|
||||||
|
() {
|
||||||
|
test('can be instantiated', () {
|
||||||
|
expect(
|
||||||
|
KickerBallContactBehavior(),
|
||||||
|
isA<KickerBallContactBehavior>(),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test(
|
||||||
|
'beginContact emits onBallContacted when contacts with a ball',
|
||||||
|
(game) async {
|
||||||
|
final behavior = KickerBallContactBehavior();
|
||||||
|
final bloc = MockKickerCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<KickerState>.empty(),
|
||||||
|
initialState: KickerState.lit,
|
||||||
|
);
|
||||||
|
|
||||||
|
final kicker = Kicker.test(bloc: bloc);
|
||||||
|
await kicker.add(behavior);
|
||||||
|
await game.ensureAdd(kicker);
|
||||||
|
|
||||||
|
behavior.beginContact(MockBall(), MockContact());
|
||||||
|
|
||||||
|
verify(kicker.bloc.onBallContacted).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flame_test/flame_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:mocktail/mocktail.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
import 'package:pinball_components/src/components/kicker/behaviors/behaviors.dart';
|
||||||
|
|
||||||
|
import '../../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
final flameTester = FlameTester(TestGame.new);
|
||||||
|
|
||||||
|
group(
|
||||||
|
'KickerBlinkingBehavior',
|
||||||
|
() {
|
||||||
|
flameTester.testGameWidget(
|
||||||
|
'calls onBlinked after 0.05 seconds when dimmed',
|
||||||
|
setUp: (game, tester) async {
|
||||||
|
final behavior = KickerBlinkingBehavior();
|
||||||
|
final bloc = MockKickerCubit();
|
||||||
|
final streamController = StreamController<KickerState>();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
streamController.stream,
|
||||||
|
initialState: KickerState.lit,
|
||||||
|
);
|
||||||
|
|
||||||
|
final kicker = Kicker.test(bloc: bloc);
|
||||||
|
await kicker.add(behavior);
|
||||||
|
await game.ensureAdd(kicker);
|
||||||
|
|
||||||
|
streamController.add(KickerState.dimmed);
|
||||||
|
await tester.pump();
|
||||||
|
game.update(0.05);
|
||||||
|
|
||||||
|
await streamController.close();
|
||||||
|
verify(bloc.onBlinked).called(1);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
import 'package:pinball_components/pinball_components.dart';
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
group(
|
||||||
|
'KickerCubit',
|
||||||
|
() {
|
||||||
|
blocTest<KickerCubit, KickerState>(
|
||||||
|
'onBallContacted emits dimmed',
|
||||||
|
build: KickerCubit.new,
|
||||||
|
act: (bloc) => bloc.onBallContacted(),
|
||||||
|
expect: () => [KickerState.dimmed],
|
||||||
|
);
|
||||||
|
|
||||||
|
blocTest<KickerCubit, KickerState>(
|
||||||
|
'onBlinked emits lit',
|
||||||
|
build: KickerCubit.new,
|
||||||
|
act: (bloc) => bloc.onBlinked(),
|
||||||
|
expect: () => [KickerState.lit],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in new issue