Files
logic-puzzle/integration_test/halloween_test.dart
T
Hadrian Burkhardt 0718e3f252 Open Lumen on a responsive bookshelf and land pending story work
- Start the app on a shelf of every installed book instead of the last
  book's home. Cards show the cover, translated metadata, available
  languages, restored patterns and either "Continue reading" or a way in.
- Keep each book's saved route: the shelf is never written to
  flutter_screen, so choosing a book resumes its own leaf.
- Lay the shelf out responsively: dense single-column cards on phones,
  a two-column grid from 720 logical pixels, a centred 860 px column on
  tablets and a chevron that exists in the bundled handwriting font.
- Keep Settings reachable from the shelf and let the home page's story
  library button open the shelf instead of a dialog.
- Add tool/shelf_screenshots_test.dart, which renders the shelf at phone
  and tablet metrics, checks that every card and Settings stay reachable
  without overflow, and writes artifacts/library/shelf-*.png.
- Commit the pending Midnight Invitation package (campaign, notebook,
  narration and artwork), cast drama and ambience tooling, region
  selection, phone/tablet integration coverage and related docs.

flutter analyze is clean and all 74 widget/domain tests pass.
2026-11-05 14:29:50 +01:00

176 lines
7.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
import 'package:lumen/domain/book.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/narrator.dart';
import 'package:lumen/services/progress.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets(
'complete Halloween story, twelve discoveries and all native recordings',
(tester) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
Future<void> orient(DeviceOrientation orientation) async {
await SystemChrome.setPreferredOrientations([orientation]);
final portrait = orientation == DeviceOrientation.portraitUp;
for (var i = 0; i < 30; i++) {
await tester.pump(const Duration(milliseconds: 100));
final size = tester.view.physicalSize;
if ((size.height > size.width) == portrait) {
await tester.pumpAndSettle();
return;
}
}
fail('Device did not enter $orientation');
}
await orient(DeviceOrientation.portraitUp);
final library = await StoryLibrary.load();
final mara = await library.open('mara-island');
final store = Progress.memory({'language': 'en'});
final g = Game(mara, store, library: library);
final voice = Narrator(mara.tracks);
await tester.pumpWidget(
MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(fontFamily: 'MaraHand'),
home: Notebook(game: g, adsEnabled: false, narrator: voice),
),
);
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> tap(String text) async {
final f = find.text(text);
await tester.ensureVisible(f);
await tester.pumpAndSettle();
await tester.tap(f);
await tester.pumpAndSettle();
}
Future<void> shot(String name) async {
await tester.pumpAndSettle();
await binding.takeScreenshot(name);
}
await tap('Story library');
await tap('The Midnight Invitation');
expect(g.book.id, 'midnight-invitation');
await shot('halloween-00-cover');
await tap('Open The Midnight Invitation · 0 / 12');
expect(g.storyPage.id, 'midnight.opening');
await voice.stop();
await tester.pumpAndSettle();
await shot('halloween-01-opening');
// The actual on-page controls must play, pause and resume a native WAV.
await tester.ensureVisible(find.text('Play this reading'));
await tester.tap(find.text('Play this reading'));
await Future<void>.delayed(const Duration(seconds: 2));
await tester.pumpAndSettle();
expect(voice.error, isEmpty);
expect(voice.playing, true);
await tester.ensureVisible(find.text('Pause recording'));
await tester.tap(find.text('Pause recording'));
await tester.pumpAndSettle();
final paused = voice.position;
expect(paused.inMilliseconds, greaterThan(500));
await tester.tap(find.text('Resume recording'));
await Future<void>.delayed(const Duration(seconds: 1));
await voice.pause();
expect(voice.position, greaterThan(paused));
await voice.stop();
// Decode every new bundled recording on the tablet, not just its metadata.
for (final id in g.book.tracks.keys) {
await voice.toggle(id, 1);
await Future<void>.delayed(const Duration(milliseconds: 350));
await voice.pause();
expect(voice.error, isEmpty, reason: id);
expect(voice.position.inMilliseconds, greaterThan(100), reason: id);
await voice.stop();
}
final book = g.book;
for (var index = 0; index < book.levels.length; index++) {
g.showStory(book.pageFor(index, StoryPageType.entry));
await tester.pumpAndSettle();
await tap('Next leaf →');
expect(g.storyPage.type, StoryPageType.puzzle);
final p = g.puzzle!;
expect(find.text('Undo a mark'), findsNothing);
expect(find.image(AssetImage(book.paperAsset!)), findsOneWidget);
if (index == 2) {
await tester.ensureVisible(find.byKey(const ValueKey('area-1')));
await tester.tap(find.byKey(const ValueKey('area-1')));
await tester.pumpAndSettle();
expect(g.selectedArea, 1);
await shot('halloween-region-selected-landscape');
await orient(DeviceOrientation.portraitUp);
await tester.ensureVisible(
find.byKey(const ValueKey('selected-region-outline')),
);
await shot('halloween-region-selected-portrait');
await orient(DeviceOrientation.landscapeLeft);
}
if (index == 0) {
final cell = p.given.indexOf(false);
await tester.ensureVisible(find.byKey(ValueKey('cell-$cell')));
await tester.tap(find.byKey(ValueKey('cell-$cell')));
await tester.pumpAndSettle();
final marks = List<int>.of(g.cells);
await tap('Next leaf →');
await tap('Read ahead');
expect(g.recoveredCount, 0);
expect(
find.image(AssetImage(book.levels[0].illustrationAsset!)),
findsNothing,
);
await tap('← Previous leaf');
expect(g.cells, marks);
await orient(DeviceOrientation.landscapeLeft);
await shot('halloween-02-puzzle-landscape');
}
for (var c = 0; c < g.cells.length; c++) {
while (g.cells[c] != (p.solution[c] == 1 ? 1 : 2)) {
g.mark(c);
}
}
await tester.pumpAndSettle();
expect(g.storyPage.type, StoryPageType.memory);
expect(g.recoveredCount, index + 1);
expect(g.solved, index + 1);
expect(
find.image(AssetImage(book.levels[index].illustrationAsset!)),
findsOneWidget,
);
if ([0, 5, 8, 11].contains(index)) {
await shot('halloween-discovery-$index');
}
expect(tester.takeException(), isNull);
}
await tap('Next leaf →');
expect(g.storyPage.id, 'midnight.ending');
await shot('halloween-03-ending');
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
g.openNotebook();
await tester.pumpAndSettle();
final restarted = Game(book, Progress.memory(store.snapshot));
await restarted.restore();
expect(restarted.storyPage.id, 'midnight.ending');
expect(restarted.recoveredCount, 12);
expect(restarted.progress.text('notebook_last_page'), 'midnight.ending');
await tap('Back to contents');
expect(g.screen, Screen.contents);
await shot('halloween-04-completed-contents');
expect(g.recoveredCount, 12);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await SystemChrome.setPreferredOrientations([]);
},
);
}