flutter_quill_test 11.1.0 copy "flutter_quill_test: ^11.1.0" to clipboard
flutter_quill_test: ^11.1.0 copied to clipboard

Test utilities for flutter_quill which includes methods to simplify interacting with the editor in test cases.

πŸ“ Flutter Quill Test #

Test utilities for flutter_quill which include methods to simplify interacting with the editor in test cases.

πŸ“š Table of contents #

πŸ’Ύ Installation #

Add the dependencies flutter_test and flutter_quill_test:

flutter pub add 'dev:flutter_test:{"sdk":"flutter"}'
flutter pub add dev:flutter_quill_test
copied to clipboard

πŸ§ͺ Testing #

To aid in testing applications using the editor an extension to the flutter WidgetTester is provided which includes methods to simplify interacting with the editor in test cases.

πŸ› οΈ Utilities #

This package provides a set of utilities to simplify testing with the QuillEditor.

First, import the test utilities in your test file:

import 'package:flutter_quill_test/flutter_quill_test.dart';
copied to clipboard

Usage #

Entering Text

To enter text into the QuillEditor, use the quillEnterText method:

await tester.quillEnterText(find.byType(QuillEditor), 'test\n');
copied to clipboard

Replacing Text

You can replace text in the QuillEditor using the quillReplaceText method:

await tester.quillReplaceText(find.byType(QuillEditor), 'text to be used for replace');
copied to clipboard

Removing Text

To remove text from the QuillEditor, you can use the quillRemoveText method:

await tester.quillRemoveText(
  find.byType(QuillEditor),
  TextSelection(baseOffset: 2, extentOffset: 3),
);
copied to clipboard

Moving the Cursor

To change the selection values into the QuillEditor without use the QuillController, use the quillUpdateSelection method:

await tester.quillUpdateSelection(find.byType(QuillEditor), 0, 10);
copied to clipboard

Full Example

Here’s a complete example of how you might use these utilities in a test:

import 'package:flutter_test/flutter_test.dart';
import 'package:flutter_quill/flutter_quill.dart';
import 'package:flutter_quill_test/flutter_quill_test.dart';

void main() {
  testWidgets('Example QuillEditor test', (WidgetTester tester) async {
    final QuillController controller = QuillController.basic();
    await tester.pumpWidget(
      MaterialApp(
        home: QuillEditor.basic(
          controller: controller,
          config: const QuillEditorConfig(),
        ),
      ),
    );

    await tester.tap(find.byType(QuillEditor));
    await tester.quillEnterText(find.byType(QuillEditor), 'Hello, World!\n');
    expect(controller.document.toPlainText(), 'Hello, World!\n');

    await tester.quillMoveCursorTo(find.byType(QuillEditor), 12);
    await tester.quillExpandSelectionTo(find.byType(QuillEditor), 13);

    await tester.quillReplaceText(find.byType(QuillEditor), ' and hi, World!');
    expect(controller.document.toPlainText(), 'Hello, World and hi, World!\n');

    await tester.quillMoveCursorTo(find.byType(QuillEditor), 0);
    await tester.quillExpandSelectionTo(find.byType(QuillEditor), 7);

    await tester.quillRemoveTextInSelection(find.byType(QuillEditor));
    expect(controller.document.toPlainText(), 'World and hi, World!\n');
  });
}
copied to clipboard

🀝 Contributing #

We greatly appreciate your time and effort.

To keep the project consistent and maintainable, we have a few guidelines that we ask all contributors to follow. These guidelines help ensure that everyone can understand and work with the code easier.

See Contributing for more details.

5
likes
150
points
4.95k
downloads

Publisher

verified publisherfreshplatform.net

Weekly Downloads

2024.09.26 - 2025.04.10

Test utilities for flutter_quill which includes methods to simplify interacting with the editor in test cases.

Repository (GitHub)
View/report issues
Contributing

Topics

#testing #text #rich-text-editor #flutter-quill

Documentation

Documentation
API reference

License

MIT (license)

Dependencies

flutter, flutter_quill, flutter_test

More

Packages that depend on flutter_quill_test