79 lines
2.6 KiB
Dart
79 lines
2.6 KiB
Dart
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_test/flutter_test.dart';
|
|
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:app_pfm_ocr_v2/features/camera/camera_screen.dart';
|
|
import 'package:app_pfm_ocr_v2/features/camera/image_preview_screen.dart';
|
|
import 'package:app_pfm_ocr_v2/core/location/location_service.dart';
|
|
|
|
void main() {
|
|
testWidgets('CameraScreen coordinates capture and preview navigation test', (WidgetTester tester) async {
|
|
// Inject mock coordinates
|
|
final mockPos = Position(
|
|
latitude: -6.2000,
|
|
longitude: 106.8000,
|
|
timestamp: DateTime.now(),
|
|
accuracy: 1.0,
|
|
altitude: 10.0,
|
|
altitudeAccuracy: 1.0,
|
|
heading: 0.0,
|
|
headingAccuracy: 1.0,
|
|
speed: 0.0,
|
|
speedAccuracy: 1.0,
|
|
);
|
|
LocationService.mockDeterminator = () async => mockPos;
|
|
|
|
// Create a dummy image file in temp directory
|
|
final tempDir = Directory.systemTemp.createTempSync();
|
|
final tempFile = File('${tempDir.path}/test_location_image.png');
|
|
final dummyPngBytes = [
|
|
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82,
|
|
0, 0, 0, 1, 0, 0, 0, 1, 8, 6, 0, 0, 0, 31, 21, 196, 137,
|
|
0, 0, 0, 10, 73, 68, 65, 84, 120, 156, 99, 0, 1, 0, 0, 5,
|
|
0, 1, 13, 10, 45, 180, 0, 0, 0, 0, 73, 69, 78, 68, 174, 66, 96, 130
|
|
];
|
|
tempFile.writeAsBytesSync(dummyPngBytes);
|
|
|
|
// Build the widget tree
|
|
await tester.pumpWidget(
|
|
const ProviderScope(
|
|
child: MaterialApp(
|
|
home: Scaffold(
|
|
body: CameraScreen(),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
|
|
// Find the state of the CameraScreen
|
|
final CameraScreenState state = tester.state(find.byType(CameraScreen));
|
|
|
|
// Call the navigation method directly with coordinates
|
|
state.navigateToPreview(
|
|
tempFile.path,
|
|
latitude: mockPos.latitude,
|
|
longitude: mockPos.longitude,
|
|
);
|
|
|
|
await tester.pump();
|
|
await tester.pump(const Duration(milliseconds: 500)); // Pushes preview screen
|
|
await tester.pump(const Duration(seconds: 1)); // Waits for blur analysis to finish
|
|
|
|
// Verify that the ImagePreviewScreen is displayed and has coordinates
|
|
final previewFinder = find.byType(ImagePreviewScreen);
|
|
expect(previewFinder, findsOneWidget);
|
|
|
|
final ImagePreviewScreen previewWidget = tester.widget(previewFinder);
|
|
expect(previewWidget.latitude, equals(-6.2000));
|
|
expect(previewWidget.longitude, equals(106.8000));
|
|
|
|
// Cleanup
|
|
try {
|
|
tempFile.deleteSync();
|
|
tempDir.deleteSync();
|
|
} catch (_) {}
|
|
LocationService.mockDeterminator = null;
|
|
});
|
|
}
|