91 lines
2.8 KiB
Dart
91 lines
2.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:app_pfm_ocr_v2/features/editor/editor_screen.dart';
|
|
import 'package:app_pfm_ocr_v2/features/documents/pending_documents_provider.dart';
|
|
import 'package:app_pfm_ocr_v2/models/document_model.dart';
|
|
import 'package:app_pfm_ocr_v2/main.dart';
|
|
import 'package:app_pfm_ocr_v2/core/storage/local_storage.dart';
|
|
|
|
class MockLocalStorage extends LocalStorage {
|
|
@override
|
|
Future<void> init() async {}
|
|
@override
|
|
Future<void> saveDocument(DocumentModel doc) async {}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('EditorScreen input validation tests', (WidgetTester tester) async {
|
|
final mockLocalStorage = MockLocalStorage();
|
|
|
|
final testDoc = DocumentModel(
|
|
id: 'pending_123',
|
|
tanggal: '29 Juni 2026',
|
|
noPo: 'PO/26/1234567890',
|
|
noSo: '1234567890',
|
|
noDo: 'DO-123',
|
|
kepadaYth: 'PT. A',
|
|
orderUntuk: 'PRIMA FRESH MART',
|
|
alamat: 'Alamat',
|
|
platTruk: 'B 1234 A',
|
|
namaDriver: 'Driver',
|
|
namaPenerima: '',
|
|
latitude: -6.2000,
|
|
longitude: 106.8000,
|
|
items: [
|
|
DocumentItem(nomorSku: '12010112', namaBarang: 'FIESTA CHICKEN NUGGET', banyak: '1 BOX', jumlah: '12 PAC'),
|
|
],
|
|
createdAt: DateTime.now(),
|
|
);
|
|
|
|
// Initialize the Riverpod container with local storage overrides
|
|
final container = ProviderContainer(
|
|
overrides: [
|
|
localStorageProvider.overrideWithValue(mockLocalStorage),
|
|
],
|
|
);
|
|
|
|
// Set the pending documents state BEFORE widget tree is built (before initState)
|
|
container.read(pendingDocumentsProvider.notifier).state = [
|
|
PendingDocument(
|
|
id: 'pending_123',
|
|
imagePath: 'dummy.png',
|
|
status: PendingDocumentStatus.success,
|
|
document: testDoc,
|
|
latitude: -6.2000,
|
|
longitude: 106.8000,
|
|
),
|
|
];
|
|
|
|
await tester.pumpWidget(
|
|
UncontrolledProviderScope(
|
|
container: container,
|
|
child: const MaterialApp(
|
|
home: Scaffold(
|
|
body: EditorScreen(pendingId: 'pending_123'),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// Find all TextFormFields
|
|
final textFormFields = find.byType(TextFormField);
|
|
expect(textFormFields, findsAtLeastNWidgets(2));
|
|
|
|
// Enter invalid PO format (Index 0 is Tanggal, Index 1 is No PO)
|
|
await tester.enterText(textFormFields.at(1), 'PO-INVALID');
|
|
await tester.pumpAndSettle();
|
|
|
|
// Trigger validation by tapping the button
|
|
final reviewButtonFinder = find.text('Review Complete');
|
|
expect(reviewButtonFinder, findsOneWidget);
|
|
await tester.tap(reviewButtonFinder);
|
|
await tester.pumpAndSettle();
|
|
|
|
// Verify PO format validation error is shown
|
|
expect(find.text('Format harus PO/[XX]/[XXXXXXXXXX]'), findsOneWidget);
|
|
});
|
|
}
|