Ver Fonte

test: node tests

Enzo Lizama há 2 anos atrás
pai
commit
bfe61ea09d

+ 35 - 9
frontend/app_flowy/packages/appflowy_editor/test/extensions/node_extension_test.dart

@@ -1,3 +1,4 @@
+import 'dart:collection';
 import 'dart:ui';
 
 import 'package:appflowy_editor/appflowy_editor.dart';
@@ -8,12 +9,12 @@ import 'package:appflowy_editor/src/extensions/node_extensions.dart';
 class MockNode extends Mock implements Node {}
 
 void main() {
-  group('NodeExtensions::', () {
-    final mockNode = MockNode();
+  final mockNode = MockNode();
 
+  group('NodeExtensions::', () {
     final selection = Selection(
-      start: Position(path: [0, 1]),
-      end: Position(path: [1, 0]),
+      start: Position(path: [0]),
+      end: Position(path: [1]),
     );
 
     test('rect - renderBox is null', () {
@@ -22,10 +23,35 @@ void main() {
       expect(result, Rect.zero);
     });
 
-    // test('inSelection', () {
-    //   when(mockNode.path).thenAnswer((_) => [3, 3]);
-    //   final result = mockNode.inSelection(selection);
-    //   expect(result, true);
-    // });
+    test('inSelection', () {
+      // I use an empty implementation instead of mock, because the mocked
+      // version throws error trying to access the path.
+
+      final subLinkedList = LinkedList<Node>()
+        ..addAll([
+          Node(type: 'type', children: LinkedList(), attributes: {}),
+          Node(type: 'type', children: LinkedList(), attributes: {}),
+          Node(type: 'type', children: LinkedList(), attributes: {}),
+          Node(type: 'type', children: LinkedList(), attributes: {}),
+          Node(type: 'type', children: LinkedList(), attributes: {}),
+        ]);
+
+      final linkedList = LinkedList<Node>()
+        ..addAll([
+          Node(
+            type: 'type',
+            children: subLinkedList,
+            attributes: {},
+          ),
+        ]);
+
+      final node = Node(
+        type: 'type',
+        children: linkedList,
+        attributes: {},
+      );
+      final result = node.inSelection(selection);
+      expect(result, false);
+    });
   });
 }