Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

test: add single/double/triple tap test

Lucas.Xua371cf3a7c26
diff --git a/frontend/app_flowy/packages/appflowy_editor/test/service/selection_service_test.dart b/frontend/app_flowy/packages/appflowy_editor/test/service/selection_service_test.dart
new file mode 100644
index 0000000000..e0b97bbc45
--- /dev/null
+++ b/frontend/app_flowy/packages/appflowy_editor/test/service/selection_service_test.dart
@@ -0,0 +1,83 @@
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter_test/flutter_test.dart';
+import '../infra/test_editor.dart';
+
+void main() async {
+ setUpAll(() {
+ TestWidgetsFlutterBinding.ensureInitialized();
+ });
+
+ group('selection_service.dart', () {
+ testWidgets('Single tap test ', (tester) async {
+ const text = 'Welcome to Appflowy 😁';
+ final editor = tester.editor
+ ..insertTextNode(text)
+ ..insertTextNode(text)
+ ..insertTextNode(text);
+ await editor.startTesting();
+
+ final secondTextNode = editor.nodeAtPath([1]);
+ final finder = find.byKey(secondTextNode!.key!);
+
+ final rect = tester.getRect(finder);
+ // tap at the beginning
+ await tester.tapAt(rect.centerLeft);
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [1], startOffset: 0),
+ );
+
+ // tap at the ending
+ await tester.tapAt(rect.centerRight);
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [1], startOffset: text.length),
+ );
+ });
+
+ testWidgets('Test double tap', (tester) async {
+ const text = 'Welcome to Appflowy 😁';
+ final editor = tester.editor
+ ..insertTextNode(text)
+ ..insertTextNode(text)
+ ..insertTextNode(text);
+ await editor.startTesting();
+
+ final secondTextNode = editor.nodeAtPath([1]);
+ final finder = find.byKey(secondTextNode!.key!);
+
+ final rect = tester.getRect(finder);
+ // double tap
+ await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0));
+ await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0));
+ await tester.pump();
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [1], startOffset: 0, endOffset: 7),
+ );
+ });
+
+ testWidgets('Test triple tap', (tester) async {
+ const text = 'Welcome to Appflowy 😁';
+ final editor = tester.editor
+ ..insertTextNode(text)
+ ..insertTextNode(text)
+ ..insertTextNode(text);
+ await editor.startTesting();
+
+ final secondTextNode = editor.nodeAtPath([1]);
+ final finder = find.byKey(secondTextNode!.key!);
+
+ final rect = tester.getRect(finder);
+ // triple tap
+ await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0));
+ await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0));
+ await tester.tapAt(rect.centerLeft + const Offset(10.0, 0.0));
+ await tester.pump();
+ expect(
+ editor.documentSelection,
+ Selection.single(path: [1], startOffset: 0, endOffset: text.length),
+ );
+ });
+ });
+}