-
Notifications
You must be signed in to change notification settings - Fork 987
Description
Hey there flutter-quill team 👋
Thanks for the repo, it is mighty useful!
I'm having a bit of trouble unit/integration testing my SPIKE app that uses flutter-quill, specifically picking an image.
I've already mocked a service that will switch devices at will on my testWidgets, so that is why you'll see it mentioned in the code snippet below.
Here's what I have so far:
testWidgets('Select image', (WidgetTester tester) async {
final platformServiceMock = MockPlatformService();
// Platform is mobile
when(platformServiceMock.isWebPlatform()).thenAnswer((_) => false);
// Build our app and trigger a frame.
await tester.pumpWidget(
App(
platformService: platformServiceMock,
),
);
await tester.pumpAndSettle();
// Expect to find the normal page setup
expect(find.text('Flutter Quill'), findsOneWidget);
// Enter 'hi' into Quill Editor.
await tester.tap(find.byType(QuillEditor));
await tester.quillEnterText(find.byType(QuillEditor), 'hi\n');
await tester.pumpAndSettle();
// Clicks on the image button
final imageButton = find.byType(ImageButton);
await tester.tap(imageButton);
await tester.pumpAndSettle();
// how do I simulate a person choosing an image so I can check it is correctly embedded in the editor?
});I don't know how to "pick an image" now in tests. Since this is a test for a mobile device, I know image_picker is being used in the background.
I've used file_picker before in https://github.com/dwyl/flutter-image-upload-demo and the creators of the package mock the return of the pickFile() function to return a file in their tests. Because flutter_quill uses image_picker and it's "under the hood" of flutter_quill, I'm having a bit of trouble mocking it so I can simulate a person choosing an image.
I've inclusively followed the guide in https://docs.flutter.dev/testing/integration-tests to see the test flow was correct on a real device and it checks out: it opens the image gallery and waits for me to pick an image.
I've tried going over flutter-quill/test/widgets/editor_test.dart and over the example app tests in https://github.com/singerdmx/flutter-quill/blob/master/example/test/widget_test.dart and unfortunately haven't found anything related to this.
Is this even possible? Am I missing something?
Thank you!