|
1 | 1 | import 'dart:io'; |
2 | 2 |
|
| 3 | +import 'package:appflowy/plugins/emoji/emoji_handler.dart'; |
3 | 4 | import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_picker.dart'; |
4 | 5 | import 'package:appflowy_editor/appflowy_editor.dart'; |
5 | 6 | import 'package:appflowy_editor/src/editor/editor_component/service/editor.dart'; |
| 7 | +import 'package:flowy_infra_ui/flowy_infra_ui.dart'; |
6 | 8 | import 'package:flutter/services.dart'; |
7 | 9 | import 'package:flutter_test/flutter_test.dart'; |
8 | 10 | import 'package:integration_test/integration_test.dart'; |
@@ -39,4 +41,114 @@ void main() { |
39 | 41 | expect(find.byType(EmojiSelectionMenu), findsOneWidget); |
40 | 42 | }); |
41 | 43 | }); |
| 44 | + |
| 45 | + group('insert emoji by colon', () { |
| 46 | + Future<void> createNewDocumentAndShowEmojiList(WidgetTester tester) async { |
| 47 | + await tester.initializeAppFlowy(); |
| 48 | + await tester.tapAnonymousSignInButton(); |
| 49 | + await tester.createNewPageWithNameUnderParent(); |
| 50 | + await tester.editor.tapLineOfEditorAt(0); |
| 51 | + await tester.ime.insertText(':'); |
| 52 | + await tester.pumpAndSettle(Duration(seconds: 1)); |
| 53 | + } |
| 54 | + |
| 55 | + testWidgets('insert with click', (tester) async { |
| 56 | + await createNewDocumentAndShowEmojiList(tester); |
| 57 | + |
| 58 | + /// emoji list is showing |
| 59 | + final emojiHandler = find.byType(EmojiHandler); |
| 60 | + expect(emojiHandler, findsOneWidget); |
| 61 | + final emojiButtons = |
| 62 | + find.descendant(of: emojiHandler, matching: find.byType(FlowyButton)); |
| 63 | + final firstTextFinder = find.descendant( |
| 64 | + of: emojiButtons.first, |
| 65 | + matching: find.byType(FlowyText), |
| 66 | + ); |
| 67 | + final emojiText = |
| 68 | + (firstTextFinder.evaluate().first.widget as FlowyText).text; |
| 69 | + |
| 70 | + /// click first emoji item |
| 71 | + await tester.tapButton(emojiButtons.first); |
| 72 | + final firstNode = |
| 73 | + tester.editor.getCurrentEditorState().getNodeAtPath([0])!; |
| 74 | + |
| 75 | + /// except the emoji is in document |
| 76 | + expect(emojiText.contains(firstNode.delta!.toPlainText()), true); |
| 77 | + }); |
| 78 | + |
| 79 | + testWidgets('insert with arrow and enter', (tester) async { |
| 80 | + await createNewDocumentAndShowEmojiList(tester); |
| 81 | + |
| 82 | + /// emoji list is showing |
| 83 | + final emojiHandler = find.byType(EmojiHandler); |
| 84 | + expect(emojiHandler, findsOneWidget); |
| 85 | + final emojiButtons = |
| 86 | + find.descendant(of: emojiHandler, matching: find.byType(FlowyButton)); |
| 87 | + |
| 88 | + /// tap arrow down and arrow up |
| 89 | + await tester.simulateKeyEvent(LogicalKeyboardKey.arrowUp); |
| 90 | + await tester.simulateKeyEvent(LogicalKeyboardKey.arrowDown); |
| 91 | + |
| 92 | + final firstTextFinder = find.descendant( |
| 93 | + of: emojiButtons.first, |
| 94 | + matching: find.byType(FlowyText), |
| 95 | + ); |
| 96 | + final emojiText = |
| 97 | + (firstTextFinder.evaluate().first.widget as FlowyText).text; |
| 98 | + |
| 99 | + /// tap enter |
| 100 | + await tester.simulateKeyEvent(LogicalKeyboardKey.enter); |
| 101 | + final firstNode = |
| 102 | + tester.editor.getCurrentEditorState().getNodeAtPath([0])!; |
| 103 | + |
| 104 | + /// except the emoji is in document |
| 105 | + expect(emojiText.contains(firstNode.delta!.toPlainText()), true); |
| 106 | + }); |
| 107 | + |
| 108 | + testWidgets('insert with searching', (tester) async { |
| 109 | + await createNewDocumentAndShowEmojiList(tester); |
| 110 | + |
| 111 | + /// search for `smiling eyes`, IME is not working, use keyboard input |
| 112 | + final searchText = [ |
| 113 | + LogicalKeyboardKey.keyS, |
| 114 | + LogicalKeyboardKey.keyM, |
| 115 | + LogicalKeyboardKey.keyI, |
| 116 | + LogicalKeyboardKey.keyL, |
| 117 | + LogicalKeyboardKey.keyI, |
| 118 | + LogicalKeyboardKey.keyN, |
| 119 | + LogicalKeyboardKey.keyG, |
| 120 | + LogicalKeyboardKey.space, |
| 121 | + LogicalKeyboardKey.keyE, |
| 122 | + LogicalKeyboardKey.keyY, |
| 123 | + LogicalKeyboardKey.keyE, |
| 124 | + LogicalKeyboardKey.keyS, |
| 125 | + ]; |
| 126 | + |
| 127 | + for (final key in searchText) { |
| 128 | + await tester.simulateKeyEvent(key); |
| 129 | + } |
| 130 | + |
| 131 | + /// tap enter |
| 132 | + await tester.simulateKeyEvent(LogicalKeyboardKey.enter); |
| 133 | + final firstNode = |
| 134 | + tester.editor.getCurrentEditorState().getNodeAtPath([0])!; |
| 135 | + |
| 136 | + /// except the emoji is in document |
| 137 | + expect(firstNode.delta!.toPlainText().contains('😄'), true); |
| 138 | + }); |
| 139 | + |
| 140 | + testWidgets('start searching with sapce', (tester) async { |
| 141 | + await createNewDocumentAndShowEmojiList(tester); |
| 142 | + |
| 143 | + /// emoji list is showing |
| 144 | + final emojiHandler = find.byType(EmojiHandler); |
| 145 | + expect(emojiHandler, findsOneWidget); |
| 146 | + |
| 147 | + /// input space |
| 148 | + await tester.simulateKeyEvent(LogicalKeyboardKey.space); |
| 149 | + |
| 150 | + /// emoji list is dismissed |
| 151 | + expect(emojiHandler, findsNothing); |
| 152 | + }); |
| 153 | + }); |
42 | 154 | } |
0 commit comments