mirror of
https://github.com/chenasraf/flame_ui.git
synced 2026-05-18 01:39:01 +00:00
130 lines
3.1 KiB
Dart
130 lines
3.1 KiB
Dart
import 'package:flame/components.dart';
|
|
import 'package:flame/game.dart';
|
|
import 'package:flame_test/flame_test.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
|
|
import 'package:flame_ui/flame_ui.dart';
|
|
|
|
void main() {
|
|
group('TimePickerComponent', () {
|
|
testWithFlameGame('stores initial hour and minute', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 14,
|
|
minute: 30,
|
|
onChanged: (_) {},
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.hour, 14);
|
|
expect(picker.minute, 30);
|
|
});
|
|
|
|
testWithFlameGame('defaults size to 60x36', (game) async {
|
|
final picker = TimePickerComponent(hour: 0, minute: 0, onChanged: (_) {});
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.size, Vector2(60, 36));
|
|
});
|
|
|
|
testWithFlameGame('uses custom size', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 0,
|
|
minute: 0,
|
|
onChanged: (_) {},
|
|
size: Vector2(120, 80),
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.size, Vector2(120, 80));
|
|
});
|
|
|
|
testWithFlameGame('hour setter updates value', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 10,
|
|
minute: 0,
|
|
onChanged: (_) {},
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
picker.hour = 22;
|
|
expect(picker.hour, 22);
|
|
});
|
|
|
|
testWithFlameGame('minute setter updates value', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 0,
|
|
minute: 15,
|
|
onChanged: (_) {},
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
picker.minute = 45;
|
|
expect(picker.minute, 45);
|
|
});
|
|
|
|
testWithFlameGame('default minuteStep is 15', (game) async {
|
|
final picker = TimePickerComponent(hour: 0, minute: 0, onChanged: (_) {});
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.minuteStep, 15);
|
|
});
|
|
|
|
testWithFlameGame('custom minuteStep is stored', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 0,
|
|
minute: 0,
|
|
onChanged: (_) {},
|
|
minuteStep: 5,
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.minuteStep, 5);
|
|
});
|
|
|
|
testWithFlameGame('creates two scroll column children on load', (
|
|
game,
|
|
) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 8,
|
|
minute: 30,
|
|
onChanged: (_) {},
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
// Should have 2 _ScrollColumn children
|
|
final positionChildren =
|
|
picker.children.whereType<PositionComponent>().toList();
|
|
expect(positionChildren.length, 2);
|
|
});
|
|
|
|
testWithFlameGame('position defaults to zero', (game) async {
|
|
final picker = TimePickerComponent(hour: 0, minute: 0, onChanged: (_) {});
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.position, Vector2.zero());
|
|
});
|
|
|
|
testWithFlameGame('uses custom position', (game) async {
|
|
final picker = TimePickerComponent(
|
|
hour: 0,
|
|
minute: 0,
|
|
onChanged: (_) {},
|
|
position: Vector2(50, 100),
|
|
);
|
|
|
|
await game.ensureAdd(picker);
|
|
|
|
expect(picker.position, Vector2(50, 100));
|
|
});
|
|
});
|
|
}
|