No content changes: git diff --ignore-all-space over these files is empty. The churn came from editing on Windows against a repo checked out with LF.
120 lines
3.4 KiB
Dart
120 lines
3.4 KiB
Dart
import 'package:hive/hive.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/documents/documents_screen.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';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
class FakeBox extends Fake implements Box {
|
|
@override
|
|
Future<int> clear() async => 0;
|
|
}
|
|
|
|
class MockLocalStorage extends LocalStorage {
|
|
final List<DocumentModel> docs;
|
|
|
|
MockLocalStorage(this.docs);
|
|
|
|
@override
|
|
Future<void> init() async {}
|
|
|
|
@override
|
|
Box get documentBox => FakeBox();
|
|
|
|
@override
|
|
Box get pendingDocumentsBox => FakeBox();
|
|
|
|
@override
|
|
List<DocumentModel> getAllDocuments() {
|
|
return docs;
|
|
}
|
|
|
|
@override
|
|
Future<void> saveDocument(DocumentModel doc) async {}
|
|
|
|
@override
|
|
Future<void> savePendingDocument(Map<String, dynamic> data) async {}
|
|
|
|
@override
|
|
Future<void> removePendingDocument(String id) async {}
|
|
|
|
@override
|
|
List<Map<String, dynamic>> getAllPendingDocuments() {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
void main() {
|
|
testWidgets('DocumentsScreen search and coordinate formatting tests', (WidgetTester tester) async {
|
|
SharedPreferences.setMockInitialValues({});
|
|
final testDocs = [
|
|
DocumentModel(
|
|
id: '1',
|
|
tanggal: '29 Juni 2026',
|
|
noPo: 'PO/26/0000111111',
|
|
noSo: '1000000001',
|
|
noDo: 'DO-BEKASI-111111',
|
|
kepadaYth: 'PM KELAPA DUA KARAWACI',
|
|
orderUntuk: 'PRIMA FRESH MART',
|
|
alamat: 'Bekasi',
|
|
platTruk: 'B 1234 ABC',
|
|
namaDriver: 'Driver A',
|
|
namaPenerima: 'Penerima A',
|
|
latitude: -6.123456,
|
|
longitude: 106.567890,
|
|
items: [],
|
|
createdAt: DateTime.now(),
|
|
),
|
|
DocumentModel(
|
|
id: '2',
|
|
tanggal: '30 Juni 2026',
|
|
noPo: 'PO/26/0000222222',
|
|
noSo: '2000000002',
|
|
noDo: 'DO-TANGERANG-222222',
|
|
kepadaYth: 'PM KELAPA DUA KARAWACI',
|
|
orderUntuk: 'PRIMA FRESH MART',
|
|
alamat: 'Tangerang',
|
|
platTruk: 'B 5678 XYZ',
|
|
namaDriver: 'Driver B',
|
|
namaPenerima: 'Penerima B',
|
|
latitude: null,
|
|
longitude: null,
|
|
items: [],
|
|
createdAt: DateTime.now().subtract(const Duration(hours: 1)),
|
|
),
|
|
];
|
|
|
|
final mockLocalStorage = MockLocalStorage(testDocs);
|
|
|
|
await tester.pumpWidget(
|
|
ProviderScope(
|
|
overrides: [
|
|
localStorageProvider.overrideWithValue(mockLocalStorage),
|
|
],
|
|
child: const MaterialApp(
|
|
home: DocumentsScreen(),
|
|
),
|
|
),
|
|
);
|
|
|
|
await tester.pumpAndSettle();
|
|
|
|
// Verify both documents are rendered initially
|
|
expect(find.text('PO/26/0000111111'), findsOneWidget);
|
|
expect(find.text('PO/26/0000222222'), findsOneWidget);
|
|
|
|
// Type query in search bar to filter only Bekasi
|
|
final searchField = find.byType(TextField);
|
|
expect(searchField, findsOneWidget);
|
|
await tester.enterText(searchField, 'BEKASI');
|
|
await tester.pump();
|
|
|
|
// Verify only the Bekasi document matches
|
|
expect(find.text('PO/26/0000111111'), findsOneWidget);
|
|
expect(find.text('PO/26/0000222222'), findsNothing);
|
|
});
|
|
}
|