From 821d33c79c994d5cde50a552d0a7e24bdc88984c Mon Sep 17 00:00:00 2001 From: Satyam Jha <135056339+may-tas@users.noreply.github.com> Date: Thu, 12 Dec 2024 20:54:40 +0530 Subject: [PATCH] added new tests cases for the ExpendableAgendaItemTile widget to enhance testing coverage (#2663) Co-authored-by: Satyam Jha --- .../widgets/agenda_item_tile_test.dart | 228 ++++++++++++++++++ 1 file changed, 228 insertions(+) diff --git a/test/widget_tests/widgets/agenda_item_tile_test.dart b/test/widget_tests/widgets/agenda_item_tile_test.dart index 8ff3cf6d4..e0aed941b 100644 --- a/test/widget_tests/widgets/agenda_item_tile_test.dart +++ b/test/widget_tests/widgets/agenda_item_tile_test.dart @@ -89,6 +89,28 @@ void main() { expect(find.text('https://example.com'), findsOneWidget); }); + testWidgets('Handles empty lists correctly', (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + duration: '00:30', + sequence: 1, + categories: [], + attachments: [], + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + expect(find.byType(Chip), findsNothing); + expect(find.text('URLs:'), findsNothing); + expect(find.text('Attachments:'), findsNothing); + }); + testWidgets('Edit button calls onEdit callback', (WidgetTester tester) async { bool editCalled = false; @@ -132,5 +154,211 @@ void main() { expect(deleteCalled, isTrue); }); + + group('Attachment Tests', () { + const validBase64Image1 = + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wAAAwAB/4JAoQAAAABJRU5ErkJggg=="; + const validBase64Image2 = + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/wQACgAB/1TwbpAAAAAASUVORK5CYII="; + final testAttachments = [ + validBase64Image1, + validBase64Image2, + ]; + testWidgets('Attachments Images display correctly', + (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + // Verify attachments header is displayed + expect(find.text('Attachments:'), findsOneWidget); + + // Verify GridView is displayed + expect(find.byType(GridView), findsOneWidget); + + // Verify the number of items in the grid + expect(find.byType(Image), findsNWidgets(testAttachments.length)); + }); + + testWidgets('GridView layout properties are correct', + (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + final GridView gridView = tester.widget(find.byType(GridView)); + final SliverGridDelegateWithFixedCrossAxisCount delegate = + gridView.gridDelegate as SliverGridDelegateWithFixedCrossAxisCount; + + expect(delegate.crossAxisCount, 3); + expect(delegate.crossAxisSpacing, 10); + expect(delegate.mainAxisSpacing, 10); + }); + + testWidgets('ClipRRect is applied correctly to valid images', + (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + expect( + find.byWidgetPredicate( + (widget) => + widget is ClipRRect && + widget.borderRadius == BorderRadius.circular(8), + ), + findsNWidgets(testAttachments.length), + ); + }); + + testWidgets('Fallback icon is displayed for invalid attachments', + (WidgetTester tester) async { + final testAttachments = [ + "invalid_base64_data", + ]; + + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + // Verify Container is displayed and its properties are correct + find.byWidgetPredicate( + (widget) => + widget is Container && + (widget.decoration! as BoxDecoration).borderRadius == + BorderRadius.circular(8), + ); + + // Verify fallback icon is displayed + expect(find.byIcon(Icons.attachment), findsOneWidget); + }); + + testWidgets('Tap on attachment opens full-screen image view', + (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + // Tap on the first attachment + await tester.tap(find.byType(Image).first); + await tester.pumpAndSettle(); + + // Verify full-screen image view is displayed + expect(find.byType(InteractiveViewer), findsOneWidget); + + // Close the dialog + await tester.tapAt(Offset.zero); + await tester.pumpAndSettle(); + + // Verify the dialog is dismissed + expect(find.byType(InteractiveViewer), findsNothing); + }); + + testWidgets('verify full-screen image properties', + (WidgetTester tester) async { + testAgendaItem = EventAgendaItem( + id: '1', + title: 'Test Agenda Item', + description: 'Test Description', + duration: '00:30', + sequence: 1, + categories: [], + attachments: testAttachments, + urls: [], + ); + + await tester.pumpWidget(createExpandableAgendaItemTile()); + await tester.pumpAndSettle(); + + await tester.tap(find.text('Test Agenda Item')); + await tester.pumpAndSettle(); + + // Tap on the first attachment + await tester.tap(find.byType(Image).first); + await tester.pumpAndSettle(); + + // Colored box renders correctly + expect( + find.byWidgetPredicate( + (widget) => + widget is ColoredBox && + widget.color == Colors.black.withOpacity(0.5), + ), + findsOneWidget, + ); + // Interactive viewer properties + final InteractiveViewer viewer = + tester.widget(find.byType(InteractiveViewer)); + expect(viewer.panEnabled, isTrue); + expect(viewer.boundaryMargin, const EdgeInsets.all(20)); + expect(viewer.minScale, 0.5); + expect(viewer.maxScale, 4); + }); + }); }); }