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/main.dart'; import 'package:lumen/services/progress.dart'; import 'package:lumen/ui/board.dart'; void main() { final binding = IntegrationTestWidgetsFlutterBinding.ensureInitialized(); testWidgets('discovery artwork fits real leaves at larger text', ( tester, ) async { expect(const bool.fromEnvironment('QA_TEST'), true); final book = await Book.load(); // Export one chapter per run: retaining every full-resolution screenshot // in reportData at once exhausts the tablet when the driver encodes JSON. const chapter = int.fromEnvironment('ART_CHAPTER', defaultValue: 0); expect(chapter, inInclusiveRange(0, 2)); final game = Game( book, Progress.memory({ 'story_access_level': 11, for (var i = 0; i < 12; i++) 'done_story_v1_$i': true, }), ); addTearDown(() => SystemChrome.setPreferredOrientations([])); await binding.convertFlutterSurfaceToImage(); for (final orientation in [ DeviceOrientation.portraitUp, DeviceOrientation.landscapeLeft, ]) { await SystemChrome.setPreferredOrientations([orientation]); await tester.pumpAndSettle(); for (var index = chapter * 4; index < (chapter + 1) * 4; index++) { game.reveal(index, readAhead: true); await tester.pumpWidget( MaterialApp( theme: ThemeData(fontFamily: 'MaraHand'), home: Builder( builder: (context) => MediaQuery( data: MediaQuery.of(context) .copyWith(textScaler: const TextScaler.linear(1.5)), child: Notebook(game: game, adsEnabled: false), ), ), ), ); await tester.pumpAndSettle(); final asset = book.levels[index].illustrationAsset; final art = asset == null ? find.byType(PixelPicture) : find.image(AssetImage(asset)); expect(art, findsOneWidget); await tester.ensureVisible(art); await tester.pumpAndSettle(); await binding.takeScreenshot( 'discovery-$index-${orientation.name}-art', ); final next = find.text( index < 4 ? 'Next leaf →' : index == 11 ? 'Return to the notebook' : 'Turn the page →', ); await tester.ensureVisible(next); await tester.pumpAndSettle(); expect(next.hitTestable(), findsOneWidget); expect(game.solved, 0); expect(tester.takeException(), isNull); } if (chapter == 0) { game.showStory(3); await tester.pumpAndSettle(); final match = find.image( AssetImage(book.levels.first.illustrationAsset!), ); expect(match, findsOneWidget); await tester.ensureVisible(match); await tester.pumpAndSettle(); await binding.takeScreenshot('opening-match-${orientation.name}'); expect(find.text('Next leaf →').hitTestable(), findsOneWidget); expect(tester.takeException(), isNull); } } await tester.pumpWidget(const SizedBox()); await tester.pumpAndSettle(); }); }