document_codeblock_paste_test.dart 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import 'dart:io';
  2. import 'package:appflowy/generated/locale_keys.g.dart';
  3. import 'package:appflowy_editor/appflowy_editor.dart';
  4. import 'package:easy_localization/easy_localization.dart';
  5. import 'package:flutter/services.dart';
  6. import 'package:flutter_test/flutter_test.dart';
  7. import 'package:integration_test/integration_test.dart';
  8. import '../util/util.dart';
  9. void main() {
  10. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  11. group('paste in codeblock', () {
  12. testWidgets('paste multiple lines in codeblock', (tester) async {
  13. await tester.initializeAppFlowy();
  14. await tester.tapGoButton();
  15. // create a new document
  16. await tester.createNewPageWithName();
  17. // mock the clipboard
  18. const lines = 3;
  19. final text = List.generate(lines, (index) => 'line $index').join('\n');
  20. AppFlowyClipboard.mockSetData(
  21. AppFlowyClipboardData(
  22. text: text,
  23. ),
  24. );
  25. await insertCodeBlockInDocument(tester);
  26. // paste the text
  27. await tester.simulateKeyEvent(
  28. LogicalKeyboardKey.keyV,
  29. isControlPressed: Platform.isLinux || Platform.isWindows,
  30. isMetaPressed: Platform.isMacOS,
  31. );
  32. await tester.pumpAndSettle();
  33. final editorState = tester.editor.getCurrentEditorState();
  34. expect(editorState.document.root.children.length, 1);
  35. expect(
  36. editorState.getNodeAtPath([0])!.delta!.toPlainText(),
  37. text,
  38. );
  39. });
  40. });
  41. }
  42. /// Inserts an codeBlock in the document
  43. Future<void> insertCodeBlockInDocument(WidgetTester tester) async {
  44. // open the actions menu and insert the codeBlock
  45. await tester.editor.showSlashMenu();
  46. await tester.editor.tapSlashMenuItemWithName(
  47. LocaleKeys.document_selectionMenu_codeBlock.tr(),
  48. );
  49. await tester.pumpAndSettle();
  50. }