Files
logic-puzzle/integration_test/notebook_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

219 lines
7.9 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/main.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/services/progress.dart';
import 'package:lumen/services/narrator.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('six leaves, recorded audio, discoveries and puzzle completion', (
tester,
) async {
expect(
const bool.fromEnvironment('QA_TEST'),
true,
reason: 'Run only with the QA flavor and QA_TEST=true',
);
final book = await Book.load(),
store = Progress.memory(),
g = Game(book, store);
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> shot(String name) async {
await tester.pumpAndSettle();
await binding.takeScreenshot(name);
}
Future<void> tap(String text) async {
final f = find.text(text);
await tester.ensureVisible(f);
await tester.tap(f);
await tester.pumpAndSettle();
}
await shot('00-home');
await tap('Open Mara’s notebook · 0 / 12');
expect(g.storyIndex, 0);
await shot('01-dedication');
final width = tester.view.physicalSize.width / tester.view.devicePixelRatio;
await tester.dragFrom(Offset(width - 12, 300), const Offset(-180, 0));
await tester.pumpAndSettle();
expect(g.storyIndex, 1);
// A normal swipe over the writing must work, not just the edge.
await tester.drag(find.text('By the cottage window'), const Offset(170, 0));
await tester.pumpAndSettle();
expect(g.storyIndex, 0);
await tester.drag(
find.text('For you, when you are ready'),
const Offset(-170, 0),
);
await tester.pumpAndSettle();
expect(g.storyIndex, 1);
expect(
tester
.getBottomRight(find.text('A recorded reading, kept with this page'))
.dy,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
);
await shot('02-cottage');
// Actual native WAV playback, all five files. Position must survive pause/resume.
final narrator = Narrator(book.tracks);
for (final id in book.tracks.keys) {
await narrator.toggle(id, 1);
await Future<void>.delayed(const Duration(seconds: 2));
await narrator.pause();
expect(narrator.error, isEmpty, reason: id);
expect(narrator.position.inMilliseconds, greaterThan(600), reason: id);
final paused = narrator.position;
await Future<void>.delayed(const Duration(milliseconds: 350));
expect((narrator.position - paused).inMilliseconds.abs(), lessThan(200));
await narrator.toggle(id, 1);
await Future<void>.delayed(const Duration(seconds: 1));
await narrator.pause();
expect(narrator.position, greaterThan(paused));
await narrator.stop();
}
narrator.dispose();
await tap('Next leaf →');
expect(g.storyIndex, 2);
expect(
tester.getBottomRight(find.text('Hint · free')).dy,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
);
await shot('03-puzzle');
final before = List.of(g.cells);
await tester.drag(
find.byKey(const ValueKey('cell-20')),
const Offset(65, 0),
);
await tester.pumpAndSettle();
expect(g.storyIndex, 2);
await tester.tap(find.byKey(const ValueKey('cell-0')));
await tester.pumpAndSettle();
expect(g.cells[0], 1);
await tester.tap(find.byKey(const ValueKey('cell-1')));
await tester.pump();
await tester.tap(find.byKey(const ValueKey('cell-1')));
await tester.pumpAndSettle();
expect(g.cells[1], 2);
await shot('03-pencil-marks');
await tap('Undo a mark');
await tap('Undo a mark');
await tap('Undo a mark');
expect(g.cells, before);
await tap('Next leaf →');
await tap('Read ahead');
expect(g.solved, 0);
expect(g.storyIndex, 3);
await shot('04-memory');
await tap('Next leaf →');
await shot('05-folded-note');
await tap('Unfold Gran’s note');
expect(store.flag('notebook_note_open'), true);
await shot('05-open-note');
await tap('Bookmark');
await tap('Next leaf →');
await shot('06-lantern');
await tester.tap(
find.bySemanticsLabel(
'Watercolour of Mara’s blue storm lantern. Tap to examine the repaired handle.',
),
);
await tester.pumpAndSettle();
await tap('Keep that thought');
expect(store.flag('notebook_handle_seen'), true);
await tap('Contents');
await tap('Return to my ribbon bookmark');
expect(g.storyIndex, 4);
final restarted = Game(book, Progress.memory(store.snapshot));
await restarted.restore();
expect(restarted.storyIndex, 4);
expect(restarted.progress.flag('notebook_note_open'), true);
g.showStory(2);
await tester.pumpAndSettle();
final p = g.puzzle!;
for (var i = 0; i < 49; i++) {
while (g.cells[i] != (p.solution[i] == 1 ? 1 : 2)) {
await tester.tap(find.byKey(ValueKey('cell-$i')));
await tester.pump();
}
}
await tester.pumpAndSettle();
expect(g.storyIndex, 3);
expect(g.solved, 1);
g.showStory(2);
g.check();
expect(g.solved, 1);
g.showStory(5);
await tester.pumpAndSettle();
await tap('Follow the lantern into the next entry →');
expect(g.screen, Screen.briefing);
await tap('Restore the pattern →');
expect(g.screen, Screen.game);
final lantern = g.puzzle!;
for (var i = 0; i < 49; i++) {
while (g.cells[i] != (lantern.solution[i] == 1 ? 1 : 2)) {
g.mark(i);
}
}
await tester.pumpAndSettle();
expect(g.screen, Screen.reveal);
expect(g.solved, 2);
await shot('07-campaign-reveal');
// The later campaign leaves need swipes too, including read-ahead.
Future<void> swipeWriting(String text, double dx) async {
final target = find.text(text);
await tester.ensureVisible(target);
await tester.drag(target, Offset(dx, 0));
await tester.pumpAndSettle();
}
await swipeWriting('The lantern', 170);
expect(g.screen, Screen.briefing);
await swipeWriting('Something to carry the flame', -170);
expect(g.screen, Screen.reveal);
await swipeWriting('The lantern', -170);
expect(g.screen, Screen.briefing);
expect(g.campaignIndex, 2);
await swipeWriting('Under the loose floorboard', -170);
expect(g.screen, Screen.game);
await tester.ensureVisible(find.byKey(const ValueKey('cell-0')));
await tester.tap(find.byKey(const ValueKey('cell-0')));
await tester.pumpAndSettle();
final keyMarks = List<int>.of(g.cells);
await swipeWriting('Under the loose floorboard', -170);
await tap('Keep solving');
expect(g.screen, Screen.game);
await swipeWriting('Under the loose floorboard', -170);
await tap('Read ahead');
expect(g.screen, Screen.reveal);
expect(g.recovered(2), false);
expect(g.solved, 2);
await shot('08-campaign-read-ahead');
await swipeWriting('The brass key', -170);
expect(g.screen, Screen.briefing);
expect(g.campaignIndex, 3);
await swipeWriting('A direction in the dark', 170);
expect(g.screen, Screen.reveal);
expect(g.campaignIndex, 2);
await swipeWriting('The brass key', 170);
expect(g.screen, Screen.briefing);
await swipeWriting('Under the loose floorboard', -170);
expect(g.screen, Screen.game);
expect(g.cells, keyMarks);
expect(g.solved, 2);
// Exercise real plugin persistence without touching main-app data.
final disk = await Progress.load();
await disk.set('qa_roundtrip', 'notebook-and-audio');
await disk.flushed;
expect((await Progress.load()).text('qa_roundtrip'), 'notebook-and-audio');
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
});
}