Closed PratyushChauhan closed 10 months ago
This works, you can use this starting point
import 'package:dairy_app/app/view/app.dart';
import 'package:dairy_app/core/pages/home_page.dart';
import 'package:dairy_app/features/auth/presentation/pages/auth_page.dart';
import 'package:flutter_dotenv/flutter_dotenv.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 test, click on sign up button to move reveal guest login button'
'click the guest login button to enter 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);
});
}
you can click on FloatingActionButton, create a note with some title and body and check if it appears in home page after saving
This works for login but we get the following error if we try to make a note and save it in guest mode.
This works for login but we get the following error if we try to make a note and save it in guest mode.
Can you push the code, I'll try running locally
On it. One more this, these logs were shown after I manually tried to create the note since the test kept failing.
Hi, this test will pass, i think the issue occurs when we try to add text into the rich text editor. So let's add only title for now
import 'package:dairy_app/core/pages/home_page.dart';
import 'package:dairy_app/core/widgets/glassmorphism_cover.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/features/notes/presentation/widgets/notes_close_button.dart';
import 'package:dairy_app/features/notes/presentation/widgets/rich_text_editor.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('...', (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();
// input some text in title field
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: 5));
await tester.pumpAndSettle();
expect(find.text('Test Title'), findsOneWidget);
expect(find.byType(HomePage), findsOneWidget);
expect(find.byType(NoteCreatePage), findsNothing);
});
}
Also there was a bug during saving the note I have fixed it in latest master commit
Makes sense, since we have to format strings before we pass them into the rich text editor. Thanks for your guidance.
Will work on updation and deletion next.
Makes sense, since we have to format strings before we pass them into the rich text editor.
Actually we should be able to enter raw text into the rich text editor since QuillEditor has TextFieldTapRegion
as one of its child. It should handle the conversion to json internally. Not sure why its not working. Anyway we can consider only title for this issue.
Found some reference for how they are doing it in widget tests of flutter_quill
. It looks a bit complicated, since we don't have access to RawEditor
outside of the package. So its better to ignore this for now https://github.com/SankethBK/dairy_app/blob/f62ea47d797507477ef412c93232e17e0f02b6c7/packages/flutter_quill/lib/src/test/widget_tester_extension.dart
Alright
Add note updation test.
Add integration test for note deletion. Please review and let me know what other tests I should add.
Add integration test for note deletion. Please review and let me know what other tests I should add.
Thank you, will review it by today
Let's have all testWidgets
in a single file note_crud_tests.dart
and create a group like this
void main() {
group('MyWidget Tests', () {
testWidgets('Test Case 1', (WidgetTester tester) async {
// Your test case code here
});
testWidgets('Test Case 2', (WidgetTester tester) async {
// Your test case code here
});
}
It would be easier to segregate if we add more tests in future
@SankethBK should I make helper functions for widgets tests and store them somewhere else for better readability?
eg:
void main() {
group('MyWidget Tests', () {
testWidgets('Test Case 1', (WidgetTester tester) async {
await testTestCase1(tester);
});
testWidgets('Test Case 2', (WidgetTester tester) async {
await testTestCase2(tester);
});
});
}
@SankethBK should I make helper functions for widgets tests and store them somewhere else for better readability?
eg:
void main() { group('MyWidget Tests', () { testWidgets('Test Case 1', (WidgetTester tester) async { await testTestCase1(tester); }); testWidgets('Test Case 2', (WidgetTester tester) async { await testTestCase2(tester); }); }); }
@PratyushChauhan not required, we can do that in future if all tests have lot of repeated code
@SankethBK tried to merge tests into one file, encountered some problems which i think might be relating to dependecy initialization. Pushed changes for your reference.
Logs:
Second test is starting right where first test was stopped, so its failing. Because its trying to initialize everything again, but they are already initalized
Let's have them in different files only for now, like it was earlier.
pushed refactorings.
Looks good, there is some linter error related to formatting, can you run this command
dart format --line-length 80 .
It will format the files, you can push those changes
got it
checks completed
Always a pleasure.
What type of PR is this? (check all applicable)
Description
Add integration tests
Featured Covered in this PR
Related Tickets & Documents
Screenshots, Recordings
Please replace this line with instructions on how to test your changes, or any screenshots or recording you can attach here.
Tested Feature??