mirror of https://github.com/flutter/pinball.git
refactor: renamed `DashNestBumper` to `DashBumper` (#381)
* refactor: renamed DashNestBumper to DashBumper * refactor: PR suggestions * refactor: renamed stories * refactor: renamed test names * test: renamed test name * docs: improved bumper docs * docs: improve docs * refactor: renamed storiespull/394/head
parent
75527d1fe1
commit
fd87afb23b
@ -0,0 +1 @@
|
|||||||
|
export 'dash_bumper_ball_contact_behavior.dart';
|
@ -0,0 +1,17 @@
|
|||||||
|
import 'package:bloc/bloc.dart';
|
||||||
|
|
||||||
|
part 'dash_bumper_state.dart';
|
||||||
|
|
||||||
|
class DashBumperCubit extends Cubit<DashBumperState> {
|
||||||
|
DashBumperCubit() : super(DashBumperState.inactive);
|
||||||
|
|
||||||
|
/// Event added when the bumper contacts with a ball.
|
||||||
|
void onBallContacted() {
|
||||||
|
emit(DashBumperState.active);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Event added when the bumper should return to its initial configuration.
|
||||||
|
void onReset() {
|
||||||
|
emit(DashBumperState.inactive);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
part of 'dash_bumper_cubit.dart';
|
||||||
|
|
||||||
|
/// Indicates the [DashBumperCubit]'s current state.
|
||||||
|
enum DashBumperState {
|
||||||
|
/// A lit up bumper.
|
||||||
|
active,
|
||||||
|
|
||||||
|
/// A dimmed bumper.
|
||||||
|
inactive,
|
||||||
|
}
|
@ -1 +0,0 @@
|
|||||||
export 'dash_nest_bumper_contact_behavior.dart';
|
|
@ -1,17 +0,0 @@
|
|||||||
import 'package:bloc/bloc.dart';
|
|
||||||
|
|
||||||
part 'dash_nest_bumper_state.dart';
|
|
||||||
|
|
||||||
class DashNestBumperCubit extends Cubit<DashNestBumperState> {
|
|
||||||
DashNestBumperCubit() : super(DashNestBumperState.inactive);
|
|
||||||
|
|
||||||
/// Event added when the bumper contacts with a ball.
|
|
||||||
void onBallContacted() {
|
|
||||||
emit(DashNestBumperState.active);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Event added when the bumper should return to its initial configuration.
|
|
||||||
void onReset() {
|
|
||||||
emit(DashNestBumperState.inactive);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
part of 'dash_nest_bumper_cubit.dart';
|
|
||||||
|
|
||||||
/// Indicates the [DashNestBumperCubit]'s current state.
|
|
||||||
enum DashNestBumperState {
|
|
||||||
/// A lit up bumper.
|
|
||||||
active,
|
|
||||||
|
|
||||||
/// A dimmed bumper.
|
|
||||||
inactive,
|
|
||||||
}
|
|
@ -0,0 +1,139 @@
|
|||||||
|
// ignore_for_file: cascade_invocations
|
||||||
|
|
||||||
|
import 'package:bloc_test/bloc_test.dart';
|
||||||
|
import 'package:flame/components.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/bumping_behavior.dart';
|
||||||
|
import 'package:pinball_components/src/components/dash_bumper/behaviors/behaviors.dart';
|
||||||
|
|
||||||
|
import '../../../helpers/helpers.dart';
|
||||||
|
|
||||||
|
class _MockDashBumperCubit extends Mock implements DashBumperCubit {}
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
TestWidgetsFlutterBinding.ensureInitialized();
|
||||||
|
|
||||||
|
group('DashBumper', () {
|
||||||
|
final flameTester = FlameTester(
|
||||||
|
() => TestGame(
|
||||||
|
[
|
||||||
|
Assets.images.dash.bumper.main.active.keyName,
|
||||||
|
Assets.images.dash.bumper.main.inactive.keyName,
|
||||||
|
Assets.images.dash.bumper.a.active.keyName,
|
||||||
|
Assets.images.dash.bumper.a.inactive.keyName,
|
||||||
|
Assets.images.dash.bumper.b.active.keyName,
|
||||||
|
Assets.images.dash.bumper.b.inactive.keyName,
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
flameTester.test('"main" loads correctly', (game) async {
|
||||||
|
final bumper = DashBumper.main();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(game.contains(bumper), isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('"a" loads correctly', (game) async {
|
||||||
|
final bumper = DashBumper.a();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
|
||||||
|
expect(game.contains(bumper), isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('"b" loads correctly', (game) async {
|
||||||
|
final bumper = DashBumper.b();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(game.contains(bumper), isTrue);
|
||||||
|
});
|
||||||
|
|
||||||
|
// ignore: public_member_api_docs
|
||||||
|
flameTester.test('closes bloc when removed', (game) async {
|
||||||
|
final bloc = _MockDashBumperCubit();
|
||||||
|
whenListen(
|
||||||
|
bloc,
|
||||||
|
const Stream<DashBumperState>.empty(),
|
||||||
|
initialState: DashBumperState.inactive,
|
||||||
|
);
|
||||||
|
when(bloc.close).thenAnswer((_) async {});
|
||||||
|
final bumper = DashBumper.test(bloc: bloc);
|
||||||
|
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
game.remove(bumper);
|
||||||
|
await game.ready();
|
||||||
|
|
||||||
|
verify(bloc.close).called(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('adds a bumperBallContactBehavior', (game) async {
|
||||||
|
final bumper = DashBumper.a();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(
|
||||||
|
bumper.children.whereType<DashBumperBallContactBehavior>().single,
|
||||||
|
isNotNull,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
group("'main' adds", () {
|
||||||
|
flameTester.test('new children', (game) async {
|
||||||
|
final component = Component();
|
||||||
|
final bumper = DashBumper.main(
|
||||||
|
children: [component],
|
||||||
|
);
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(bumper.children, contains(component));
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('a BumpingBehavior', (game) async {
|
||||||
|
final bumper = DashBumper.main();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(
|
||||||
|
bumper.children.whereType<BumpingBehavior>().single,
|
||||||
|
isNotNull,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group("'a' adds", () {
|
||||||
|
flameTester.test('new children', (game) async {
|
||||||
|
final component = Component();
|
||||||
|
final bumper = DashBumper.a(
|
||||||
|
children: [component],
|
||||||
|
);
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(bumper.children, contains(component));
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('a BumpingBehavior', (game) async {
|
||||||
|
final bumper = DashBumper.a();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(
|
||||||
|
bumper.children.whereType<BumpingBehavior>().single,
|
||||||
|
isNotNull,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
group("'b' adds", () {
|
||||||
|
flameTester.test('new children', (game) async {
|
||||||
|
final component = Component();
|
||||||
|
final bumper = DashBumper.b(
|
||||||
|
children: [component],
|
||||||
|
);
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(bumper.children, contains(component));
|
||||||
|
});
|
||||||
|
|
||||||
|
flameTester.test('a BumpingBehavior', (game) async {
|
||||||
|
final bumper = DashBumper.b();
|
||||||
|
await game.ensureAdd(bumper);
|
||||||
|
expect(
|
||||||
|
bumper.children.whereType<BumpingBehavior>().single,
|
||||||
|
isNotNull,
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -1,137 +0,0 @@
|
|||||||
// ignore_for_file: cascade_invocations
|
|
||||||
|
|
||||||
import 'package:bloc_test/bloc_test.dart';
|
|
||||||
import 'package:flame/components.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/bumping_behavior.dart';
|
|
||||||
import 'package:pinball_components/src/components/dash_nest_bumper/behaviors/behaviors.dart';
|
|
||||||
|
|
||||||
import '../../../helpers/helpers.dart';
|
|
||||||
|
|
||||||
class _MockDashNestBumperCubit extends Mock implements DashNestBumperCubit {}
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
TestWidgetsFlutterBinding.ensureInitialized();
|
|
||||||
|
|
||||||
group('DashNestBumper', () {
|
|
||||||
final assets = [
|
|
||||||
Assets.images.dash.bumper.main.active.keyName,
|
|
||||||
Assets.images.dash.bumper.main.inactive.keyName,
|
|
||||||
Assets.images.dash.bumper.a.active.keyName,
|
|
||||||
Assets.images.dash.bumper.a.inactive.keyName,
|
|
||||||
Assets.images.dash.bumper.b.active.keyName,
|
|
||||||
Assets.images.dash.bumper.b.inactive.keyName,
|
|
||||||
];
|
|
||||||
final flameTester = FlameTester(() => TestGame(assets));
|
|
||||||
|
|
||||||
flameTester.test('"main" loads correctly', (game) async {
|
|
||||||
final bumper = DashNestBumper.main();
|
|
||||||
await game.ensureAdd(bumper);
|
|
||||||
expect(game.contains(bumper), isTrue);
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('"a" loads correctly', (game) async {
|
|
||||||
final bumper = DashNestBumper.a();
|
|
||||||
await game.ensureAdd(bumper);
|
|
||||||
|
|
||||||
expect(game.contains(bumper), isTrue);
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('"b" loads correctly', (game) async {
|
|
||||||
final bumper = DashNestBumper.b();
|
|
||||||
await game.ensureAdd(bumper);
|
|
||||||
expect(game.contains(bumper), isTrue);
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('closes bloc when removed', (game) async {
|
|
||||||
final bloc = _MockDashNestBumperCubit();
|
|
||||||
whenListen(
|
|
||||||
bloc,
|
|
||||||
const Stream<DashNestBumperState>.empty(),
|
|
||||||
initialState: DashNestBumperState.inactive,
|
|
||||||
);
|
|
||||||
when(bloc.close).thenAnswer((_) async {});
|
|
||||||
final dashNestBumper = DashNestBumper.test(bloc: bloc);
|
|
||||||
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
game.remove(dashNestBumper);
|
|
||||||
await game.ready();
|
|
||||||
|
|
||||||
verify(bloc.close).called(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('adds a DashNestBumperBallContactBehavior', (game) async {
|
|
||||||
final dashNestBumper = DashNestBumper.a();
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(
|
|
||||||
dashNestBumper.children
|
|
||||||
.whereType<DashNestBumperBallContactBehavior>()
|
|
||||||
.single,
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
group("'main' adds", () {
|
|
||||||
flameTester.test('new children', (game) async {
|
|
||||||
final component = Component();
|
|
||||||
final dashNestBumper = DashNestBumper.main(
|
|
||||||
children: [component],
|
|
||||||
);
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(dashNestBumper.children, contains(component));
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('a BumpingBehavior', (game) async {
|
|
||||||
final dashNestBumper = DashNestBumper.main();
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(
|
|
||||||
dashNestBumper.children.whereType<BumpingBehavior>().single,
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group("'a' adds", () {
|
|
||||||
flameTester.test('new children', (game) async {
|
|
||||||
final component = Component();
|
|
||||||
final dashNestBumper = DashNestBumper.a(
|
|
||||||
children: [component],
|
|
||||||
);
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(dashNestBumper.children, contains(component));
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('a BumpingBehavior', (game) async {
|
|
||||||
final dashNestBumper = DashNestBumper.a();
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(
|
|
||||||
dashNestBumper.children.whereType<BumpingBehavior>().single,
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
group("'b' adds", () {
|
|
||||||
flameTester.test('new children', (game) async {
|
|
||||||
final component = Component();
|
|
||||||
final dashNestBumper = DashNestBumper.b(
|
|
||||||
children: [component],
|
|
||||||
);
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(dashNestBumper.children, contains(component));
|
|
||||||
});
|
|
||||||
|
|
||||||
flameTester.test('a BumpingBehavior', (game) async {
|
|
||||||
final dashNestBumper = DashNestBumper.b();
|
|
||||||
await game.ensureAdd(dashNestBumper);
|
|
||||||
expect(
|
|
||||||
dashNestBumper.children.whereType<BumpingBehavior>().single,
|
|
||||||
isNotNull,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
Loading…
Reference in new issue