| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  | import 'dart:io'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/share/share_button.dart'; | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  | import 'package:flutter_test/flutter_test.dart'; | 
					
						
							|  |  |  | import 'package:integration_test/integration_test.dart'; | 
					
						
							| 
									
										
										
										
											2023-07-02 23:37:30 +08:00
										 |  |  | import 'package:path/path.dart' as p; | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  | import 'util/mock/mock_file_picker.dart'; | 
					
						
							|  |  |  | import 'util/util.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void main() { | 
					
						
							|  |  |  |   IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   group('share markdown in document page', () { | 
					
						
							|  |  |  |     testWidgets('click the share button in document page', (tester) async { | 
					
						
							| 
									
										
										
										
											2023-07-02 23:37:30 +08:00
										 |  |  |       final context = await tester.initializeAppFlowy(); | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // expect to see a readme page
 | 
					
						
							| 
									
										
										
										
											2023-08-08 07:09:17 +02:00
										 |  |  |       tester.expectToSeePageName(gettingStarted); | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |       // mock the file picker
 | 
					
						
							| 
									
										
										
										
											2023-07-02 23:37:30 +08:00
										 |  |  |       final path = await mockSaveFilePath( | 
					
						
							|  |  |  |         p.join(context.applicationDataDirectory, 'test.md'), | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  |       // click the share button and select markdown
 | 
					
						
							|  |  |  |       await tester.tapShareButton(); | 
					
						
							|  |  |  |       await tester.tapMarkdownButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // expect to see the success dialog
 | 
					
						
							|  |  |  |       tester.expectToExportSuccess(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       final file = File(path); | 
					
						
							|  |  |  |       final isExist = file.existsSync(); | 
					
						
							|  |  |  |       expect(isExist, true); | 
					
						
							|  |  |  |       final markdown = file.readAsStringSync(); | 
					
						
							|  |  |  |       expect(markdown, expectedMarkdown); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     testWidgets( | 
					
						
							|  |  |  |       'share the markdown after renaming the document name', | 
					
						
							|  |  |  |       (tester) async { | 
					
						
							| 
									
										
										
										
											2023-07-02 23:37:30 +08:00
										 |  |  |         final context = await tester.initializeAppFlowy(); | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  |         await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |         // expect to see a getting started page
 | 
					
						
							| 
									
										
										
										
											2023-08-08 07:09:17 +02:00
										 |  |  |         tester.expectToSeePageName(gettingStarted); | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // rename the document
 | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |         await tester.hoverOnPageName( | 
					
						
							| 
									
										
										
										
											2023-08-08 07:09:17 +02:00
										 |  |  |           gettingStarted, | 
					
						
							| 
									
										
										
										
											2023-07-31 19:06:01 +07:00
										 |  |  |           onHover: () async { | 
					
						
							|  |  |  |             await tester.renamePage('example'); | 
					
						
							|  |  |  |           }, | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         final shareButton = find.byType(ShareActionList); | 
					
						
							|  |  |  |         final shareButtonState = | 
					
						
							|  |  |  |             tester.state(shareButton) as ShareActionListState; | 
					
						
							| 
									
										
										
										
											2023-07-02 23:37:30 +08:00
										 |  |  |         final path = await mockSaveFilePath( | 
					
						
							|  |  |  |           p.join( | 
					
						
							|  |  |  |             context.applicationDataDirectory, | 
					
						
							|  |  |  |             '${shareButtonState.name}.md', | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2023-06-12 14:29:09 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |         // click the share button and select markdown
 | 
					
						
							|  |  |  |         await tester.tapShareButton(); | 
					
						
							|  |  |  |         await tester.tapMarkdownButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         // expect to see the success dialog
 | 
					
						
							|  |  |  |         tester.expectToExportSuccess(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         final file = File(path); | 
					
						
							|  |  |  |         final isExist = file.existsSync(); | 
					
						
							|  |  |  |         expect(isExist, true); | 
					
						
							|  |  |  |       }, | 
					
						
							|  |  |  |     ); | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const expectedMarkdown = r''' | 
					
						
							|  |  |  | # Welcome to AppFlowy! | 
					
						
							|  |  |  | ## Here are the basics | 
					
						
							|  |  |  | - [ ] Click anywhere and just start typing. | 
					
						
							|  |  |  | - [ ] Highlight any text, and use the editing menu to _style_ **your** <u>writing</u> `however` you ~~like.~~ | 
					
						
							|  |  |  | - [ ] As soon as you type `/` a menu will pop up. Select different types of content blocks you can add. | 
					
						
							|  |  |  | - [ ] Type `/` followed by `/bullet` or `/num` to create a list. | 
					
						
							|  |  |  | - [x] Click `+ New Page `button at the bottom of your sidebar to add a new page. | 
					
						
							|  |  |  | - [ ] Click `+` next to any page title in the sidebar to quickly add a new subpage, `Document`, `Grid`, or `Kanban Board`. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | --- | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ## Keyboard shortcuts, markdown, and code block | 
					
						
							|  |  |  | 1. Keyboard shortcuts [guide](https://appflowy.gitbook.io/docs/essential-documentation/shortcuts)
 | 
					
						
							|  |  |  | 1. Markdown [reference](https://appflowy.gitbook.io/docs/essential-documentation/markdown)
 | 
					
						
							|  |  |  | 1. Type `/code` to insert a code block | 
					
						
							| 
									
										
										
										
											2023-08-10 17:35:27 +07:00
										 |  |  | ```rust | 
					
						
							|  |  |  | // This is the main function.
 | 
					
						
							|  |  |  | fn main() { | 
					
						
							|  |  |  |     // Print text to the console.
 | 
					
						
							|  |  |  |     println!("Hello World!"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | ``` | 
					
						
							| 
									
										
										
										
											2023-06-10 22:38:25 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | ## Have a question❓ | 
					
						
							|  |  |  | > Click `?` at the bottom right for help and support. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ''';
 |