From d613a4602223f048440d4b9cd88006d4c7519b6a Mon Sep 17 00:00:00 2001 From: Pratyush Chauhan Date: Sun, 15 Oct 2023 17:43:16 +0530 Subject: [PATCH] Integration test #57 (#90) * #57: add integration tests for notes crud operations --- integration_test/test_guest_login.dart | 61 ++++++++++++++++++++ integration_test/test_note_deletion.dart | 64 +++++++++++++++++++++ integration_test/test_note_updation.dart | 71 ++++++++++++++++++++++++ pubspec.lock | 47 ++++++++++++++-- pubspec.yaml | 3 + test_driver/integration_driver.dart | 3 + 6 files changed, 245 insertions(+), 4 deletions(-) create mode 100644 integration_test/test_guest_login.dart create mode 100644 integration_test/test_note_deletion.dart create mode 100644 integration_test/test_note_updation.dart create mode 100644 test_driver/integration_driver.dart diff --git a/integration_test/test_guest_login.dart b/integration_test/test_guest_login.dart new file mode 100644 index 00000000..1991be00 --- /dev/null +++ b/integration_test/test_guest_login.dart @@ -0,0 +1,61 @@ +import 'package:dairy_app/core/pages/home_page.dart'; +import 'package:dairy_app/features/notes/presentation/pages/note_create_page.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_save_button.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_title_input_field.dart'; +import 'package:dairy_app/app/view/app.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_quill/flutter_quill.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:dairy_app/core/dependency_injection/injection_container.dart' + as di; + +Future main() async { + setUpAll(() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(); + await di.init(); + }); + + testWidgets( + 'Guest login integration test,' + 'click on sign up button to move reveal guest login button' + 'click the guest login button to enter HomePage' + 'Click on the floating action button to move to NoteCreatePage' + 'Enter some text in the title field' + 'Enter some text in the body field' + 'Click on the save button to save the note' + 'Click on the back button to move back to HomePage' + 'Check if the note is saved in the HomePage', + (WidgetTester tester) async { + await tester.pumpWidget(const App()); + await tester.pumpAndSettle(); + await tester.tap(find.text('Continue as guest')); + await tester.pumpAndSettle(); + expect(find.byType(HomePage), findsOneWidget); + await tester.pumpAndSettle(); + await tester.tap(find.byType(FloatingActionButton)); + await tester.pumpAndSettle(); + await tester.enterText(find.byType(NoteTitleInputField), 'Test Title'); + await tester.pumpAndSettle(); + + expect(find.byType(QuillEditor), findsOneWidget); + + expect( + find.descendant( + of: find.byType(QuillEditor), + matching: find.byType(TextFieldTapRegion), + ), + findsOneWidget); + + await tester.tap(find.byType(NoteSaveButton)); + await tester.pumpAndSettle(); + + await Future.delayed(const Duration(seconds: 1)); + await tester.pumpAndSettle(); + expect(find.text('Test Title'), findsOneWidget); + expect(find.byType(HomePage), findsOneWidget); + expect(find.byType(NoteCreatePage), findsNothing); + }); +} diff --git a/integration_test/test_note_deletion.dart b/integration_test/test_note_deletion.dart new file mode 100644 index 00000000..f1beb1be --- /dev/null +++ b/integration_test/test_note_deletion.dart @@ -0,0 +1,64 @@ +import 'package:dairy_app/core/pages/home_page.dart'; +import 'package:dairy_app/core/widgets/home_page_app_bar.dart'; +import 'package:dairy_app/features/notes/presentation/pages/note_create_page.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_save_button.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_title_input_field.dart'; +import 'package:dairy_app/app/view/app.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_quill/flutter_quill.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:dairy_app/core/dependency_injection/injection_container.dart' + as di; + +Future main() async { + setUpAll(() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(); + await di.init(); + }); + + testWidgets( + 'Run login and create note' + 'long press the note' + 'delete the note and check if the note is deleted', + (WidgetTester tester) async { + await tester.pumpWidget(const App()); + await tester.pumpAndSettle(); + await tester.tap(find.text('Continue as guest')); + await tester.pumpAndSettle(); + expect(find.byType(HomePage), findsOneWidget); + await tester.pumpAndSettle(); + await tester.tap(find.byType(FloatingActionButton)); + await tester.pumpAndSettle(); + await tester.enterText(find.byType(NoteTitleInputField), 'Test Title'); + await tester.pumpAndSettle(); + + expect(find.byType(QuillEditor), findsOneWidget); + + expect( + find.descendant( + of: find.byType(QuillEditor), + matching: find.byType(TextFieldTapRegion), + ), + findsOneWidget); + + await tester.tap(find.byType(NoteSaveButton)); + await tester.pumpAndSettle(); + + await Future.delayed(const Duration(seconds: 1)); + await tester.pumpAndSettle(); + expect(find.text('Test Title'), findsOneWidget); + expect(find.byType(HomePage), findsOneWidget); + expect(find.byType(NoteCreatePage), findsNothing); + await tester.longPress(find.text('Test Title')); + await tester.pumpAndSettle(); + await tester.tap(find.byType(DeleteIcon)); + await tester.pumpAndSettle(); + await tester.tap(find.text('Delete')); + await Future.delayed(const Duration(seconds: 1)); + expect(find.text('Test Title'), findsNothing); + expect(find.byType(HomePage), findsOneWidget); + }); +} diff --git a/integration_test/test_note_updation.dart b/integration_test/test_note_updation.dart new file mode 100644 index 00000000..3d11f2a7 --- /dev/null +++ b/integration_test/test_note_updation.dart @@ -0,0 +1,71 @@ +import 'package:dairy_app/core/pages/home_page.dart'; +import 'package:dairy_app/features/notes/presentation/pages/note_create_page.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_save_button.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/note_title_input_field.dart'; +import 'package:dairy_app/app/view/app.dart'; +import 'package:dairy_app/features/notes/presentation/widgets/toggle_read_write_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter_dotenv/flutter_dotenv.dart'; +import 'package:flutter_quill/flutter_quill.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:integration_test/integration_test.dart'; +import 'package:dairy_app/core/dependency_injection/injection_container.dart' + as di; + +Future main() async { + setUpAll(() async { + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); + await dotenv.load(); + await di.init(); + }); + + testWidgets( + 'Run login and create note,' + 'update the note title and chek if the note is updated', + (WidgetTester tester) async { + await tester.pumpWidget(const App()); + await tester.pumpAndSettle(); + await tester.tap(find.text('Continue as guest')); + await tester.pumpAndSettle(); + expect(find.byType(HomePage), findsOneWidget); + await tester.pumpAndSettle(); + await tester.tap(find.byType(FloatingActionButton)); + await tester.pumpAndSettle(); + await tester.enterText(find.byType(NoteTitleInputField), 'Test Title'); + await tester.pumpAndSettle(); + + expect(find.byType(QuillEditor), findsOneWidget); + + expect( + find.descendant( + of: find.byType(QuillEditor), + matching: find.byType(TextFieldTapRegion), + ), + findsOneWidget); + + await tester.tap(find.byType(NoteSaveButton)); + await tester.pumpAndSettle(); + + await Future.delayed(const Duration(seconds: 1)); + await tester.pumpAndSettle(); + expect(find.text('Test Title'), findsOneWidget); + expect(find.byType(HomePage), findsOneWidget); + expect(find.byType(NoteCreatePage), findsNothing); + await tester.tap(find.text('Test Title')); + await tester.pumpAndSettle(); + await tester.tap(find.byType(ToggleReadWriteButton)); + await tester.pumpAndSettle(); + await tester.enterText( + find.byType(NoteTitleInputField), 'Test Title Updated'); + await tester.pumpAndSettle(); + await tester.tap(find.byType(NoteSaveButton)); + await tester.pumpAndSettle(); + + await Future.delayed(const Duration(seconds: 1)); + await tester.pumpAndSettle(); + expect(find.text('Test Title'), findsNothing); + expect(find.text('Test Title Updated'), findsOneWidget); + expect(find.byType(HomePage), findsOneWidget); + expect(find.byType(NoteCreatePage), findsNothing); + }); +} diff --git a/pubspec.lock b/pubspec.lock index c081fd2c..1e704ad9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -398,6 +398,11 @@ packages: url: "https://pub.dev" source: hosted version: "5.1.0" + flutter_driver: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" flutter_inappwebview: dependency: transitive description: @@ -619,6 +624,11 @@ packages: url: "https://pub.dev" source: hosted version: "3.2.0" + fuchsia_remote_debug_protocol: + dependency: transitive + description: flutter + source: sdk + version: "0.0.0" gallery_saver: dependency: transitive description: @@ -779,6 +789,11 @@ packages: url: "https://pub.dev" source: hosted version: "0.2.1" + integration_test: + dependency: "direct dev" + description: flutter + source: sdk + version: "0.0.0" internet_connection_checker: dependency: "direct main" description: @@ -1087,10 +1102,10 @@ packages: dependency: transitive description: name: platform - sha256: "57c07bf82207aee366dfaa3867b3164e4f03a238a461a11b0e8a3a510d51203d" + sha256: "4a451831508d7d6ca779f7ac6e212b4023dd5a7d08a27a63da33756410e32b76" url: "https://pub.dev" source: hosted - version: "3.1.1" + version: "3.1.0" plugin_platform_interface: dependency: transitive description: @@ -1115,6 +1130,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.5.1" + process: + dependency: transitive + description: + name: process + sha256: "53fd8db9cec1d37b0574e12f07520d582019cb6c44abf5479a01505099a34a09" + url: "https://pub.dev" + source: hosted + version: "4.2.4" provider: dependency: "direct main" description: @@ -1366,6 +1389,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.0" + sync_http: + dependency: transitive + description: + name: sync_http + sha256: "7f0cd72eca000d2e026bcd6f990b81d0ca06022ef4e32fb257b30d3d1014a961" + url: "https://pub.dev" + source: hosted + version: "0.3.1" synchronized: dependency: transitive description: @@ -1594,10 +1625,10 @@ packages: dependency: transitive description: name: vm_service - sha256: "0fae432c85c4ea880b33b497d32824b97795b04cdaa74d270219572a1f50268d" + sha256: c620a6f783fa22436da68e42db7ebbf18b8c44b9a46ab911f666ff09ffd9153f url: "https://pub.dev" source: hosted - version: "11.9.0" + version: "11.7.1" watcher: dependency: transitive description: @@ -1622,6 +1653,14 @@ packages: url: "https://pub.dev" source: hosted version: "2.4.0" + webdriver: + dependency: transitive + description: + name: webdriver + sha256: "3c923e918918feeb90c4c9fdf1fe39220fa4c0e8e2c0fffaded174498ef86c49" + url: "https://pub.dev" + source: hosted + version: "3.0.2" webkit_inspection_protocol: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index ffd0a034..e3aeae28 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -78,6 +78,9 @@ dev_dependencies: flutter_test: sdk: flutter mockito: ^5.1.0 + integration_test: + sdk: flutter + # not using this as of now # flutter_icons: diff --git a/test_driver/integration_driver.dart b/test_driver/integration_driver.dart new file mode 100644 index 00000000..b38629cc --- /dev/null +++ b/test_driver/integration_driver.dart @@ -0,0 +1,3 @@ +import 'package:integration_test/integration_test_driver.dart'; + +Future main() => integrationDriver();