Migrate Lumen to Dart and Flutter 2.0
This commit is contained in:
@@ -0,0 +1,158 @@
|
||||
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);
|
||||
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 decoder, 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 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');
|
||||
// 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();
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user