fix: spitting test

pull/277/head
Allison Ryan 3 years ago
parent 3af0c51b05
commit a896da3d97

@ -30,7 +30,7 @@ class _BarrierBehindDino extends BodyComponent {
Body createBody() { Body createBody() {
final shape = EdgeShape() final shape = EdgeShape()
..set( ..set(
Vector2(27, -14.2), Vector2(25, -14.2),
Vector2(25, -7.7), Vector2(25, -7.7),
); );

@ -34,7 +34,7 @@ class ChromeDinoSpittingBehavior extends Component
void _spit() { void _spit() {
parent.bloc.state.ball! parent.bloc.state.ball!
..firstChild<SpriteComponent>()!.setOpacity(1) ..firstChild<SpriteComponent>()!.setOpacity(1)
..body.linearVelocity = Vector2(-50, 3); ..body.linearVelocity = Vector2(-50, 0);
parent.bloc.onSpit(); parent.bloc.onSpit();
} }

@ -28,31 +28,47 @@ void main() {
); );
}); });
flameTester.test( group('on the next time the mouth opens and status is chomping', () {
'creates a RevoluteJoint', flameTester.test(
(game) async { 'sets ball sprite to visible and sets a linear velocity',
final behavior = ChromeDinoSpittingBehavior(); (game) async {
final bloc = MockChromeDinoCubit(); final ball = Ball(baseColor: Colors.red);
whenListen( final behavior = ChromeDinoSpittingBehavior();
bloc, final bloc = MockChromeDinoCubit();
const Stream<ChromeDinoState>.empty(), final streamController = StreamController<ChromeDinoState>();
initialState: const ChromeDinoState.inital(), final chompingState = ChromeDinoState(
); status: ChromeDinoStatus.chomping,
isMouthOpen: true,
ball: ball,
);
whenListen(
bloc,
streamController.stream,
initialState: chompingState,
);
final chromeDino = ChromeDino.test(bloc: bloc); final chromeDino = ChromeDino.test(bloc: bloc);
await chromeDino.add(behavior); await chromeDino.add(behavior);
await game.ensureAdd(chromeDino); await game.ensureAddAll([chromeDino, ball]);
streamController.add(chompingState.copyWith(isMouthOpen: false));
streamController.add(chompingState.copyWith(isMouthOpen: true));
await game.ready();
game
.descendants()
.whereType<TimerComponent>()
.single
.timer
.onTick!();
expect( expect(ball.firstChild<SpriteComponent>()!.getOpacity(), equals(1));
game.world.joints.whereType<RevoluteJoint>().single, expect(ball.body.linearVelocity, equals(Vector2(-50, 0)));
isNotNull, },
); );
},
);
group('calls', () {
flameTester.test( flameTester.test(
'onSpit the next time the mouth opens and status is chomping', 'calls onSpit',
(game) async { (game) async {
final ball = Ball(baseColor: Colors.red); final ball = Ball(baseColor: Colors.red);
final behavior = ChromeDinoSpittingBehavior(); final behavior = ChromeDinoSpittingBehavior();

Loading…
Cancel
Save