Complete cottage notebook with narration and discovery-only artwork

This commit is contained in:
Hadrian Burkhardt
2026-11-01 00:18:34 +01:00
parent 36fbbce6ef
commit 6bd14a9e20
90 changed files with 2394 additions and 221 deletions
+191
View File
@@ -0,0 +1,191 @@
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/main.dart';
import 'package:lumen/services/progress.dart';
import 'package:lumen/services/narrator.dart';
void main() {
final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized();
testWidgets('complete cottage chapter, bookmarks and larger-text rotation', (
tester,
) async {
expect(const bool.fromEnvironment('QA_TEST'), true);
final book = await Book.load();
final game = Game(book, Progress.memory());
final voice = Narrator(book.tracks);
for (final id in book.tracks.keys.where(
(id) => book.tracks[id]['speaker'] == 'Narrator',
)) {
await voice.toggle(id, 1);
await Future<void>.delayed(const Duration(milliseconds: 900));
await voice.pause();
expect(voice.error, isEmpty, reason: id);
expect(voice.position.inMilliseconds, greaterThan(200), reason: id);
await voice.stop();
}
voice.dispose();
addTearDown(() => SystemChrome.setPreferredOrientations([]));
await SystemChrome.setPreferredOrientations([DeviceOrientation.portraitUp]);
game.showStory(0);
await tester.pumpWidget(
MaterialApp(
theme: ThemeData(fontFamily: 'MaraHand'),
home: Builder(
builder: (context) => MediaQuery(
data: MediaQuery.of(context)
.copyWith(textScaler: const TextScaler.linear(1.5)),
child: Notebook(game: game, adsEnabled: false),
),
),
),
);
await tester.pumpAndSettle();
await binding.convertFlutterSurfaceToImage();
Future<void> tap(String label) async {
await tester.ensureVisible(find.text(label));
await tester.pumpAndSettle();
await tester.tap(find.text(label));
await tester.pumpAndSettle();
}
for (var i = 0; i < book.pages.length; i++) {
expect(game.storyIndex, i);
final page = book.pages[i];
if (page.campaignIndex case final index?) {
expect(
find.image(AssetImage(book.levels[index].illustrationAsset!)),
findsNothing,
);
}
if (page.speaker == 'Narrator') {
expect(find.text('Narrator · recorded story'), findsOneWidget);
}
if (page.type == StoryPageType.puzzle) {
final cell = game.puzzle!.given.indexOf(false);
final target = find.byKey(ValueKey('cell-$cell'));
await tester.ensureVisible(target);
await tester.pumpAndSettle();
await tester.tap(target);
await tester.pumpAndSettle();
final marks = List<int>.of(game.cells);
await tap('Bookmark');
final savedId = game.progress.text('notebook_manual_bookmark');
expect(savedId, page.id);
final restored = Game(book, Progress.memory(game.progress.snapshot));
await restored.restore();
expect(restored.storyPage.id, page.id);
expect(restored.cells, marks);
}
if ([6, 10, 14, 15].contains(i)) {
await tester.ensureVisible(find.text(page.title));
await tester.pumpAndSettle();
await binding.takeScreenshot('cottage-$i-portrait');
}
expect(tester.takeException(), isNull, reason: page.id);
await tap(
i == book.pages.length - 1 ? 'Across the tide →' : 'Next leaf →',
);
if (page.type == StoryPageType.puzzle) await tap('Read ahead');
expect(game.solved, 0);
}
expect(game.screen, Screen.briefing);
expect(game.campaignIndex, 4);
await tester.drag(find.text('At the water’s edge'), const Offset(170, 0));
await tester.pumpAndSettle();
expect(game.storyPage.type, StoryPageType.closing);
expect(game.screen, Screen.story);
game.contents(0);
await tester.pumpAndSettle();
await binding.takeScreenshot('cottage-contents-portrait');
await tap('Return to my ribbon bookmark');
expect(game.storyPage.id, 'cottage.compass.puzzle');
final marks = List<int>.of(game.cells);
await SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeLeft,
]);
for (
var attempt = 0;
attempt < 20 &&
tester.view.physicalSize.width < tester.view.physicalSize.height;
attempt++
) {
await tester.pump(const Duration(milliseconds: 100));
}
await tester.pumpAndSettle();
expect(
tester.view.physicalSize.width,
greaterThan(tester.view.physicalSize.height),
);
expect(game.cells, marks);
await tester.ensureVisible(find.text('Hint · free'));
await tester.pumpAndSettle();
expect(find.text('Hint · free').hitTestable(), findsOneWidget);
final lastCell = tester.getRect(find.byKey(const ValueKey('cell-48')));
expect(
lastCell.bottom,
lessThan(tester.getTopLeft(find.text('Contents')).dy),
);
await binding.takeScreenshot('cottage-compass-landscape');
for (var i = 0; i < 4; i++) {
game.showStory(book.pageFor(i, StoryPageType.puzzle));
final solution = List<int>.of(game.puzzle!.solution);
for (var c = 0; c < solution.length; c++) {
while (game.cells[c] != (solution[c] == 1 ? 1 : 2)) {
game.mark(c);
}
}
expect(game.storyPage.type, StoryPageType.memory);
expect(game.campaignIndex, i);
expect(game.solved, i + 1);
await tester.pumpAndSettle();
expect(
find.image(AssetImage(book.levels[i].illustrationAsset!)),
findsOneWidget,
);
game.showStory(book.pageFor(i, StoryPageType.puzzle));
game.check();
expect(game.solved, i + 1);
}
for (final index in [5, 6, 9, 12, 15]) {
game.showStory(index);
await tester.pumpAndSettle();
for (final level in book.levels) {
expect(
find.image(AssetImage(level.illustrationAsset!)),
findsNothing,
reason:
'Completed progress must not reveal art on ${game.storyPage.id}',
);
}
}
game.showStory(6);
await tester.pumpAndSettle();
await binding.takeScreenshot('cottage-revisit-entry-landscape');
game.showStory(8);
await tester.pumpAndSettle();
expect(
find.image(AssetImage(book.levels[1].illustrationAsset!)),
findsOneWidget,
);
await binding.takeScreenshot('cottage-discovery-landscape');
game.contents(0);
await tester.pumpAndSettle();
final disk = await Progress.load();
for (final entry in game.progress.snapshot.entries) {
await disk.set(entry.key, entry.value);
}
await disk.flushed;
final restarted = Game(book, await Progress.load());
await restarted.restore();
expect(restarted.screen, Screen.contents);
expect(restarted.contentsChapter, 0);
expect(restarted.solved, 4);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
await tester.pumpAndSettle();
});
}
+12 -2
View File
@@ -19,7 +19,13 @@ void main() {
// in reportData at once exhausts the tablet when the driver encodes JSON.
const chapter = int.fromEnvironment('ART_CHAPTER', defaultValue: 0);
expect(chapter, inInclusiveRange(0, 2));
final game = Game(book, Progress.memory({'story_access_level': 11}));
final game = Game(
book,
Progress.memory({
'story_access_level': 11,
for (var i = 0; i < 12; i++) 'done_story_v1_$i': true,
}),
);
addTearDown(() => SystemChrome.setPreferredOrientations([]));
await binding.convertFlutterSurfaceToImage();
for (final orientation in [
@@ -54,7 +60,11 @@ void main() {
'discovery-$index-${orientation.name}-art',
);
final next = find.text(
index == 11 ? 'Return to the notebook' : 'Turn the page →',
index < 4
? 'Next leaf →'
: index == 11
? 'Return to the notebook'
: 'Turn the page →',
);
await tester.ensureVisible(next);
await tester.pumpAndSettle();
+25 -27
View File
@@ -118,14 +118,13 @@ void main() {
await tap('Bookmark');
await tap('Next leaf →');
await shot('06-lantern');
await tester.tap(
expect(
find.bySemanticsLabel(
'Watercolour of Mara’s blue storm lantern. Tap to examine the repaired handle.',
),
findsNothing,
);
await tester.pumpAndSettle();
await tap('Keep that thought');
expect(store.flag('notebook_handle_seen'), true);
expect(store.flag('notebook_handle_seen'), false);
await tap('Contents');
await tap('Return to my ribbon bookmark');
expect(g.storyIndex, 4);
@@ -151,9 +150,9 @@ void main() {
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);
expect(g.storyIndex, 6);
await tap('Turn to the pattern →');
expect(g.storyIndex, 7);
final lantern = g.puzzle!;
for (var i = 0; i < 49; i++) {
while (g.cells[i] != (lantern.solution[i] == 1 ? 1 : 2)) {
@@ -161,9 +160,17 @@ void main() {
}
}
await tester.pumpAndSettle();
expect(g.screen, Screen.reveal);
expect(g.storyIndex, 8);
expect(g.solved, 2);
await shot('07-campaign-reveal');
g.showStory(5);
await tester.pumpAndSettle();
await tap('Read Gran’s margin note');
await tap('Keep that thought');
expect(store.flag('notebook_handle_seen'), true);
g.showStory(8);
await tester.pumpAndSettle();
// The later campaign leaves need swipes too, including read-ahead.
Future<void> swipeWriting(String text, double dx) async {
final target = find.text(text);
@@ -172,38 +179,29 @@ void main() {
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('A light at the door', -170);
expect(g.storyIndex, 9);
await swipeWriting('Under the loose floorboard', -170);
expect(g.screen, Screen.game);
expect(g.storyIndex, 10);
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);
expect(g.storyIndex, 10);
await swipeWriting('Under the loose floorboard', -170);
await tap('Read ahead');
expect(g.screen, Screen.reveal);
expect(g.storyIndex, 11);
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 journey kept ready', -170);
expect(g.storyIndex, 12);
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.storyIndex, 11);
await swipeWriting('A journey kept ready', 170);
expect(g.storyIndex, 10);
expect(g.cells, keyMarks);
expect(g.solved, 2);
// Exercise real plugin persistence without touching main-app data.