edit_document_test.dart 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import 'dart:io';
  2. import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart';
  3. import 'package:appflowy_editor/appflowy_editor.dart';
  4. import 'package:flutter/services.dart';
  5. import 'package:flutter_test/flutter_test.dart';
  6. import 'package:integration_test/integration_test.dart';
  7. import '../util/ime.dart';
  8. import '../util/util.dart';
  9. void main() {
  10. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  11. group('edit document', () {
  12. const location = 'appflowy';
  13. setUp(() async {
  14. await TestFolder.cleanTestLocation(location);
  15. await TestFolder.setTestLocation(location);
  16. });
  17. tearDown(() async {
  18. await TestFolder.cleanTestLocation(null);
  19. });
  20. testWidgets('redo & undo', (tester) async {
  21. await tester.initializeAppFlowy();
  22. await tester.tapGoButton();
  23. // create a new document called Sample
  24. const pageName = 'Sample';
  25. await tester.createNewPageWithName(ViewLayoutPB.Document, pageName);
  26. // focus on the editor
  27. await tester.editor.tapLineOfEditorAt(0);
  28. // insert 1. to trigger it to be a numbered list
  29. await tester.ime.insertText('1. ');
  30. expect(find.text('1.', findRichText: true), findsOneWidget);
  31. expect(
  32. tester.editor.getCurrentEditorState().getNodeAtPath([0])!.type,
  33. NumberedListBlockKeys.type,
  34. );
  35. // undo
  36. // numbered list will be reverted to paragraph
  37. await tester.simulateKeyEvent(
  38. LogicalKeyboardKey.keyZ,
  39. isControlPressed: Platform.isWindows || Platform.isLinux,
  40. isMetaPressed: Platform.isMacOS,
  41. );
  42. expect(
  43. tester.editor.getCurrentEditorState().getNodeAtPath([0])!.type,
  44. ParagraphBlockKeys.type,
  45. );
  46. // redo
  47. await tester.simulateKeyEvent(
  48. LogicalKeyboardKey.keyZ,
  49. isControlPressed: Platform.isWindows || Platform.isLinux,
  50. isMetaPressed: Platform.isMacOS,
  51. isShiftPressed: true,
  52. );
  53. expect(
  54. tester.editor.getCurrentEditorState().getNodeAtPath([0])!.type,
  55. NumberedListBlockKeys.type,
  56. );
  57. // switch to other page and switch back
  58. await tester.openPage(readme);
  59. await tester.openPage(pageName);
  60. // the numbered list should be kept
  61. expect(
  62. tester.editor.getCurrentEditorState().getNodeAtPath([0])!.type,
  63. NumberedListBlockKeys.type,
  64. );
  65. });
  66. testWidgets('write a readme document', (tester) async {
  67. await tester.initializeAppFlowy();
  68. await tester.tapGoButton();
  69. // create a new document called Sample
  70. const pageName = 'Sample';
  71. await tester.createNewPageWithName(ViewLayoutPB.Document, pageName);
  72. // focus on the editor
  73. await tester.editor.tapLineOfEditorAt(0);
  74. // mock inputting the sample
  75. final lines = _sample.split('\n');
  76. for (final line in lines) {
  77. await tester.ime.insertText(line);
  78. await tester.ime.insertCharacter('\n');
  79. }
  80. // switch to other page and switch back
  81. await tester.openPage(readme);
  82. await tester.openPage(pageName);
  83. // this screenshots are different on different platform, so comment it out temporarily.
  84. // check the document
  85. // await expectLater(
  86. // find.byType(AppFlowyEditor),
  87. // matchesGoldenFile('document/edit_document_test.png'),
  88. // );
  89. });
  90. });
  91. }
  92. // TODO(Lucas.Xu): there're no shorctcuts for underline, format code yet.
  93. const _sample = r'''
  94. # Heading 1
  95. ## Heading 2
  96. ### Heading 3
  97. ---
  98. [] Highlight any text, and use the editing menu to _style_ **your** writing `however` you ~~like.~~
  99. [] Type followed by bullet or num to create a list.
  100. [x] Click `+ New Page` button at the bottom of your sidebar to add a new page.
  101. [] Click `+` next to any page title in the sidebar to quickly add a new subpage, `Document`, `Grid`, or `Kanban Board`.
  102. ---
  103. * bulleted list 1
  104. * bulleted list 2
  105. * bulleted list 3
  106. bulleted list 4
  107. ---
  108. 1. numbered list 1
  109. 2. numbered list 2
  110. 3. numbered list 3
  111. numbered list 4
  112. ---
  113. " quote''';