|
| 1 | +import 'package:appflowy_editor/appflowy_editor.dart'; |
| 2 | +import 'package:flutter_test/flutter_test.dart'; |
| 3 | +import '../infra/test_editor.dart'; |
| 4 | + |
| 5 | +void main() async { |
| 6 | + setUpAll(() { |
| 7 | + TestWidgetsFlutterBinding.ensureInitialized(); |
| 8 | + }); |
| 9 | + |
| 10 | + group('selection_service.dart', () { |
| 11 | + testWidgets('Single tap test ', (tester) async { |
| 12 | + const text = 'Welcome to Appflowy 😁'; |
| 13 | + final editor = tester.editor |
| 14 | + ..insertTextNode(text) |
| 15 | + ..insertTextNode(text) |
| 16 | + ..insertTextNode(text); |
| 17 | + await editor.startTesting(); |
| 18 | + |
| 19 | + final secondTextNode = editor.nodeAtPath([1]); |
| 20 | + final finder = find.byKey(secondTextNode!.key!); |
| 21 | + |
| 22 | + final rect = tester.getRect(finder); |
| 23 | + // tap at the beginning |
| 24 | + await tester.tapAt(rect.centerLeft); |
| 25 | + expect( |
| 26 | + editor.documentSelection, |
| 27 | + Selection.single(path: [1], startOffset: 0), |
| 28 | + ); |
| 29 | + |
| 30 | + // tap at the ending |
| 31 | + await tester.tapAt(rect.centerRight); |
| 32 | + expect( |
| 33 | + editor.documentSelection, |
| 34 | + Selection.single(path: [1], startOffset: text.length), |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + testWidgets('Test double tap', (tester) async { |
| 39 | + const text = 'Welcome to Appflowy 😁'; |
| 40 | + final editor = tester.editor |
| 41 | + ..insertTextNode(text) |
| 42 | + ..insertTextNode(text) |
| 43 | + ..insertTextNode(text); |
| 44 | + await editor.startTesting(); |
| 45 | + |
| 46 | + final secondTextNode = editor.nodeAtPath([1]); |
| 47 | + final finder = find.byKey(secondTextNode!.key!); |
| 48 | + |
| 49 | + final rect = tester.getRect(finder); |
| 50 | + // double tap |
| 51 | + await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0)); |
| 52 | + await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0)); |
| 53 | + await tester.pump(); |
| 54 | + expect( |
| 55 | + editor.documentSelection, |
| 56 | + Selection.single(path: [1], startOffset: 0, endOffset: 7), |
| 57 | + ); |
| 58 | + }); |
| 59 | + |
| 60 | + testWidgets('Test triple tap', (tester) async { |
| 61 | + const text = 'Welcome to Appflowy 😁'; |
| 62 | + final editor = tester.editor |
| 63 | + ..insertTextNode(text) |
| 64 | + ..insertTextNode(text) |
| 65 | + ..insertTextNode(text); |
| 66 | + await editor.startTesting(); |
| 67 | + |
| 68 | + final secondTextNode = editor.nodeAtPath([1]); |
| 69 | + final finder = find.byKey(secondTextNode!.key!); |
| 70 | + |
| 71 | + final rect = tester.getRect(finder); |
| 72 | + // triple tap |
| 73 | + await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0)); |
| 74 | + await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0)); |
| 75 | + await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0)); |
| 76 | + await tester.pump(); |
| 77 | + expect( |
| 78 | + editor.documentSelection, |
| 79 | + Selection.single(path: [1], startOffset: 0, endOffset: text.length), |
| 80 | + ); |
| 81 | + }); |
| 82 | + }); |
| 83 | +} |
0 commit comments