share_markdown_test.dart 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. import 'dart:io';
  2. import 'package:appflowy/plugins/document/presentation/share/share_button.dart';
  3. import 'package:flutter_test/flutter_test.dart';
  4. import 'package:integration_test/integration_test.dart';
  5. import 'package:path/path.dart' as p;
  6. import 'util/mock/mock_file_picker.dart';
  7. import 'util/util.dart';
  8. void main() {
  9. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  10. group('share markdown in document page', () {
  11. testWidgets('click the share button in document page', (tester) async {
  12. final context = await tester.initializeAppFlowy();
  13. await tester.tapGoButton();
  14. // mock the file picker
  15. final path = await mockSaveFilePath(
  16. p.join(context.applicationDataDirectory, 'test.md'),
  17. );
  18. // click the share button and select markdown
  19. await tester.tapShareButton();
  20. await tester.tapMarkdownButton();
  21. // expect to see the success dialog
  22. tester.expectToExportSuccess();
  23. final file = File(path);
  24. final isExist = file.existsSync();
  25. expect(isExist, true);
  26. final markdown = file.readAsStringSync();
  27. expect(markdown, expectedMarkdown);
  28. });
  29. testWidgets(
  30. 'share the markdown after renaming the document name',
  31. (tester) async {
  32. final context = await tester.initializeAppFlowy();
  33. await tester.tapGoButton();
  34. // expect to see a getting started page
  35. tester.expectToSeePageName(gettingStarted);
  36. // rename the document
  37. await tester.hoverOnPageName(
  38. gettingStarted,
  39. onHover: () async {
  40. await tester.renamePage('example');
  41. },
  42. );
  43. final shareButton = find.byType(ShareActionList);
  44. final shareButtonState =
  45. tester.state(shareButton) as ShareActionListState;
  46. final path = await mockSaveFilePath(
  47. p.join(
  48. context.applicationDataDirectory,
  49. '${shareButtonState.name}.md',
  50. ),
  51. );
  52. // click the share button and select markdown
  53. await tester.tapShareButton();
  54. await tester.tapMarkdownButton();
  55. // expect to see the success dialog
  56. tester.expectToExportSuccess();
  57. final file = File(path);
  58. final isExist = file.existsSync();
  59. expect(isExist, true);
  60. },
  61. );
  62. });
  63. }
  64. const expectedMarkdown = '''
  65. # Welcome to AppFlowy!
  66. ## Here are the basics
  67. - [ ] Click anywhere and just start typing.
  68. - [ ] Highlight any text, and use the editing menu to _style_ **your** <u>writing</u> `however` you ~~like.~~
  69. - [ ] As soon as you type `/` a menu will pop up. Select different types of content blocks you can add.
  70. - [ ] Type `/` followed by `/bullet` or `/num` to create a list.
  71. - [x] Click `+ New Page `button at the bottom of your sidebar to add a new page.
  72. - [ ] Click `+` next to any page title in the sidebar to quickly add a new subpage, `Document`, `Grid`, or `Kanban Board`.
  73. ---
  74. ## Keyboard shortcuts, markdown, and code block
  75. 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts)
  76. 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown)
  77. 1. Type `/code` to insert a code block
  78. ```rust
  79. // This is the main function.
  80. fn main() {
  81. // Print text to the console.
  82. println!("Hello World!");
  83. }
  84. ```
  85. ## Have a question❓
  86. > Click `?` at the bottom right for help and support.
  87. > 🥰
  88. >
  89. > Like AppFlowy? Follow us:
  90. > [GitHub](https://github.com/AppFlowy-IO/AppFlowy)
  91. > [Twitter](https://twitter.com/appflowy): @appflowy
  92. > [Newsletter](https://blog-appflowy.ghost.io/)
  93. >
  94. ''';