Files
jiu/client/test/searchable_option_create_test.dart
T
wangjia a76724b385 feat(client): 录单表单优化 + 可搜索下拉支持新建 + 日期选择器组件
新增 DatePickerField 日期选择器与 date_util;可搜索下拉 SearchableOptionField
支持内联新建选项;入库/出库录单表单、商品页、财务页、app_shell 导航相应调整。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-20 07:05:22 +08:00

60 lines
2.1 KiB
Dart

import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:jiu_client/widgets/searchable_option_field.dart';
void main() {
Widget host({
required ValueChanged<int?> onChanged,
Future<int?> Function(String)? onCreate,
}) {
return MaterialApp(
home: Scaffold(
body: SearchableOptionField(
options: [OptionItem(id: 1, name: '53度')],
selectedId: null,
hint: '选择系列',
dialogTitle: '选择系列',
onChanged: onChanged,
onCreate: onCreate,
),
),
);
}
testWidgets('搜不到时显示「新增到基础数据」入口', (tester) async {
await tester.pumpWidget(host(onChanged: (_) {}, onCreate: (_) async => 99));
// 打开搜索对话框
await tester.tap(find.byType(SearchableOptionField));
await tester.pumpAndSettle();
// 输入不存在的关键字
await tester.enterText(find.byType(TextField).first, '52度');
await tester.pumpAndSettle();
expect(find.textContaining('新增「52度」到基础数据'), findsOneWidget);
});
testWidgets('确认新增后回填选中新 id', (tester) async {
int? selected;
await tester.pumpWidget(
host(onChanged: (v) => selected = v, onCreate: (_) async => 99));
await tester.tap(find.byType(SearchableOptionField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField).first, '52度');
await tester.pumpAndSettle();
await tester.tap(find.textContaining('新增「52度」到基础数据'));
await tester.pumpAndSettle();
// 确认框
await tester.tap(find.text('确认新增'));
await tester.pumpAndSettle();
expect(selected, 99);
});
testWidgets('未提供 onCreate 时不显示新增入口', (tester) async {
await tester.pumpWidget(host(onChanged: (_) {}));
await tester.tap(find.byType(SearchableOptionField));
await tester.pumpAndSettle();
await tester.enterText(find.byType(TextField).first, '52度');
await tester.pumpAndSettle();
expect(find.textContaining('新增'), findsNothing);
});
}