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/domain/library.dart'; import 'package:lumen/main.dart'; import 'package:lumen/services/progress.dart'; import 'halloween_test.dart' as halloween; import 'library_test.dart' as library_flow; import 'region_test.dart' as regions; void main() { final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); testWidgets('phone reading and puzzle controls fit default and larger text', ( tester, ) async { expect(const bool.fromEnvironment('QA_TEST'), true); final library = await StoryLibrary.load(); final book = await library.open('midnight-invitation'); final game = Game( book, Progress.memory({'language': 'en', 'ambience_enabled': false}), library: library, ); var scale = 1.0; Widget app() => MaterialApp( debugShowCheckedModeBanner: false, theme: ThemeData(fontFamily: 'MaraHand'), builder: (context, child) => MediaQuery( data: MediaQuery.of(context) .copyWith(textScaler: TextScaler.linear(scale)), child: child!, ), home: Notebook(game: game, adsEnabled: false), ); await tester.pumpWidget(app()); await tester.pumpAndSettle(); await binding.convertFlutterSurfaceToImage(); Future orient(DeviceOrientation orientation) async { await SystemChrome.setPreferredOrientations([orientation]); for (var i = 0; i < 40; i++) { await tester.pump(const Duration(milliseconds: 100)); final size = tester.view.physicalSize; if ((size.height > size.width) == (orientation == DeviceOrientation.portraitUp)) { await tester.pumpAndSettle(); return; } } fail('Phone did not rotate to $orientation'); } for (final textScale in [1.0, 1.3]) { scale = textScale; await tester.pumpWidget(app()); for (final orientation in [ DeviceOrientation.portraitUp, DeviceOrientation.landscapeLeft, ]) { await orient(orientation); final layout = orientation == DeviceOrientation.portraitUp ? 'portrait' : 'landscape'; final tag = 'phone-$layout-${(scale * 100).round()}'; game.home(); await tester.pumpAndSettle(); expect(find.text(book.title), findsOneWidget); await binding.takeScreenshot('$tag-home'); for (final pageId in [ 'midnight.opening', 'midnight.key.puzzle', 'midnight.candle.entry', 'midnight.mirror.puzzle', 'midnight.ending', ]) { game.showStory(book.pages.indexWhere((p) => p.id == pageId)); await tester.pumpAndSettle(); final next = pageId == 'midnight.ending' ? 'Back to contents' : 'Next leaf →'; expect( find.text(next).hitTestable(), findsOneWidget, reason: '$tag $pageId', ); expect(find.text('Contents'), findsNothing, reason: '$tag $pageId'); if (game.storyPage.type == StoryPageType.puzzle) { for (final index in [0, game.cells.length - 1]) { final cell = find.byKey(ValueKey('cell-$index')); expect( cell.hitTestable(), findsOneWidget, reason: '$tag $pageId', ); expect( tester.getRect(cell).bottom, lessThan(tester.getRect(find.text(next)).top), reason: '$tag $pageId', ); } final hint = find.text('Hint · rewarded ad'); await tester.ensureVisible(hint); await tester.pumpAndSettle(); expect(hint.hitTestable(), findsOneWidget, reason: '$tag $pageId'); final cell = find.byKey(const ValueKey('cell-0')); debugPrint('PHONE_GRID $tag $pageId cell=${tester.getSize(cell)}'); await tester.ensureVisible(find.byKey(const ValueKey('area-1'))); await tester.tap(find.byKey(const ValueKey('area-1'))); await tester.pumpAndSettle(); expect(game.selectedArea, 1); } await binding.takeScreenshot('$tag-${pageId.replaceAll('.', '-')}'); expect(tester.takeException(), isNull, reason: '$tag $pageId'); } } } await tester.pumpWidget(const SizedBox()); await SystemChrome.setPreferredOrientations([]); }); halloween.main(); regions.main(); library_flow.main(); }