feat: add Flutter schema-driven form cards
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import 'package:aioa_mobile/core/forms/presentation/dynamic_form_card.dart';
|
||||
import 'package:aioa_mobile/core/forms/schema/form_schema.dart';
|
||||
import 'package:aioa_mobile/features/form/domain/leave_form_definition.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
testWidgets('renders controls from data and UI schema', (tester) async {
|
||||
await tester.pumpWidget(
|
||||
MaterialApp(
|
||||
home: Scaffold(
|
||||
body: SingleChildScrollView(
|
||||
child: DynamicFormCard(
|
||||
definition: leaveFormDefinition,
|
||||
state: const DynamicFormState(),
|
||||
onChanged: (_, _) {},
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
expect(find.text('请假信息'), findsOneWidget);
|
||||
expect(find.text('补充说明'), findsOneWidget);
|
||||
expect(find.text('请假类型 *'), findsOneWidget);
|
||||
expect(find.text('开始时间 *'), findsOneWidget);
|
||||
expect(find.text('结束时间 *'), findsOneWidget);
|
||||
expect(find.text('请假原因 *'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
import 'package:aioa_mobile/core/forms/schema/form_validator.dart';
|
||||
import 'package:aioa_mobile/features/form/domain/leave_form_definition.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
test('required fields are validated from JSON Schema', () {
|
||||
final errors = validateDynamicForm(
|
||||
leaveFormDefinition.dataSchema,
|
||||
const {},
|
||||
);
|
||||
|
||||
expect(errors.keys, containsAll(['type', 'startsAt', 'endsAt', 'reason']));
|
||||
});
|
||||
|
||||
test('valid leave draft passes schema validation', () {
|
||||
final errors = validateDynamicForm(leaveFormDefinition.dataSchema, {
|
||||
'type': 'PERSONAL',
|
||||
'startsAt': '2026-07-20T01:00:00Z',
|
||||
'endsAt': '2026-07-20T05:00:00Z',
|
||||
'reason': '办理个人事务',
|
||||
});
|
||||
|
||||
expect(errors, isEmpty);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user