@@ -3,6 +3,12 @@ import 'dart:ffi' hide Size;
33import 'dart:io' ;
44
55import 'package:bloc_test/bloc_test.dart' ;
6+ import 'package:otzaria/book_protection/models/book_protection.dart' ;
7+ import 'package:otzaria/divine_names/models/divine_name_spans.dart' ;
8+ import 'package:otzaria/divine_names/repository/divine_names_repository.dart' ;
9+ import 'package:otzaria/models/books.dart' ;
10+ import 'package:otzaria/text_book/models/book_notes.dart' ;
11+ import 'package:otzaria/text_book/repository/book_notes_repository.dart' ;
612import 'package:ffi/ffi.dart' show using;
713import 'package:flutter/material.dart' ;
814import 'package:flutter/services.dart' ;
@@ -508,4 +514,160 @@ void main() {
508514 timeout: const Timeout (Duration (minutes: 2 )),
509515 );
510516 }
517+ for (final prebuilt in [false , true ]) {
518+ for (final initialPages in [1 , 2 ]) {
519+ testWidgets (
520+ 'שינוי מ-$initialPages ל-${3 - initialPages } עמודים בזמן טעינת נתוני ${prebuilt ? 'מפרשים' : 'טקסט' } שומר את כיוון המשימה' ,
521+ (tester) async {
522+ tester.view.physicalSize = const Size (1600 , 1200 );
523+ tester.view.devicePixelRatio = 1 ;
524+ addTearDown (tester.view.reset);
525+ final pendingNames = Completer <DivineNameSpans >();
526+ addTearDown (() {
527+ if (! pendingNames.isCompleted) {
528+ pendingNames.complete (DivineNameSpans .empty);
529+ }
530+ });
531+ final lines = ['ספר' , for (var i = 1 ; i <= 100 ; i++ ) 'שורת בדיקה $i ' ];
532+ DivineNamesRepository .instance.clear ();
533+ BookNotesRepository .instance.clear ();
534+ DivineNamesRepository .instance.debugLoader =
535+ (
536+ title, {
537+ categoryId,
538+ required source,
539+ }) => pendingNames.future;
540+ BookNotesRepository .instance.debugLoader =
541+ (
542+ title, {
543+ categoryId,
544+ required source,
545+ }) async => BookNotes .empty;
546+ addTearDown (() {
547+ DivineNamesRepository .instance
548+ ..debugLoader = null
549+ ..clear ();
550+ BookNotesRepository .instance
551+ ..debugLoader = null
552+ ..clear ();
553+ });
554+ final platform = _CapturingPrintingPlatform ();
555+ PrintingPlatform .instance = platform;
556+ addTearDown (() async {
557+ if (! platform.job.isCompleted) platform.job.complete (false );
558+ await tester.pumpWidget (const SizedBox ());
559+ await drainPrintingRasterQueue (tester);
560+ });
561+ final settingsBloc = _MockSettingsBloc ();
562+ whenListen (
563+ settingsBloc,
564+ const Stream <SettingsState >.empty (),
565+ initialState: SettingsState .initial (),
566+ );
567+ await tester.runAsync (pdfrxFlutterInitialize);
568+ await tester.pumpWidget (
569+ RepositoryProvider <SettingsRepository >.value (
570+ value: _FakeSettingsRepository (),
571+ child: BlocProvider <SettingsBloc >.value (
572+ value: settingsBloc,
573+ child: MaterialApp (
574+ builder: (context, child) => MediaQuery (
575+ data: MediaQuery .of (
576+ context,
577+ ).copyWith (textScaler: const TextScaler .linear (0.5 )),
578+ child: child! ,
579+ ),
580+ home: PrintingScreen (
581+ data: Future .value (lines.join ('\n ' )),
582+ prebuiltBlocks: prebuilt
583+ ? [
584+ for (final line in lines)
585+ PrintBlock (
586+ kind: PrintBlockKind .commentary,
587+ text: line,
588+ ),
589+ ]
590+ : null ,
591+ startLine: 1 ,
592+ endLine: 101 ,
593+ bookId: 'ספר בדיקה' ,
594+ book: TextBook (title: 'ספר בדיקה' ),
595+ protection: BookProtection .none,
596+ ),
597+ ),
598+ ),
599+ ),
600+ );
601+ await tester.pump ();
602+ tester
603+ .widget <PrintingOrientationDropdownRow >(
604+ find.byType (PrintingOrientationDropdownRow ),
605+ )
606+ .onChanged (pw.PageOrientation .landscape);
607+ void setPages (int value) => tester
608+ .widget <PrintingPagesPerSheetDropdownRow >(
609+ find.byType (PrintingPagesPerSheetDropdownRow ),
610+ )
611+ .onChanged (value);
612+ setPages (initialPages);
613+ await tester.pump (const Duration (milliseconds: 300 ));
614+ await tester.tap (find.text ('הדפסה' ));
615+ await tester.pump ();
616+ expect (platform.onLayout, isNotNull);
617+ var outputReady = false ;
618+ final pendingOutput = Future .value (
619+ platform.onLayout !(PdfPageFormat .a4),
620+ )..then ((_) => outputReady = true );
621+ await tester.pump (const Duration (milliseconds: 50 ));
622+ expect (
623+ outputReady,
624+ isFalse,
625+ reason: 'נתוני הספר עדיין ממתינים בזמן שינוי ההגדרות.' ,
626+ );
627+ setPages (3 - initialPages);
628+ await tester.pump (const Duration (milliseconds: 300 ));
629+ expect (outputReady, isFalse);
630+ pendingNames.complete (DivineNameSpans .empty);
631+ final output = await _settle (tester, pendingOutput);
632+ platform.job.complete (false );
633+ await tester.pump ();
634+ Future <void > expectGeometry (Uint8List bytes, int pages) async {
635+ final document = await _settle (tester, PdfDocument .openData (bytes));
636+ final sheet = document.pages.first.size;
637+ await _settle (tester, document.dispose ());
638+ expect (sheet.width, closeTo (PdfPageFormat .a4.landscape.width, 0.1 ));
639+ expect (
640+ sheet.height,
641+ closeTo (PdfPageFormat .a4.landscape.height, 0.1 ),
642+ );
643+ if (pages == 2 ) {
644+ final placements = await _settle (
645+ tester,
646+ _pdfFirstSheet (bytes, 1 , 2 ),
647+ );
648+ expect (placements, hasLength (2 ));
649+ for (final placement in placements) {
650+ expect (
651+ placement.page.width,
652+ closeTo (placement.cell.width, 0.1 ),
653+ );
654+ expect (
655+ placement.page.height,
656+ closeTo (placement.cell.height, 0.1 ),
657+ );
658+ }
659+ }
660+ }
661+
662+ await expectGeometry (output, initialPages);
663+ final nextOutput = await _settle (
664+ tester,
665+ Future .value (platform.onLayout !(PdfPageFormat .a4)),
666+ );
667+ await expectGeometry (nextOutput, 3 - initialPages);
668+ },
669+ timeout: const Timeout (Duration (minutes: 2 )),
670+ );
671+ }
672+ }
511673}
0 commit comments