editor_test_operations.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:appflowy_editor/appflowy_editor.dart' hide Log;
  2. import 'package:flutter_test/flutter_test.dart';
  3. import 'ime.dart';
  4. import 'util.dart';
  5. extension EditorWidgetTester on WidgetTester {
  6. EditorOperations get editor => EditorOperations(this);
  7. }
  8. class EditorOperations {
  9. const EditorOperations(this.tester);
  10. final WidgetTester tester;
  11. EditorState getCurrentEditorState() {
  12. return tester
  13. .widget<AppFlowyEditor>(find.byType(AppFlowyEditor))
  14. .editorState;
  15. }
  16. /// Tap the line of editor at [index]
  17. Future<void> tapLineOfEditorAt(int index) async {
  18. final textBlocks = find.byType(TextBlockComponentWidget);
  19. await tester.tapAt(tester.getTopRight(textBlocks.at(index)));
  20. }
  21. /// Hover on cover plugin button above the document
  22. Future<void> hoverOnCoverPluginAddButton() async {
  23. final editor = find.byWidgetPredicate(
  24. (widget) => widget is AppFlowyEditor,
  25. );
  26. await tester.hoverOnWidget(
  27. editor,
  28. offset: tester.getTopLeft(editor).translate(20, 20),
  29. );
  30. }
  31. /// trigger the slash command (selection menu)
  32. Future<void> showSlashMenu() async {
  33. await tester.ime.insertCharacter('/');
  34. }
  35. /// Tap the slash menu item with [name]
  36. ///
  37. /// Must call [showSlashMenu] first.
  38. Future<void> tapSlashMenuItemWithName(String name) async {
  39. final slashMenuItem = find.text(name, findRichText: true);
  40. await tester.tapButton(slashMenuItem);
  41. }
  42. }