Imrpoved image handling since the size of the image is about 5MB.

This commit is contained in:
verboomp
2026-02-02 10:54:53 +01:00
parent 8d329501e4
commit 5f2a54a5bc
4 changed files with 151 additions and 115 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flutter_image_test_utils/image_test/image_test_io.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:fotodocumentation/controller/customer_controller.dart';
import 'package:fotodocumentation/dto/customer_dto.dart' show CustomerDto, CustomerListDto;
@@ -78,18 +79,20 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Verify customer name is displayed
expect(find.text('Test Apotheke'), findsOneWidget);
// Verify customer name is displayed
expect(find.text('Test Apotheke'), findsOneWidget);
// Verify customer number is displayed
expect(find.text('CUST001'), findsOneWidget);
// Verify customer number is displayed
expect(find.text('CUST001'), findsOneWidget);
// Verify labels are displayed
expect(find.text('KUNDENNUMMER'), findsOneWidget);
expect(find.text('KOMMENTAR'), findsOneWidget);
// Verify labels are displayed
expect(find.text('KUNDENNUMMER'), findsOneWidget);
expect(find.text('KOMMENTAR'), findsOneWidget);
});
});
testWidgets('displays picture comment', (WidgetTester tester) async {
@@ -98,11 +101,13 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Verify the comment is displayed
expect(find.text('First picture comment'), findsOneWidget);
// Verify the comment is displayed
expect(find.text('First picture comment'), findsOneWidget);
});
});
testWidgets('displays empty string when comment is null', (WidgetTester tester) async {
@@ -110,12 +115,13 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// The comment field should be empty but the label should exist
expect(find.text('KOMMENTAR'), findsOneWidget);
// The comment field should be empty but the label should exist
expect(find.text('KOMMENTAR'), findsOneWidget);
});
});
testWidgets('shows both navigation buttons at bottom', (WidgetTester tester) async {
@@ -124,12 +130,14 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Both navigation buttons should always be visible at the bottom
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
// Both navigation buttons should always be visible at the bottom
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
});
});
testWidgets('shows both navigation buttons when on middle picture', (WidgetTester tester) async {
@@ -137,13 +145,14 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Both navigation buttons should be visible
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
// Both navigation buttons should be visible
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
});
});
testWidgets('shows both navigation buttons on last picture', (WidgetTester tester) async {
@@ -151,13 +160,14 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Both navigation buttons should be visible (right one is disabled)
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
// Both navigation buttons should be visible (right one is disabled)
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
});
});
testWidgets('navigates to next picture when right button is tapped', (WidgetTester tester) async {
@@ -165,20 +175,21 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Verify first picture comment is shown
expect(find.text('First picture comment'), findsOneWidget);
// Verify first picture comment is shown
expect(find.text('First picture comment'), findsOneWidget);
// Tap right navigation button
await tester.tap(find.byKey(Key("navigate_right")));
await tester.pumpAndSettle();
// Tap right navigation button
await tester.tap(find.byKey(Key("navigate_right")));
await tester.pumpAndSettle();
// Verify second picture comment is now shown
expect(find.text('Second picture comment'), findsOneWidget);
expect(find.text('First picture comment'), findsNothing);
// Verify second picture comment is now shown
expect(find.text('Second picture comment'), findsOneWidget);
expect(find.text('First picture comment'), findsNothing);
});
});
testWidgets('navigates to previous picture when left button is tapped', (WidgetTester tester) async {
@@ -187,19 +198,21 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/2");
await tester.pumpAndSettle();
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/2");
await tester.pumpAndSettle();
// Verify second picture comment is shown
expect(find.text('Second picture comment'), findsOneWidget);
// Verify second picture comment is shown
expect(find.text('Second picture comment'), findsOneWidget);
// Tap left navigation button
await tester.tap(find.byKey(Key("navigate_left")));
await tester.pumpAndSettle();
// Tap left navigation button
await tester.tap(find.byKey(Key("navigate_left")));
await tester.pumpAndSettle();
// Verify first picture comment is now shown
expect(find.text('First picture comment'), findsOneWidget);
expect(find.text('Second picture comment'), findsNothing);
// Verify first picture comment is now shown
expect(find.text('First picture comment'), findsOneWidget);
expect(find.text('Second picture comment'), findsNothing);
});
});
testWidgets('shows disabled navigation buttons when only one picture', (WidgetTester tester) async {
@@ -215,12 +228,14 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => singlePictureCustomer);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Both navigation buttons should be shown but disabled
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
// Both navigation buttons should be shown but disabled
expect(find.byKey(Key("navigate_left")), findsOneWidget);
expect(find.byKey(Key("navigate_right")), findsOneWidget);
});
});
testWidgets('opens fullscreen dialog when image is tapped', (WidgetTester tester) async {
@@ -228,25 +243,26 @@ void main() {
when(mockCustomerController.get(id: 1)).thenAnswer((_) async => customerDto);
when(mockCustomerController.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1${GlobalRouter.pathPicture}/1");
await tester.pumpAndSettle();
// Find the GestureDetector with the image key
final imageFinder = find.byKey(const Key("image"));
expect(imageFinder, findsOneWidget);
// Find the GestureDetector with the image key
final imageFinder = find.byKey(const Key("image"));
expect(imageFinder, findsOneWidget);
// Ensure the widget is visible first
await tester.ensureVisible(imageFinder);
await tester.pumpAndSettle();
// Ensure the widget is visible first
await tester.ensureVisible(imageFinder);
await tester.pumpAndSettle();
// Tap the image - use warnIfMissed: false since the Image.memory may have
// rendering issues in test environment but the GestureDetector should still work
await tester.tap(imageFinder, warnIfMissed: false);
await tester.pumpAndSettle();
// Tap the image - use warnIfMissed: false since the Image.memory may have
// rendering issues in test environment but the GestureDetector should still work
await tester.tap(imageFinder, warnIfMissed: false);
await tester.pumpAndSettle();
// Verify fullscreen dialog is shown
expect(find.byType(PictureFullscreenDialog), findsOneWidget);
// Verify fullscreen dialog is shown
expect(find.byType(PictureFullscreenDialog), findsOneWidget);
});
});
});
}