share_markdown_test.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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 'util/mock/mock_file_picker.dart';
  6. import 'util/util.dart';
  7. void main() {
  8. IntegrationTestWidgetsFlutterBinding.ensureInitialized();
  9. group('share markdown in document page', () {
  10. const location = 'markdown';
  11. setUp(() async {
  12. await TestFolder.cleanTestLocation(location);
  13. await TestFolder.setTestLocation(location);
  14. });
  15. tearDown(() async {
  16. await TestFolder.cleanTestLocation(location);
  17. });
  18. tearDownAll(() async {
  19. await TestFolder.cleanTestLocation(null);
  20. });
  21. testWidgets('click the share button in document page', (tester) async {
  22. await tester.initializeAppFlowy();
  23. await tester.tapGoButton();
  24. // expect to see a readme page
  25. tester.expectToSeePageName(readme);
  26. // mock the file picker
  27. final path = await mockSaveFilePath(location, 'test.md');
  28. // click the share button and select markdown
  29. await tester.tapShareButton();
  30. await tester.tapMarkdownButton();
  31. // expect to see the success dialog
  32. tester.expectToExportSuccess();
  33. final file = File(path);
  34. final isExist = file.existsSync();
  35. expect(isExist, true);
  36. final markdown = file.readAsStringSync();
  37. expect(markdown, expectedMarkdown);
  38. });
  39. testWidgets(
  40. 'share the markdown after renaming the document name',
  41. (tester) async {
  42. await tester.initializeAppFlowy();
  43. await tester.tapGoButton();
  44. // expect to see a readme page
  45. tester.expectToSeePageName(readme);
  46. // rename the document
  47. await tester.hoverOnPageName(readme);
  48. await tester.renamePage('example');
  49. final shareButton = find.byType(ShareActionList);
  50. final shareButtonState =
  51. tester.state(shareButton) as ShareActionListState;
  52. final path =
  53. await mockSaveFilePath(location, '${shareButtonState.name}.md');
  54. // click the share button and select markdown
  55. await tester.tapShareButton();
  56. await tester.tapMarkdownButton();
  57. // expect to see the success dialog
  58. tester.expectToExportSuccess();
  59. final file = File(path);
  60. final isExist = file.existsSync();
  61. expect(isExist, true);
  62. },
  63. );
  64. });
  65. }
  66. const expectedMarkdown = r'''
  67. # Welcome to AppFlowy!
  68. ## Here are the basics
  69. - [ ] Click anywhere and just start typing.
  70. - [ ] Highlight any text, and use the editing menu to _style_ **your** <u>writing</u> `however` you ~~like.~~
  71. - [ ] As soon as you type `/` a menu will pop up. Select different types of content blocks you can add.
  72. - [ ] Type `/` followed by `/bullet` or `/num` to create a list.
  73. - [x] Click `+ New Page `button at the bottom of your sidebar to add a new page.
  74. - [ ] Click `+` next to any page title in the sidebar to quickly add a new subpage, `Document`, `Grid`, or `Kanban Board`.
  75. ---
  76. ## Keyboard shortcuts, markdown, and code block
  77. 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts)
  78. 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown)
  79. 1. Type `/code` to insert a code block
  80. ## Have a question❓
  81. > Click `?` at the bottom right for help and support.
  82. ''';