editor_test_operations.dart 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. /// Tap the line of editor at [index]
  12. Future<void> tapLineOfEditorAt(int index) async {
  13. final textBlocks = find.byType(TextBlockComponentWidget);
  14. await tester.tapAt(tester.getTopRight(textBlocks.at(index)));
  15. }
  16. /// Hover on cover plugin button above the document
  17. Future<void> hoverOnCoverPluginAddButton() async {
  18. final editor = find.byWidgetPredicate(
  19. (widget) => widget is AppFlowyEditor,
  20. );
  21. await tester.hoverOnWidget(
  22. editor,
  23. offset: tester.getTopLeft(editor).translate(20, 20),
  24. );
  25. }
  26. /// trigger the slash command (selection menu)
  27. Future<void> showSlashMenu() async {
  28. await tester.ime.insertCharacter('/');
  29. }
  30. /// Tap the slash menu item with [name]
  31. ///
  32. /// Must call [showSlashMenu] first.
  33. Future<void> tapSlashMenuItemWithName(String name) async {
  34. final slashMenuItem = find.text(name, findRichText: true);
  35. await tester.tapButton(slashMenuItem);
  36. }
  37. }