42 lines
1.5 KiB
Dart
42 lines
1.5 KiB
Dart
|
|
// Runtime contract test for the pdfrx-backed PageDocumentSource (P0.5 step 12).
|
||
|
|
// The .fromDocument factory's pdfrx-API pin is verified statically by
|
||
|
|
// `flutter analyze lib/editor` (the Oracle); here we exercise the concrete
|
||
|
|
// type's PageDocumentSource behavior + composition with the layout math via the
|
||
|
|
// pdfium-free .fromSizes constructor.
|
||
|
|
|
||
|
|
import 'dart:ui' show Size;
|
||
|
|
|
||
|
|
import 'package:flutter_test/flutter_test.dart';
|
||
|
|
|
||
|
|
import 'package:badnote/editor/pdf/pdf_document_source.dart';
|
||
|
|
import 'package:badnote/editor/pdf/pdfrx_page_document_source.dart';
|
||
|
|
|
||
|
|
void main() {
|
||
|
|
test('fromSizes implements the PageDocumentSource contract', () {
|
||
|
|
const src = PdfrxPageDocumentSource.fromSizes([
|
||
|
|
Size(600, 800),
|
||
|
|
Size(595, 842),
|
||
|
|
]);
|
||
|
|
expect(src, isA<PageDocumentSource>());
|
||
|
|
expect(src.pageCount, 2);
|
||
|
|
expect(src.pageSize(0), const Size(600, 800));
|
||
|
|
expect(src.pageSize(1), const Size(595, 842));
|
||
|
|
});
|
||
|
|
|
||
|
|
test('composes with the fit-to-width layout math', () {
|
||
|
|
const src = PdfrxPageDocumentSource.fromSizes([
|
||
|
|
Size(600, 800), // portrait → at width 300, height 400
|
||
|
|
Size(800, 600), // landscape → at width 300, height 225
|
||
|
|
]);
|
||
|
|
final metrics = pageStackMetricsForWidth(src, 300, gap: 10);
|
||
|
|
expect(metrics.heightOf(0), closeTo(400, 1e-9));
|
||
|
|
expect(metrics.heightOf(1), closeTo(225, 1e-9));
|
||
|
|
expect(metrics.offsetOf(1), closeTo(410, 1e-9)); // 400 + 10 gap
|
||
|
|
});
|
||
|
|
|
||
|
|
test('empty document', () {
|
||
|
|
const src = PdfrxPageDocumentSource.fromSizes([]);
|
||
|
|
expect(src.pageCount, 0);
|
||
|
|
});
|
||
|
|
}
|