edit_document_test.dart 3.7 KB

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