169 lines
6.1 KiB
Dart
169 lines
6.1 KiB
Dart
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');
|
|
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);
|
|
await tap('Bookmark');
|
|
await tap('Language');
|
|
await tap('Deutsch');
|
|
expect(g.book.language, 'de');
|
|
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);
|
|
expect(g.progress.text('notebook_manual_bookmark'), 'boat.puzzle');
|
|
await tap('Buch schließen');
|
|
await tap('Geschichtenbibliothek');
|
|
expect(
|
|
find.descendant(
|
|
of: find.byType(AlertDialog),
|
|
matching: find.text('Das Papierboot'),
|
|
),
|
|
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').hitTestable(), findsOneWidget);
|
|
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('اللغة'), findsOneWidget);
|
|
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());
|
|
});
|
|
}
|