Files
logic-puzzle/test/widget_test.dart
T
Hadrian Burkhardt a863b0ca93 Rearrange landscape puzzle layout
Landscape leaves now lay the puzzle out in two columns: the whole grid
keeps one column (square, sized to the page) with the heading, area
totals, hint/undo and notes beside it, and the leaf navigation folds
into a single row. The game leaf also keeps its actions in a compact
bottom bar, so the board and controls are visible without scrolling.

- Leaf gains an optional wideBody used on landscape pages.
- Board gains maxWidth, defaulting to the previous 350.
- Split the puzzle body into area, board and note builders so both
  layouts share the same controls.
- Add a landscape widget regression test and document the layout.

This snapshot also carries the pending 2.0.2 notebook work already in
the tree: read-ahead restore, bundled PCM WAV narration assets, the
audio consistency comment, version 2.0.2+11, and the related unit,
integration and script updates.
2026-10-31 06:21:36 +01:00

216 lines
7.2 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/puzzle.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/progress.dart';
import 'package:lumen/ui/board.dart';
import 'package:lumen/ui/paper.dart';
void main() {
testWidgets('page margins turn leaves; grid drags never turn', (
tester,
) async {
tester.view.reset();
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var turns = 0, marks = 0;
final p = Puzzle(7, List.filled(49, 0));
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Paper(
onTurn: (d) => turns += d,
child: Board(
puzzle: p,
cells: List.filled(49, 0),
onMark: (_) => marks++,
),
),
),
),
);
await tester.pumpAndSettle();
await tester.dragFrom(const Offset(585, 400), const Offset(-180, 0));
await tester.pumpAndSettle();
expect(turns, 1);
await tester.drag(
find.byKey(const ValueKey('cell-20')),
const Offset(70, 0),
);
await tester.pumpAndSettle();
expect(turns, 1);
await tester.tap(find.byKey(const ValueKey('cell-20')));
expect(marks, 1);
expect(tester.takeException(), isNull);
});
testWidgets(
'reading swipes turn both ways; controls, scrolling and cancelled drags do not',
(tester) async {
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
var turns = 0, plays = 0;
final scroll = ScrollController();
addTearDown(scroll.dispose);
await tester.pumpWidget(
MaterialApp(
home: Scaffold(
body: Paper(
onTurn: (direction) => turns += direction,
child: Column(
children: [
Expanded(
child: SingleChildScrollView(
controller: scroll,
child: Column(
children: [
SizedBox(
key: const ValueKey('reading-zone'),
height: 130,
width: double.infinity,
child: writing(
'My dear, take your time with these pages.',
),
),
SizedBox(
key: const ValueKey('blank-zone'),
height: 100,
width: double.infinity,
),
for (var i = 0; i < 12; i++)
SizedBox(
height: 80,
child: writing('A remembered passage $i.'),
),
],
),
),
),
InkButton('Play this reading', () => plays++),
],
),
),
),
),
);
await tester.pumpAndSettle();
await tester.drag(
find.byKey(const ValueKey('reading-zone')),
const Offset(-150, 0),
);
await tester.pumpAndSettle();
expect(turns, 1);
await tester.dragFrom(
tester.getCenter(find.byKey(const ValueKey('blank-zone'))),
const Offset(150, 0),
);
await tester.pumpAndSettle();
expect(turns, 0);
await tester.drag(find.text('Play this reading'), const Offset(-120, 0));
await tester.pumpAndSettle();
expect(turns, 0);
expect(plays, 0);
await tester.tap(find.text('Play this reading'));
expect(plays, 1);
await tester.drag(
find.byKey(const ValueKey('reading-zone')),
const Offset(-30, 0),
);
await tester.pumpAndSettle();
expect(turns, 0);
final drag = await tester.startGesture(
tester.getCenter(find.byKey(const ValueKey('reading-zone'))),
);
await drag.moveBy(const Offset(-140, 0));
await drag.cancel();
await tester.pumpAndSettle();
expect(turns, 0);
await tester.drag(
find.byKey(const ValueKey('reading-zone')),
const Offset(0, -200),
);
await tester.pumpAndSettle();
expect(scroll.offset, greaterThan(0));
expect(turns, 0);
expect(tester.takeException(), isNull);
},
);
testWidgets('paper supports small and landscape viewports and larger text', (
tester,
) async {
addTearDown(tester.view.reset);
for (final size in [const Size(360, 640), const Size(960, 600)]) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
await tester.pumpWidget(
MaterialApp(
home: MediaQuery(
data: MediaQueryData(
size: size,
textScaler: const TextScaler.linear(1.5),
),
child: Scaffold(
body: Leaf(
body: Column(
children: [
writing('For you, when you are ready', size: 31),
writing('A remembered passage. ' * 40),
],
),
footer: InkButton('Next leaf', () {}),
),
),
),
),
);
await tester.pumpAndSettle();
expect(find.text('Next leaf'), findsOneWidget);
expect(tester.takeException(), isNull);
}
});
testWidgets('landscape pages keep the whole grid beside its notes', (
tester,
) async {
const width = 960.0, height = 600.0;
tester.view.physicalSize = const Size(width, height);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final book = await Book.load();
final game = Game(book, Progress.memory());
game.startCampaign(0);
await tester.pumpWidget(LumenApp(game: game, adsEnabled: false));
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
// The campaign leaf gives the board its own column, with the heading and
// controls beside it rather than above the fold.
final lastCell = tester.getRect(find.byKey(const ValueKey('cell-48')));
expect(lastCell.bottom, lessThan(height * .94));
expect(
tester.getTopLeft(find.text('A spark in the drawer')).dx,
greaterThan(lastCell.right),
);
expect(find.text('Hint · free'), findsOneWidget);
expect(find.text('Back to notebook'), findsOneWidget);
expect(tester.takeException(), isNull);
// The opening notebook's puzzle leaf uses the same two columns, with the
// grid on the page and its controls beside it.
game.showStory(2);
await tester.pump();
await tester.pump(const Duration(milliseconds: 100));
final storyLast = tester.getRect(find.byKey(const ValueKey('cell-48')));
expect(storyLast.bottom, lessThan(height * .94));
expect(
tester.getTopLeft(find.text('Hint · free')).dx,
greaterThan(storyLast.right),
);
expect(find.text('Next leaf →'), findsOneWidget);
expect(tester.takeException(), isNull);
});
}