mirror of https://github.com/flutter/pinball.git
parent
83212d91ba
commit
f428cb2def
Before Width: | Height: | Size: 844 KiB |
@ -0,0 +1,76 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame/components.dart';
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/game.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart' as theme;
|
||||
|
||||
import '../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('Backboard', () {
|
||||
final characterIconPath = theme.Assets.images.dash.leaderboardIcon.keyName;
|
||||
final assets = [
|
||||
characterIconPath,
|
||||
Assets.images.backboard.marquee.keyName,
|
||||
Assets.images.backboard.displayDivider.keyName,
|
||||
];
|
||||
final tester = FlameTester(() => EmptyPinballTestGame(assets: assets));
|
||||
|
||||
tester.test(
|
||||
'loads correctly',
|
||||
(game) async {
|
||||
final backboard = Backboard();
|
||||
await game.ensureAdd(backboard);
|
||||
|
||||
expect(game.children, contains(backboard));
|
||||
},
|
||||
);
|
||||
|
||||
group('renders correctly', () {
|
||||
tester.testGameWidget(
|
||||
'empty',
|
||||
setUp: (game, tester) async {
|
||||
await game.images.loadAll(assets);
|
||||
game.camera.zoom = 6;
|
||||
game.camera.followVector2(Vector2(0, -130));
|
||||
await game.ensureAdd(Backboard());
|
||||
await game.ready();
|
||||
await tester.pump();
|
||||
},
|
||||
verify: (game, tester) async {
|
||||
await expectLater(
|
||||
find.byGame<EmptyPinballTestGame>(),
|
||||
matchesGoldenFile('../golden/backboard/empty.png'),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
tester.testGameWidget(
|
||||
'on initialsInput',
|
||||
setUp: (game, tester) async {
|
||||
await game.mounted;
|
||||
await game.images.loadAll(assets);
|
||||
game.camera.zoom = 2;
|
||||
game.camera.followVector2(Vector2.zero());
|
||||
final backboard = Backboard();
|
||||
await game.ensureAdd(backboard);
|
||||
await backboard.initialsInput(
|
||||
score: 1000,
|
||||
characterIconPath: characterIconPath,
|
||||
onSubmit: (_) {},
|
||||
);
|
||||
await tester.pump();
|
||||
},
|
||||
verify: (game, tester) async {
|
||||
await expectLater(
|
||||
find.byGame<EmptyPinballTestGame>(),
|
||||
matchesGoldenFile('../golden/backboard/initials-input.png'),
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
@ -0,0 +1,139 @@
|
||||
// ignore_for_file: cascade_invocations
|
||||
|
||||
import 'package:flame_test/flame_test.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pinball/game/components/backboard/displays/displays.dart';
|
||||
import 'package:pinball_components/pinball_components.dart';
|
||||
import 'package:pinball_theme/pinball_theme.dart' as theme;
|
||||
|
||||
import '../../../../helpers/helpers.dart';
|
||||
|
||||
void main() {
|
||||
group('InitialsInputDisplay', () {
|
||||
final characterIconPath = theme.Assets.images.dash.leaderboardIcon.keyName;
|
||||
final assets = [
|
||||
characterIconPath,
|
||||
Assets.images.backboard.displayDivider.keyName,
|
||||
];
|
||||
final tester = FlameTester(() => EmptyPinballTestGame(assets: assets));
|
||||
|
||||
tester.testGameWidget(
|
||||
'changes the initials with arrow keys',
|
||||
setUp: (game, tester) async {
|
||||
final initialsInputDisplay = InitialsInputDisplay(
|
||||
score: 1000,
|
||||
characterIconPath: characterIconPath,
|
||||
onSubmit: (_) {},
|
||||
);
|
||||
await game.ensureAdd(initialsInputDisplay);
|
||||
|
||||
// Focus is already on the first letter
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
await tester.pump();
|
||||
|
||||
// Move to the next an press up again
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
await tester.pump();
|
||||
|
||||
// One more time
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowRight);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
await tester.pump();
|
||||
|
||||
// Back to the previous and increase one more
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowLeft);
|
||||
await tester.pump();
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
await tester.pump();
|
||||
},
|
||||
verify: (game, tester) async {
|
||||
final initialsInputDisplay =
|
||||
game.descendants().whereType<InitialsInputDisplay>().first;
|
||||
|
||||
expect(initialsInputDisplay.initials, equals('BCB'));
|
||||
},
|
||||
);
|
||||
|
||||
String? submitedInitials;
|
||||
tester.testGameWidget(
|
||||
'enter submits the initials',
|
||||
setUp: (game, tester) async {
|
||||
final initialsInputDisplay = InitialsInputDisplay(
|
||||
score: 1000,
|
||||
characterIconPath: characterIconPath,
|
||||
onSubmit: (value) {
|
||||
submitedInitials = value;
|
||||
},
|
||||
);
|
||||
await game.ensureAdd(initialsInputDisplay);
|
||||
|
||||
await tester.sendKeyEvent(LogicalKeyboardKey.enter);
|
||||
await tester.pump();
|
||||
},
|
||||
verify: (game, tester) async {
|
||||
expect(submitedInitials, equals('AAA'));
|
||||
},
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
// group('BackboardLetterPrompt', () {
|
||||
// final tester = FlameTester(KeyboardTestGame.new);
|
||||
|
||||
// tester.testGameWidget(
|
||||
// 'cycles the char up and down when it has focus',
|
||||
// setUp: (game, tester) async {
|
||||
// await game.ensureAdd(
|
||||
// BackboardLetterPrompt(hasFocus: true, position: Vector2.zero()),
|
||||
// );
|
||||
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
// await tester.pump();
|
||||
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
// await tester.pump();
|
||||
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
// await tester.pump();
|
||||
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
|
||||
// await tester.pump();
|
||||
// },
|
||||
// verify: (game, tester) async {
|
||||
// final prompt = game.firstChild<BackboardLetterPrompt>();
|
||||
// expect(prompt?.char, equals('C'));
|
||||
// },
|
||||
// );
|
||||
|
||||
// tester.testGameWidget(
|
||||
// "does nothing when it doesn't have focus",
|
||||
// setUp: (game, tester) async {
|
||||
// await game.ensureAdd(
|
||||
// BackboardLetterPrompt(position: Vector2.zero()),
|
||||
// );
|
||||
// await tester.sendKeyEvent(LogicalKeyboardKey.arrowUp);
|
||||
// await tester.pump();
|
||||
// },
|
||||
// verify: (game, tester) async {
|
||||
// final prompt = game.firstChild<BackboardLetterPrompt>();
|
||||
// expect(prompt?.char, equals('A'));
|
||||
// },
|
||||
// );
|
||||
|
||||
// tester.testGameWidget(
|
||||
// 'blinks the prompt when it has the focus',
|
||||
// setUp: (game, tester) async {
|
||||
// await game.ensureAdd(
|
||||
// BackboardLetterPrompt(position: Vector2.zero(), hasFocus: true),
|
||||
// );
|
||||
// },
|
||||
// verify: (game, tester) async {
|
||||
// final underscore = game.descendants().whereType<ShapeComponent>().first;
|
||||
// expect(underscore.paint.color, Colors.white);
|
||||
|
||||
// game.update(2);
|
||||
// expect(underscore.paint.color, Colors.transparent);
|
||||
// },
|
||||
// );
|
||||
// });
|
||||
|
After Width: | Height: | Size: 1.1 MiB |
Loading…
Reference in new issue