Files
BlockSeasons/test/ui/board_geometry_test.dart
T
airkjw 3138fc4b08 Add playable core UI: board painter, drag-and-drop, HUD, result overlay
CustomPainter board with gems/ghost/clear-flash, finger-lifted drag
with snap preview, combo text effect, HUD chips, phase overlays with
rescue stubs, demo stage. E2E widget test drives a real drag gesture.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 13:19:34 +09:00

47 lines
1.5 KiB
Dart

import 'package:block_seasons/game/models/piece_library.dart';
import 'package:block_seasons/ui/widgets/board_geometry.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
const geo = BoardGeometry(boardSize: 320); // cell = 40
group('cellAt', () {
test('maps points inside cells', () {
expect(geo.cellAt(const Offset(5, 5)), (0, 0));
expect(geo.cellAt(const Offset(60, 100)), (1, 2));
expect(geo.cellAt(const Offset(319, 319)), (7, 7));
});
test('returns null outside the board', () {
expect(geo.cellAt(const Offset(-1, 10)), isNull);
expect(geo.cellAt(const Offset(10, 321)), isNull);
});
});
group('cellRect', () {
test('returns the drawn rect for a cell', () {
final rect = geo.cellRect(2, 3);
expect(rect.left, 80);
expect(rect.top, 120);
expect(rect.width, 40);
expect(rect.height, 40);
});
});
group('snapAnchor', () {
final mono = PieceLibrary.byId('mono');
final line5h = PieceLibrary.byId('line5_h');
test('rounds to the nearest cell', () {
expect(geo.snapAnchor(mono, const Offset(78, 122)), (2, 3));
expect(geo.snapAnchor(mono, const Offset(99, 99)), (2, 2));
});
test('clamps so the piece bounding box stays on the board', () {
// line5_h is 5 wide: anchor x can be at most 3.
expect(geo.snapAnchor(line5h, const Offset(310, 0)), (3, 0));
expect(geo.snapAnchor(line5h, const Offset(-50, -50)), (0, 0));
});
});
}