share_markdown_test.dart 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. // expect to see a readme page
  15. tester.expectToSeePageName(gettingStarted);
  16. // mock the file picker
  17. final path = await mockSaveFilePath(
  18. p.join(context.applicationDataDirectory, 'test.md'),
  19. );
  20. // click the share button and select markdown
  21. await tester.tapShareButton();
  22. await tester.tapMarkdownButton();
  23. // expect to see the success dialog
  24. tester.expectToExportSuccess();
  25. final file = File(path);
  26. final isExist = file.existsSync();
  27. expect(isExist, true);
  28. final markdown = file.readAsStringSync();
  29. expect(markdown, expectedMarkdown);
  30. });
  31. testWidgets(
  32. 'share the markdown after renaming the document name',
  33. (tester) async {
  34. final context = await tester.initializeAppFlowy();
  35. await tester.tapGoButton();
  36. // expect to see a getting started page
  37. tester.expectToSeePageName(gettingStarted);
  38. // rename the document
  39. await tester.hoverOnPageName(
  40. gettingStarted,
  41. onHover: () async {
  42. await tester.renamePage('example');
  43. },
  44. );
  45. final shareButton = find.byType(ShareActionList);
  46. final shareButtonState =
  47. tester.state(shareButton) as ShareActionListState;
  48. final path = await mockSaveFilePath(
  49. p.join(
  50. context.applicationDataDirectory,
  51. '${shareButtonState.name}.md',
  52. ),
  53. );
  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. ```rust
  81. // This is the main function.
  82. fn main() {
  83. // Print text to the console.
  84. println!("Hello World!");
  85. }
  86. ```
  87. ## Have a question❓
  88. > Click `?` at the bottom right for help and support.
  89. ''';