021c4f17cc
Deploy Client / build-windows (push) Successful in 1m54s
Deploy Client / build-client-web (push) Successful in 44s
Deploy Client / build-macos (push) Successful in 2m22s
Deploy Client / build-android (push) Successful in 1m35s
Deploy Client / build-ios (push) Successful in 2m47s
Deploy Client / release-deploy-client (push) Successful in 1m57s
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
69 lines
2.5 KiB
Dart
69 lines
2.5 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:pdf/widgets.dart' as pw;
|
|
import 'package:jiu_client/core/utils/print_util_stub.dart';
|
|
|
|
/// 出/入库单打印分页回归测试。
|
|
///
|
|
/// 背景:1.0.83 的打印改版用「非可拆分 Container 包裹整块内容」,当明细超过一页
|
|
/// 时 MultiPage 无法拆分、分页算法不前进 → 无限加页、内存暴涨 → 打印卡死。
|
|
/// 1.0.86 改为三段结构(前/后两段短原子 Container + 可拆分明细表,竖线由内容
|
|
/// 自身携带),明细表可跨页拆分,无「原子大组件超页」,正常分页且竖线尾页贴合
|
|
/// 内容。本测试锁定该行为,防止再退回卡死实现。
|
|
void main() {
|
|
late pw.Font font;
|
|
|
|
setUpAll(() {
|
|
// 直接从仓库内字体文件加载(无需 Flutter asset bundle / binding)。
|
|
final bytes =
|
|
File('assets/fonts/NotoSansSC-Regular.ttf').readAsBytesSync();
|
|
font = pw.Font.ttf(bytes.buffer.asByteData());
|
|
});
|
|
|
|
List<List<String>> makeRows(int n) => [
|
|
for (var i = 0; i < n; i++)
|
|
[
|
|
'ZXZ0112$i',
|
|
'茅台金贵宾2011',
|
|
'普通/53度',
|
|
'500ml/单品',
|
|
'2010-32/07852',
|
|
'2026-01-19',
|
|
'1',
|
|
'1000.00',
|
|
'1000.00',
|
|
'',
|
|
],
|
|
];
|
|
|
|
Future<int> pageCount(int rows) => debugOrderDocPageCount(
|
|
() => debugBuildOrderDoc(
|
|
font: font,
|
|
bold: font,
|
|
rows: makeRows(rows),
|
|
totalQty: rows.toDouble(),
|
|
totalAmt: rows * 1000.0,
|
|
),
|
|
);
|
|
|
|
test('单页:少量明细生成 1 页', () async {
|
|
expect(await pageCount(1), 1);
|
|
expect(await pageCount(3), 1);
|
|
});
|
|
|
|
test('跨页:明细超过一页能正常分页且不卡死(回归 1.0.84 打印卡死)', () async {
|
|
// 60 行远超一页:旧实现会在此无限加页→卡死。新实现应正常分页到多页。
|
|
// 用 timeout 兜底——若退回卡死实现,此处会超时失败而非整个测试进程挂死。
|
|
final pages = await pageCount(60);
|
|
expect(pages, greaterThan(1));
|
|
}, timeout: const Timeout(Duration(seconds: 30)));
|
|
|
|
test('明细行数越多页数单调不减(分页稳定推进,不会原地打转)', () async {
|
|
final p20 = await pageCount(20);
|
|
final p120 = await pageCount(120);
|
|
expect(p120, greaterThanOrEqualTo(p20));
|
|
expect(p120, greaterThan(1));
|
|
}, timeout: const Timeout(Duration(seconds: 45)));
|
|
}
|