edit_document_test.dart 3.7 KB

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