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

File diff suppressed because one or more lines are too long

View File

@@ -12,6 +12,7 @@ import 'package:fotodocumentation/controller/customer_controller.dart';
import 'package:fotodocumentation/controller/picture_controller.dart';
import 'package:fotodocumentation/dto/customer_dto.dart';
import 'package:fotodocumentation/utils/di_container.dart';
import 'package:flutter_image_test_utils/flutter_image_test_utils.dart';
import '../testing/test_utils.dart';
import '../testing/test_utils.mocks.dart';
@@ -31,16 +32,17 @@ void main() {
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
when(controller.getAll("", "")).thenAnswer((_) async => _list);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_1")).first);
await tester.pumpAndSettle();
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_1")).first);
await tester.pumpAndSettle();
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureWidget), findsOneWidget);
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureWidget), findsOneWidget);
});
});
testWidgets('Customer delete yes', (WidgetTester tester) async {
@@ -55,22 +57,24 @@ void main() {
when(controller.getAll("", "")).thenAnswer((_) async => _list);
when(pictureController.delete(argThat(isA<PictureDto>()))).thenAnswer((_) async => true);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_delete_1")).first);
await tester.pumpAndSettle();
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_delete_1")).first);
await tester.pumpAndSettle();
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureDeleteDialog), findsOneWidget);
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureDeleteDialog), findsOneWidget);
// Click the yes button to confirm delete
await tester.tap(find.byKey(Key("picture_delete_yes")));
await tester.pumpAndSettle();
// Click the yes button to confirm delete
await tester.tap(find.byKey(Key("picture_delete_yes")));
await tester.pumpAndSettle();
// Verify that the delete method was called on the picture controller
verify(pictureController.delete(argThat(isA<PictureDto>()))).called(1);
// Verify that the delete method was called on the picture controller
verify(pictureController.delete(argThat(isA<PictureDto>()))).called(1);
});
});
testWidgets('Customer delete no', (WidgetTester tester) async {
@@ -84,28 +88,39 @@ void main() {
when(controller.get(id: 1)).thenAnswer((_) async => _dto);
when(controller.getAll("", "")).thenAnswer((_) async => _list);
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
provideMockedNetworkImages(() async {
await pumpAppConfig(tester, "${GlobalRouter.pathHome}${GlobalRouter.pathCustomer}/1");
verify(controller.get(id: 1)).called(1);
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_delete_1")).first);
await tester.pumpAndSettle();
// Click on the first row (InkWell) to open the picture popup
await tester.tap(find.byKey(Key("table_row_delete_1")).first);
await tester.pumpAndSettle();
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureDeleteDialog), findsOneWidget);
// Verify that the popup is shown by checking for the PictureWidget
expect(find.byType(PictureDeleteDialog), findsOneWidget);
// Click the yes button to confirm delete
await tester.tap(find.byKey(Key("picture_delete_no")));
await tester.pumpAndSettle();
// Click the yes button to confirm delete
await tester.tap(find.byKey(Key("picture_delete_no")));
await tester.pumpAndSettle();
// Verify that the delete method was called on the picture controller
verifyNever(pictureController.delete(argThat(isA<PictureDto>())));
// Verify that the delete method was called on the picture controller
verifyNever(pictureController.delete(argThat(isA<PictureDto>())));
});
});
});
}
CustomerDto _dto = CustomerDto(id: 1, customerNumber: "CODE1", name: "Customer 1", pictures: [
PictureDto(id: 1, comment: "Some comment", category: "category", pictureDate: DateTime.now(), username: "username", imageUrl: "", evaluation: 1, normalSizeUrl: "", thumbnailSizeUrl: ""),
]);
PictureDto(
id: 1,
comment: "Some comment",
category: "category",
pictureDate: DateTime.now(),
username: "username",
imageUrl: "https://en.wikipedia.org/wiki/File:Keir_Starmer_meets_T%C3%B4_L%C3%A2m_29-10-2025_(6)_(cropped).jpg",
evaluation: 1,
normalSizeUrl: "https://en.wikipedia.org/wiki/File:Keir_Starmer_meets_T%C3%B4_L%C3%A2m_29-10-2025_(6)_(cropped).jpg",
thumbnailSizeUrl: "https://en.wikipedia.org/wiki/File:Keir_Starmer_meets_T%C3%B4_L%C3%A2m_29-10-2025_(6)_(cropped).jpg"),
]);
List<CustomerListDto> _list = [CustomerListDto(id: 1, customerNumber: "CODE1", name: "Customer 1"), CustomerListDto(id: 2, customerNumber: "CODE2", name: "Customer 2")];
List<CustomerListDto> _list = [CustomerListDto(id: 1, customerNumber: "CODE1", name: "Customer 1"), CustomerListDto(id: 2, customerNumber: "CODE2", name: "Customer 2")];

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);
});
});
});
}