fix(client): 出入库抽屉生产日期截取防空串崩溃

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
wangjia
2026-07-14 10:09:35 +08:00
parent 44c985e6b5
commit 782cf057a3
4 changed files with 45 additions and 6 deletions
@@ -0,0 +1,31 @@
import 'package:flutter_test/flutter_test.dart';
import 'package:jiu_client/core/utils/date_util.dart';
/// 2026-07-14 Critical 修复回归:出入库详情抽屉构造 OrderLine 时对
/// `productionDate` 做 `substring(0, 10)`,只防 null 不防空串——后端
/// `Date.MarshalJSON` 对零值日期序列化为 `""`(非 null),历史导入数据里
/// 大量商品无生产日期,`''.substring(0, 10)` 会抛 RangeError 导致打开
/// 详情抽屉直接崩溃。`shortDate` 需把空串也当「无值」归一为 null。
void main() {
group('shortDate', () {
test('null 返回 null', () {
expect(shortDate(null), isNull);
});
test('空串返回 null(回归:曾经 substring(0, 10) 抛 RangeError', () {
expect(shortDate(''), isNull);
});
test('标准 yyyy-MM-dd 原样截取前 10 位', () {
expect(shortDate('2021-01-27'), '2021-01-27');
});
test('带时间戳的日期截取前 10 位', () {
expect(shortDate('2021-01-27T00:00:00Z'), '2021-01-27');
});
test('长度不足 10 原样返回', () {
expect(shortDate('2021'), '2021');
});
});
}