116 lines
3.9 KiB
Dart
116 lines
3.9 KiB
Dart
// Real Flutter UI captures at a 360 x 640 logical phone viewport, rendered at 3x.
|
|
// Run: flutter test tool/capture_play_store_test.dart
|
|
import 'dart:io';
|
|
import 'dart:ui' as ui;
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.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/domain/postcards.dart';
|
|
import 'package:lumen/main.dart';
|
|
import 'package:lumen/services/progress.dart';
|
|
|
|
void main() {
|
|
TestWidgetsFlutterBinding.ensureInitialized();
|
|
testWidgets('capture Play Store phone screens from the real app', (
|
|
tester,
|
|
) async {
|
|
tester.view.physicalSize = const Size(360, 640);
|
|
tester.view.devicePixelRatio = 1;
|
|
addTearDown(tester.view.reset);
|
|
await tester.runAsync(() async {
|
|
for (final name in ['sans-serif', 'serif', 'Roboto']) {
|
|
await (FontLoader(name)
|
|
..addFont(rootBundle.load('assets/fonts/NotoSans-Regular.ttf')))
|
|
.load();
|
|
}
|
|
for (final font in {
|
|
'MaraHand': 'DancingScript.ttf',
|
|
'LumenText': 'NotoSans-Regular.ttf',
|
|
'LumenSymbols': 'NotoSansSymbols-Regular.ttf',
|
|
'LumenSymbols2': 'NotoSansSymbols2-Regular.ttf',
|
|
'LumenMath': 'NotoSansMath-Regular.ttf',
|
|
}.entries) {
|
|
await (FontLoader(
|
|
font.key,
|
|
)..addFont(rootBundle.load('assets/fonts/${font.value}'))).load();
|
|
}
|
|
});
|
|
await tester.runAsync(() async {
|
|
await (FontLoader(
|
|
'MaterialIcons',
|
|
)..addFont(rootBundle.load('fonts/MaterialIcons-Regular.otf'))).load();
|
|
});
|
|
final library = (await tester.runAsync(StoryLibrary.load))!;
|
|
final book = (await tester.runAsync(() async {
|
|
for (final story in library.stories) {
|
|
await library.open(story.id);
|
|
}
|
|
return library.open('mara-island');
|
|
}))!;
|
|
final game = Game(
|
|
book,
|
|
Progress.memory({'language': 'en', 'ambience_enabled': false}),
|
|
library: library,
|
|
);
|
|
await tester.pumpWidget(
|
|
RepaintBoundary(
|
|
key: const ValueKey('store-capture'),
|
|
child: LumenApp(game: game, adsEnabled: false),
|
|
),
|
|
);
|
|
Future<void> capture(String name) async {
|
|
// Resolve asset IO in the real event loop without activating narration timers.
|
|
for (var i = 0; i < 5; i++) {
|
|
await tester.runAsync(
|
|
() => Future<void>.delayed(const Duration(milliseconds: 40)),
|
|
);
|
|
await tester.pump();
|
|
}
|
|
await tester.pumpAndSettle();
|
|
expect(tester.takeException(), isNull);
|
|
final boundary = tester.renderObject<RenderRepaintBoundary>(
|
|
find.byKey(const ValueKey('store-capture')),
|
|
);
|
|
await tester.runAsync(() async {
|
|
final image = await boundary.toImage(pixelRatio: 3);
|
|
final data = await image.toByteData(format: ui.ImageByteFormat.png);
|
|
final directory = Directory('artifacts/play-store/phone')
|
|
..createSync(recursive: true);
|
|
File('${directory.path}/$name.png')
|
|
.writeAsBytesSync(data!.buffer.asUint8List());
|
|
image.dispose();
|
|
});
|
|
}
|
|
|
|
game.home();
|
|
await capture('01-notebook');
|
|
game.showStory(book.pages.indexWhere((p) => p.id == 'cottage.window'));
|
|
await capture('02-story');
|
|
game.showStory(
|
|
book.pages.indexWhere((p) => p.id == 'cottage.match.puzzle'),
|
|
);
|
|
final puzzle = game.puzzle!;
|
|
for (var i = 0; i < puzzle.size * 2; i++) {
|
|
if (puzzle.given[i]) continue;
|
|
game.mark(i);
|
|
if (puzzle.solution[i] == 0) game.mark(i);
|
|
}
|
|
await capture('03-logic-puzzle');
|
|
for (var slot = 0; slot < 3; slot++) {
|
|
await game.store.set(
|
|
'done_${islandPostcards.first.puzzleKey(slot)}',
|
|
true,
|
|
);
|
|
}
|
|
game.showPostcards();
|
|
await capture('04-island-postcards');
|
|
game.showLibrary();
|
|
await capture('05-bookshelf');
|
|
await tester.pumpWidget(const SizedBox());
|
|
});
|
|
}
|