Files
logic-puzzle/test/library_widget_test.dart
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

225 lines
8.5 KiB
Dart
Raw Permalink 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/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:lumen/domain/game.dart';
import 'package:lumen/domain/library.dart';
import 'package:lumen/main.dart';
import 'package:lumen/services/progress.dart';
import 'package:lumen/services/translation.dart';
import 'package:lumen/ui/translation.dart';
import 'support/story_fixtures.dart';
void main() {
testWidgets(
'library and language controls open a translated story and preserve live marks',
(tester) async {
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
await tester.runAsync(() async {
final font = FontLoader('MaraHand')
..addFont(rootBundle.load('assets/fonts/DancingScript.ttf'));
await font.load();
});
final library = (await tester.runAsync(StoryLibrary.load))!;
for (final story in library.stories) {
for (final language in story.languages.keys) {
await tester.runAsync(
() => library.open(story.id, language: language),
);
}
}
final book = (await tester.runAsync(() => library.open('mara-island')))!;
final g = Game(book, Progress.memory(), library: library);
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
Future<void> tap(String text) async {
await tester.ensureVisible(find.text(text));
await tester.pumpAndSettle();
await tester.tap(find.text(text));
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 20)),
);
await tester.pumpAndSettle();
}
await tap('Story library');
await tap('The paper boat');
expect(g.book.id, 'paper-boat');
expect(find.text('The paper boat').hitTestable(), findsOneWidget);
await tap('Open The paper boat · 0 / 1');
expect(g.storyPage.id, 'boat.entry');
await tap('Next leaf →');
await tester.ensureVisible(find.byKey(const ValueKey('cell-0')));
await tester.tap(find.byKey(const ValueKey('cell-0')));
await tester.pumpAndSettle();
final marks = List<int>.of(g.cells);
expect(find.text('Contents'), findsNothing);
expect(find.text('Bookmark'), findsNothing);
expect(find.text('Language'), findsNothing);
expect(find.text('Close book'), findsNothing);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
await tap('Settings');
await tap('Language');
await tap('Deutsch');
expect(g.book.language, 'de');
expect(g.screen, Screen.home);
g.openNotebook();
await tester.pumpAndSettle();
expect(g.storyPage.id, 'boat.puzzle');
expect(g.cells, marks);
expect(g.canUndo, true);
expect(find.text('Eine kleine Überfahrt'), findsOneWidget);
expect(find.text('Nächste Seite →'), findsOneWidget);
await tester.binding.handlePopRoute();
await tester.pumpAndSettle();
expect(g.screen, Screen.home);
expect(find.text('Einstellungen'), findsOneWidget);
await tap('Geschichtenbibliothek');
expect(g.screen, Screen.library);
expect(find.text('Wähle ein Buch'), findsOneWidget);
expect(find.text('Das Papierboot'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
},
);
testWidgets('the first window is the bookshelf and opens a chosen book', (
tester,
) async {
tester.view.physicalSize = const Size(600, 960);
tester.view.devicePixelRatio = 1;
addTearDown(tester.view.reset);
final library = (await tester.runAsync(StoryLibrary.load))!;
await tester.runAsync(() async {
for (final story in library.stories) {
for (final language in story.languages.keys) {
await library.open(story.id, language: language);
}
}
});
final book = (await tester.runAsync(() => library.open('mara-island')))!;
final g = Game(book, Progress.memory({'language': 'en'}), library: library)
..showLibrary();
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
// The shelf loads books through futures created outside the fake async
// zone, so give the real event loop a turn before checking the cards.
for (var i = 0; i < 3; i++) {
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 20)),
);
await tester.pump();
}
expect(g.screen, Screen.library);
expect(find.byKey(const ValueKey('library')), findsOneWidget);
for (final story in library.stories) {
expect(find.text(story.title), findsOneWidget);
}
expect(find.text('Open this book ›'), findsNWidgets(3));
final boat = find.text('The paper boat');
await tester.ensureVisible(boat);
await tester.pumpAndSettle();
await tester.tap(boat);
await tester.runAsync(
() => Future<void>.delayed(const Duration(milliseconds: 20)),
);
await tester.pumpAndSettle();
expect(g.book.id, 'paper-boat');
expect(g.screen, Screen.home);
expect(find.text('Open The paper boat · 0 / 1'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
});
testWidgets(
'German story pages fit portrait and landscape with larger text',
(tester) async {
addTearDown(tester.view.reset);
tester.platformDispatcher.textScaleFactorTestValue = 1.5;
addTearDown(tester.platformDispatcher.clearTextScaleFactorTestValue);
final library = (await tester.runAsync(StoryLibrary.load))!;
final book = (await tester.runAsync(
() => library.open('paper-boat', language: 'de'),
))!;
for (final size in [const Size(360, 640), const Size(960, 600)]) {
tester.view.physicalSize = size;
tester.view.devicePixelRatio = 1;
final g = Game(
book,
Progress.memory({'language': 'de'}),
library: library,
);
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
for (var i = 0; i < book.pages.length; i++) {
g.showStory(i);
await tester.pumpAndSettle();
expect(find.text('Sprache'), findsNothing);
expect(
find
.text(i == 2 ? 'Zum Inhaltsverzeichnis' : 'Nächste Seite →')
.hitTestable(),
findsOneWidget,
);
expect(tester.takeException(), isNull);
}
g.contents();
await tester.pumpAndSettle();
expect(find.text('Eine kleine Überfahrt'), findsOneWidget);
expect(tester.takeException(), isNull);
await tester.pumpWidget(const SizedBox());
}
},
);
testWidgets('a right-to-left story uses RTL layout and a system font', (
tester,
) async {
final data = fixture();
data['fixture/ar.json'] = {
'title': 'قصة قصيرة',
'pages': {
'entry-0': {'title': 'البداية', 'text': 'تبدأ الرحلة هنا.'},
},
};
final original = definition('arabic');
original.languages['ar'] = {'label': 'العربية', 'asset': 'fixture/ar.json'};
final library = StoryLibrary(
[original],
bundle: FixtureBundle(data),
copy: const TranslationCatalog(
{'en': 'English', 'ar': 'العربية'},
{
'ar': {'Language': 'اللغة'},
},
),
);
final book = (await tester.runAsync(
() => library.open('arabic', language: 'ar'),
))!;
final g = Game(book, Progress.memory({'language': 'ar'}), library: library)
..showStory(0);
await tester.pumpWidget(LumenApp(game: g, adsEnabled: false));
await tester.pumpAndSettle();
final heading = find.text('البداية');
expect(Directionality.of(tester.element(heading)), TextDirection.rtl);
expect(tester.widget<Text>(heading).style?.fontFamily, 'sans-serif');
expect(find.text('اللغة'), findsNothing);
g.startCampaign(0);
await tester.pumpAndSettle();
expect(
tester.getCenter(find.byKey(const ValueKey('cell-0'))).dx,
lessThan(tester.getCenter(find.byKey(const ValueKey('cell-4'))).dx),
);
expect(tester.takeException(), isNull);
expect(tester.takeException(), isNull);
expect(localeFromTag('zh-Hant-TW').scriptCode, 'Hant');
expect(localeFromTag('zh-Hant-TW').countryCode, 'TW');
await tester.pumpWidget(const SizedBox());
});
}