share_markdown_test.dart 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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(readme);
  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 readme page
  37. tester.expectToSeePageName(readme);
  38. // rename the document
  39. await tester.hoverOnPageName(readme);
  40. await tester.renamePage('example');
  41. final shareButton = find.byType(ShareActionList);
  42. final shareButtonState =
  43. tester.state(shareButton) as ShareActionListState;
  44. final path = await mockSaveFilePath(
  45. p.join(
  46. context.applicationDataDirectory,
  47. '${shareButtonState.name}.md',
  48. ),
  49. );
  50. // click the share button and select markdown
  51. await tester.tapShareButton();
  52. await tester.tapMarkdownButton();
  53. // expect to see the success dialog
  54. tester.expectToExportSuccess();
  55. final file = File(path);
  56. final isExist = file.existsSync();
  57. expect(isExist, true);
  58. },
  59. );
  60. });
  61. }
  62. const expectedMarkdown = r'''
  63. # Welcome to AppFlowy!
  64. ## Here are the basics
  65. - [ ] Click anywhere and just start typing.
  66. - [ ] Highlight any text, and use the editing menu to _style_ **your** <u>writing</u> `however` you ~~like.~~
  67. - [ ] As soon as you type `/` a menu will pop up. Select different types of content blocks you can add.
  68. - [ ] Type `/` followed by `/bullet` or `/num` to create a list.
  69. - [x] Click `+ New Page `button at the bottom of your sidebar to add a new page.
  70. - [ ] Click `+` next to any page title in the sidebar to quickly add a new subpage, `Document`, `Grid`, or `Kanban Board`.
  71. ---
  72. ## Keyboard shortcuts, markdown, and code block
  73. 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts)
  74. 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown)
  75. 1. Type `/code` to insert a code block
  76. ## Have a question❓
  77. > Click `?` at the bottom right for help and support.
  78. ''';