edit_document_test.dart 3.6 KB

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