53 lines
1.9 KiB
Dart
53 lines
1.9 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:app_pfm_ocr_v2/features/camera/camera_screen.dart';
|
|
import 'package:app_pfm_ocr_v2/features/camera/image_preview_screen.dart';
|
|
|
|
void main() {
|
|
testWidgets('CameraScreen navigation to ImagePreviewScreen test', (WidgetTester tester) async {
|
|
// Generate a valid 1x1 PNG file in temp directory
|
|
final tempDir = Directory.systemTemp.createTempSync();
|
|
final tempFile = File('${tempDir.path}/test_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 a mock version of the widget tree with a simple navigator
|
|
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 to test the routing
|
|
state.navigateToPreview(tempFile.path);
|
|
|
|
// Pump frames to allow navigation and async processing to complete
|
|
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 now displayed on top of the navigator
|
|
expect(find.byType(ImagePreviewScreen), findsOneWidget);
|
|
|
|
// Cleanup
|
|
try {
|
|
tempFile.deleteSync();
|
|
tempDir.deleteSync();
|
|
} catch (_) {}
|
|
});
|
|
}
|