Skip to content

Commit

Permalink
Integration test #57 (#90)
Browse files Browse the repository at this point in the history
* #57: add integration tests for notes crud operations
  • Loading branch information
PratyushChauhan authored and SankethBK committed Oct 20, 2023
1 parent 9e81d01 commit d613a46
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 4 deletions.
61 changes: 61 additions & 0 deletions integration_test/test_guest_login.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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);
});
}
64 changes: 64 additions & 0 deletions integration_test/test_note_deletion.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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);
});
}
71 changes: 71 additions & 0 deletions integration_test/test_note_updation.dart
Original file line number Diff line number Diff line change
@@ -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<void> 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);
});
}
47 changes: 43 additions & 4 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions test_driver/integration_driver.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'package:integration_test/integration_test_driver.dart';

Future<void> main() => integrationDriver();

0 comments on commit d613a46

Please sign in to comment.