결재 단계 편집 다이얼로그 구현

This commit is contained in:
JiWoong Sul
2025-09-25 17:57:29 +09:00
parent 6d6781f552
commit 8a6ad1e81b
17 changed files with 1689 additions and 42 deletions

View File

@@ -7,6 +7,7 @@ import 'package:shadcn_ui/shadcn_ui.dart';
import 'package:superport_v2/core/common/models/paginated_result.dart';
import 'package:superport_v2/features/approvals/domain/entities/approval.dart';
import 'package:superport_v2/features/approvals/step/domain/entities/approval_step_input.dart';
import 'package:superport_v2/features/approvals/step/domain/entities/approval_step_record.dart';
import 'package:superport_v2/features/approvals/step/domain/repositories/approval_step_repository.dart';
import 'package:superport_v2/features/approvals/step/presentation/pages/approval_step_page.dart';
@@ -29,6 +30,12 @@ Widget _buildApp(Widget child) {
void main() {
TestWidgetsFlutterBinding.ensureInitialized();
setUpAll(() {
registerFallbackValue(
ApprovalStepInput(approvalId: 1, stepOrder: 1, approverId: 1),
);
});
late _MockApprovalStepRepository repository;
final record = ApprovalStepRecord(
@@ -107,4 +114,153 @@ void main() {
await tester.tap(find.text('닫기'));
await tester.pumpAndSettle();
});
testWidgets('단계 추가 다이얼로그에서 저장을 호출한다', (tester) async {
dotenv.testLoad(fileInput: 'FEATURE_APPROVALS_ENABLED=true\n');
repository = _MockApprovalStepRepository();
GetIt.I.registerLazySingleton<ApprovalStepRepository>(() => repository);
final createdRecord = ApprovalStepRecord(
approvalId: 12,
approvalNo: 'APP-2024-0012',
transactionNo: 'TRX-2024-012',
templateName: '입고 기본',
step: ApprovalStep(
id: 777,
stepOrder: 2,
approver: ApprovalApprover(id: 33, employeeNo: 'E033', name: '김승인2'),
status: ApprovalStatus(id: 1, name: '승인대기', color: null),
assignedAt: DateTime(2024, 4, 2, 9),
decidedAt: null,
note: '신규 단계',
),
);
when(
() => repository.list(
page: any(named: 'page'),
pageSize: any(named: 'pageSize'),
query: any(named: 'query'),
statusId: any(named: 'statusId'),
approverId: any(named: 'approverId'),
approvalId: any(named: 'approvalId'),
),
).thenAnswer(
(_) async => PaginatedResult<ApprovalStepRecord>(
items: [record],
page: 1,
pageSize: 20,
total: 1,
),
);
when(() => repository.create(any())).thenAnswer((_) async => createdRecord);
await tester.pumpWidget(_buildApp(const ApprovalStepPage()));
await tester.pump();
await tester.pumpAndSettle();
await tester.tap(find.byKey(const ValueKey('approval_step_create')));
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const ValueKey('step_form_approval_id')),
'12',
);
await tester.enterText(
find.byKey(const ValueKey('step_form_step_order')),
'2',
);
await tester.enterText(
find.byKey(const ValueKey('step_form_approver_id')),
'33',
);
await tester.enterText(
find.byKey(const ValueKey('step_form_note')),
'신규 단계',
);
await tester.tap(find.byKey(const ValueKey('step_form_submit')));
await tester.pump();
await tester.pumpAndSettle();
verify(() => repository.create(any())).called(1);
expect(find.text('결재번호 APP-2024-0012 단계가 추가되었습니다.'), findsOneWidget);
});
testWidgets('단계 수정 다이얼로그에서 저장을 호출한다', (tester) async {
dotenv.testLoad(fileInput: 'FEATURE_APPROVALS_ENABLED=true\n');
repository = _MockApprovalStepRepository();
GetIt.I.registerLazySingleton<ApprovalStepRepository>(() => repository);
final updatedRecord = ApprovalStepRecord(
approvalId: record.approvalId,
approvalNo: record.approvalNo,
transactionNo: record.transactionNo,
templateName: record.templateName,
step: ApprovalStep(
id: record.step.id,
stepOrder: 2,
approver: ApprovalApprover(id: 30, employeeNo: 'E030', name: '박수정'),
status: record.step.status,
assignedAt: record.step.assignedAt,
decidedAt: record.step.decidedAt,
note: '수정됨',
),
);
when(
() => repository.list(
page: any(named: 'page'),
pageSize: any(named: 'pageSize'),
query: any(named: 'query'),
statusId: any(named: 'statusId'),
approverId: any(named: 'approverId'),
approvalId: any(named: 'approvalId'),
),
).thenAnswer(
(_) async => PaginatedResult<ApprovalStepRecord>(
items: [record],
page: 1,
pageSize: 20,
total: 1,
),
);
when(
() => repository.update(any(), any()),
).thenAnswer((_) async => updatedRecord);
await tester.pumpWidget(_buildApp(const ApprovalStepPage()));
await tester.pump();
await tester.pumpAndSettle();
final editButtonFinder = find.byKey(
ValueKey('step_edit_${record.step.id}_${record.step.stepOrder}'),
);
final editButton = tester.widget<ShadButton>(editButtonFinder);
editButton.onPressed?.call();
await tester.pump();
await tester.pumpAndSettle();
await tester.enterText(
find.byKey(const ValueKey('step_form_step_order')),
'2',
);
await tester.enterText(
find.byKey(const ValueKey('step_form_approver_id')),
'30',
);
await tester.enterText(find.byKey(const ValueKey('step_form_note')), '수정됨');
await tester.tap(find.byKey(const ValueKey('step_form_submit')));
await tester.pump();
await tester.pumpAndSettle();
verify(() => repository.update(record.step.id!, any())).called(1);
expect(
find.text('결재번호 ${record.approvalNo} 단계 정보를 수정했습니다.'),
findsOneWidget,
);
});
}