diff --git a/lib/ui/pages/landing_page/landing_page.dart b/lib/ui/pages/landing_page/landing_page.dart index 03458398..aa184cbc 100644 --- a/lib/ui/pages/landing_page/landing_page.dart +++ b/lib/ui/pages/landing_page/landing_page.dart @@ -116,12 +116,17 @@ class _LandingPageState extends ConsumerState { Flexible( flex: 2, child: _ProjectPreview( - ioHandler: ioHandler, - imageService: imageService, - latestModifiedProject: latestModifiedProject, - openProject: () => - _openProject(latestModifiedProject, ioHandler, ref), - ), + ioHandler: ioHandler, + imageService: imageService, + latestModifiedProject: latestModifiedProject, + onProjectPreviewTap: () { + if (latestModifiedProject != null) { + _openProject(latestModifiedProject, ioHandler, ref); + } else { + _clearCanvas(); + _navigateToPocketPaint(); + } + }), ), Container( color: PaintroidTheme.of(context).primaryContainerColor, @@ -208,13 +213,13 @@ class _ProjectPreview extends StatelessWidget { final Project? latestModifiedProject; final IOHandler ioHandler; final IImageService imageService; - final VoidCallback openProject; + final VoidCallback onProjectPreviewTap; const _ProjectPreview({ this.latestModifiedProject, required this.ioHandler, required this.imageService, - required this.openProject, + required this.onProjectPreviewTap, }); @override @@ -223,7 +228,7 @@ class _ProjectPreview extends StatelessWidget { children: [ Material( child: InkWell( - onTap: openProject, + onTap: onProjectPreviewTap, child: ImagePreview( project: latestModifiedProject, imageService: imageService, @@ -236,15 +241,30 @@ class _ProjectPreview extends StatelessWidget { key: const Key('myEditIcon'), iconSize: 264, onPressed: () async { - if (latestModifiedProject != null) { - openProject(); - } + onProjectPreviewTap.call(); }, - icon: const IconSvg( - path: 'assets/svg/ic_edit_circle.svg', - height: 264.0, - width: 264.0, - ), + icon: latestModifiedProject == null + ? Container( + height: 170.0, + width: 170.0, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: PaintroidTheme.of(context) + .outlineColor + .withAlpha(180)), + child: Center( + child: Icon( + Icons.add, + color: PaintroidTheme.of(context).backgroundColor, + size: 150.0, + ), + ), + ) + : const IconSvg( + path: 'assets/svg/ic_edit_circle.svg', + height: 264.0, + width: 264.0, + ), ), ), Align( diff --git a/test/widget/landing_page/landing_page_test.dart b/test/widget/landing_page/landing_page_test.dart index 24447fb8..ce6a6f0f 100644 --- a/test/widget/landing_page/landing_page_test.dart +++ b/test/widget/landing_page/landing_page_test.dart @@ -23,6 +23,7 @@ import 'package:paintroid/core/models/database/project.dart'; import 'package:paintroid/core/providers/object/device_service.dart'; import 'package:paintroid/core/providers/object/file_service.dart'; import 'package:paintroid/core/providers/object/image_service.dart'; +import 'package:paintroid/core/providers/state/canvas_state_provider.dart'; import 'package:paintroid/ui/pages/landing_page/components/main_overflow_menu.dart'; import 'package:paintroid/ui/pages/landing_page/components/project_list_tile.dart'; import 'package:paintroid/ui/pages/landing_page/components/project_overflow_menu.dart'; @@ -156,6 +157,128 @@ void main() { }, ); + testWidgets( + 'Should open PocketPaint widget trough edit (new project) icon and return back to Landing page', + (tester) async { + when(database.projectDAO).thenReturn(dao); + when(dao.getProjects()).thenAnswer((_) => Future.value([])); + await tester.pumpWidget(sut); + await tester.pumpAndSettle(); + verify(database.projectDAO); + verify(dao.getProjects()); + + final editButton = find.byKey(const Key('myEditIcon')); + await tester.tap(editButton); + await tester.pumpAndSettle(); + + expect(find.byType(TopAppBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); + + final titleFinder = find.widgetWithText(TopAppBar, 'Pocket Paint'); + expect(titleFinder, findsOneWidget); + + final overflowMenuButtonFinder = find.widgetWithIcon( + PopupMenuButton, + Icons.more_vert, + ); + expect(overflowMenuButtonFinder, findsOneWidget); + + // Check the canvas is empty + final container = ProviderContainer(); + final canvasState = container.read(canvasStateProvider); + expect(canvasState.backgroundImage, isNull); + expect(canvasState.cachedImage, isNull); + expect(canvasState.size, equals(Size.zero)); + + await tester.pageBack(); + await tester.pumpAndSettle(); + expect(find.text('My Projects'), findsOneWidget); + }, + ); + + testWidgets( + 'Should open PocketPaint widget trough edit (new project) icon save it and return back to Landing page. Then open the project trough edit icon.', + (tester) async { + String projectName = 'project.catrobat-image'; + + when(database.projectDAO).thenReturn(dao); + when(dao.getProjects()).thenAnswer((_) => Future.value([])); + when(fileService.checkIfFileExistsInApplicationDirectory(projectName)) + .thenAnswer((_) => Future.value(false)); + when(imageService.getProjectPreview(filePath)) + .thenReturn(Result.ok(testFile.readAsBytesSync())); + await tester.pumpWidget(sut); + await tester.pumpAndSettle(); + verify(database.projectDAO); + verify(dao.getProjects()); + + final plusButton = find.byKey(const Key('myEditIcon')); + expect(plusButton, findsOneWidget); + await tester.tap(plusButton); + await tester.pumpAndSettle(); + + expect(find.byType(TopAppBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); + + final titleFinder = find.widgetWithText(TopAppBar, 'Pocket Paint'); + expect(titleFinder, findsOneWidget); + + final overflowMenuButtonFinder = find.widgetWithIcon( + PopupMenuButton, + Icons.more_vert, + ); + expect(overflowMenuButtonFinder, findsOneWidget); + + // Check the canvas is empty + final container = ProviderContainer(); + final canvasState = container.read(canvasStateProvider); + expect(canvasState.backgroundImage, isNull); + expect(canvasState.cachedImage, isNull); + expect(canvasState.size, equals(Size.zero)); + + await tester.tap(overflowMenuButtonFinder); + await tester.pumpAndSettle(); + + final saveProjectButton = find.text('Save project'); + expect(saveProjectButton, findsOneWidget); + + await tester.tap(saveProjectButton); + await tester.pumpAndSettle(); + + final textFormField = find.widgetWithText(TextFormField, 'Project name'); + expect(textFormField, findsOneWidget); + + await tester.enterText(textFormField, 'project'); + + final saveButton = find.widgetWithText(TextButton, 'Save'); + expect(saveButton, findsOneWidget); + + await tester.tap(saveButton); + await tester.pumpAndSettle(); + + await tester.pageBack(); + await tester.pumpAndSettle(); + + expect(find.text('My Projects'), findsOneWidget); + + final editButton = find.byKey(const Key('myEditIcon')); + await tester.tap(editButton); + await tester.pumpAndSettle(); + + expect(find.byType(TopAppBar), findsOneWidget); + expect(find.byType(NavigationBar), findsOneWidget); + + final titleFinder2 = find.widgetWithText(TopAppBar, 'Pocket Paint'); + expect(titleFinder2, findsOneWidget); + + final overflowMenuButtonFinder2 = find.widgetWithIcon( + PopupMenuButton, + Icons.more_vert, + ); + expect(overflowMenuButtonFinder2, findsOneWidget); + }, + ); + testWidgets( 'Should have "My Projects" section', (tester) async {