| 
									
										
										
										
											2023-08-30 17:21:32 +08:00
										 |  |  | import 'package:appflowy/generated/flowy_svgs.g.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-09 18:57:08 +05:30
										 |  |  | import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-30 17:21:32 +08:00
										 |  |  | import 'package:appflowy_editor/appflowy_editor.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-09 18:57:08 +05:30
										 |  |  | import 'package:flutter/services.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-30 17:21:32 +08:00
										 |  |  | import 'package:flutter_test/flutter_test.dart'; | 
					
						
							|  |  |  | import 'package:integration_test/integration_test.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-09 18:57:08 +05:30
										 |  |  | import '../util/keyboard.dart'; | 
					
						
							| 
									
										
										
										
											2023-08-30 17:21:32 +08:00
										 |  |  | import '../util/util.dart'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void main() { | 
					
						
							|  |  |  |   IntegrationTestWidgetsFlutterBinding.ensureInitialized(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   group('document alignment', () { | 
					
						
							|  |  |  |     testWidgets('edit alignment in toolbar', (tester) async { | 
					
						
							|  |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       final selection = Selection.single( | 
					
						
							|  |  |  |         path: [0], | 
					
						
							|  |  |  |         startOffset: 0, | 
					
						
							|  |  |  |         endOffset: 1, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       // click the first line of the readme
 | 
					
						
							|  |  |  |       await tester.editor.tapLineOfEditorAt(0); | 
					
						
							|  |  |  |       await tester.editor.updateSelection(selection); | 
					
						
							|  |  |  |       await tester.pumpAndSettle(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // click the align center
 | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_left_s); | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_center_s); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // expect to see the align center
 | 
					
						
							|  |  |  |       final editorState = tester.editor.getCurrentEditorState(); | 
					
						
							|  |  |  |       final first = editorState.getNodeAtPath([0])!; | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], 'center'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // click the align right
 | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_center_s); | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_right_s); | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], 'right'); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // click the align left
 | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_right_s); | 
					
						
							|  |  |  |       await tester.tapButtonWithFlowySvgData(FlowySvgs.toolbar_align_left_s); | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], 'left'); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2024-01-09 18:57:08 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |     testWidgets('edit alignment using shortcut', (tester) async { | 
					
						
							|  |  |  |       await tester.initializeAppFlowy(); | 
					
						
							|  |  |  |       await tester.tapGoButton(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // click the first line of the readme
 | 
					
						
							|  |  |  |       await tester.editor.tapLineOfEditorAt(0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       await tester.pumpAndSettle(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       final editorState = tester.editor.getCurrentEditorState(); | 
					
						
							|  |  |  |       final first = editorState.getNodeAtPath([0])!; | 
					
						
							|  |  |  |        | 
					
						
							|  |  |  |       // expect to see text aligned to the right
 | 
					
						
							|  |  |  |       await FlowyTestKeyboard.simulateKeyDownEvent( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           LogicalKeyboardKey.control, | 
					
						
							|  |  |  |           LogicalKeyboardKey.shift, | 
					
						
							|  |  |  |           LogicalKeyboardKey.keyR, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         tester: tester, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], rightAlignmentKey); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // expect to see text aligned to the center
 | 
					
						
							|  |  |  |       await FlowyTestKeyboard.simulateKeyDownEvent( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           LogicalKeyboardKey.control, | 
					
						
							|  |  |  |           LogicalKeyboardKey.shift, | 
					
						
							|  |  |  |           LogicalKeyboardKey.keyE, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         tester: tester, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], centerAlignmentKey); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       // expect to see text aligned to the left
 | 
					
						
							|  |  |  |       await FlowyTestKeyboard.simulateKeyDownEvent( | 
					
						
							|  |  |  |         [ | 
					
						
							|  |  |  |           LogicalKeyboardKey.control, | 
					
						
							|  |  |  |           LogicalKeyboardKey.shift, | 
					
						
							|  |  |  |           LogicalKeyboardKey.keyL, | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         tester: tester, | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |       expect(first.attributes[blockComponentAlign], leftAlignmentKey); | 
					
						
							|  |  |  |     }); | 
					
						
							| 
									
										
										
										
											2023-08-30 17:21:32 +08:00
										 |  |  |   }); | 
					
						
							|  |  |  | } |