parent
97fd404618
commit
2283bd7278
2 changed files with 83 additions and 0 deletions
@ -0,0 +1,52 @@ |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_quill/src/widgets/editor.dart'; |
||||
import 'package:flutter_quill/src/widgets/raw_editor.dart'; |
||||
import 'package:flutter_test/flutter_test.dart'; |
||||
|
||||
extension QuillEnterText on WidgetTester { |
||||
/// Give the QuillEditor widget specified by [finder] the focus. |
||||
Future<void> quillGiveFocus(Finder finder) { |
||||
return TestAsyncUtils.guard(() async { |
||||
final editor = state<QuillEditorState>( |
||||
find.descendant( |
||||
of: finder, |
||||
matching: |
||||
find.byType(QuillEditor, skipOffstage: finder.skipOffstage), |
||||
matchRoot: true), |
||||
); |
||||
editor.widget.focusNode.requestFocus(); |
||||
await pump(); |
||||
expect(editor.widget.focusNode.hasFocus, isTrue); |
||||
}); |
||||
} |
||||
|
||||
/// Give the QuillEditor widget specified by [finder] the focus and update its |
||||
/// editing value with [text], as if it had been provided by the onscreen |
||||
/// keyboard. |
||||
/// |
||||
/// The widget specified by [finder] must be a [QuillEditor] or have a |
||||
/// [QuillEditor] descendant. For example `find.byType(QuillEditor)`. |
||||
Future<void> quillEnterText(Finder finder, String text) async { |
||||
return TestAsyncUtils.guard(() async { |
||||
await quillGiveFocus(finder); |
||||
await updateEditingValue(finder, text); |
||||
await idle(); |
||||
}); |
||||
} |
||||
|
||||
Future<void> updateEditingValue(Finder finder, String text) async { |
||||
return TestAsyncUtils.guard(() async { |
||||
final editor = state<RawEditorState>( |
||||
find.descendant( |
||||
of: finder, |
||||
matching: find.byType(RawEditor, skipOffstage: finder.skipOffstage), |
||||
matchRoot: true), |
||||
); |
||||
testTextInput.updateEditingValue(TextEditingValue( |
||||
text: text, |
||||
selection: TextSelection.collapsed( |
||||
offset: editor.textEditingValue.text.length))); |
||||
await idle(); |
||||
}); |
||||
} |
||||
} |
@ -0,0 +1,31 @@ |
||||
import 'package:flutter/material.dart'; |
||||
import 'package:flutter_quill/src/widgets/controller.dart'; |
||||
import 'package:flutter_quill/src/widgets/editor.dart'; |
||||
import 'package:flutter_test/flutter_test.dart'; |
||||
|
||||
import '../widget_tester_extension.dart'; |
||||
|
||||
void main() { |
||||
late QuillController controller; |
||||
|
||||
setUp(() { |
||||
controller = QuillController.basic(); |
||||
}); |
||||
|
||||
tearDown(() { |
||||
controller.dispose(); |
||||
}); |
||||
|
||||
group('QuillEditor', () { |
||||
testWidgets('Keyboard entered text is stored in document', (tester) async { |
||||
await tester.pumpWidget( |
||||
MaterialApp( |
||||
home: QuillEditor.basic(controller: controller, readOnly: false), |
||||
), |
||||
); |
||||
await tester.quillEnterText(find.byType(QuillEditor), 'test\n'); |
||||
|
||||
expect(controller.document.toPlainText(), 'test\n'); |
||||
}); |
||||
}); |
||||
} |
Loading…
Reference in new issue