Browse Source

test: add delete node test

Lucas.Xu 2 năm trước cách đây
mục cha
commit
9e4227d3d2

+ 7 - 0
frontend/app_flowy/packages/flowy_editor/assets/document.json

@@ -14,6 +14,13 @@
           "tag": "*"
         },
         "children": [
+          {
+            "type": "text",
+            "attributes": {
+              "text-type": "heading2",
+              "check": true
+            }
+          },
           {
             "type": "text",
             "attributes": {

+ 6 - 3
frontend/app_flowy/packages/flowy_editor/test/flowy_editor_test.dart

@@ -42,19 +42,22 @@ void main() {
     final String response = await rootBundle.loadString('assets/document.json');
     final data = Map<String, Object>.from(json.decode(response));
     final stateTree = StateTree.fromJson(data);
-    final deletedNode = stateTree.delete([1, 0]);
+    final deletedNode = stateTree.delete([1, 1]);
     expect(deletedNode != null, true);
     expect(deletedNode!.attributes['text-type'], 'check-box');
+    final node = stateTree.nodeAtPath([1, 1]);
+    expect(node != null, true);
+    expect(node!.attributes['tag'], '**');
   });
 
   test('update node in state tree', () async {
     final String response = await rootBundle.loadString('assets/document.json');
     final data = Map<String, Object>.from(json.decode(response));
     final stateTree = StateTree.fromJson(data);
-    final attributes = stateTree.update([1, 0], {'text-type': 'heading1'});
+    final attributes = stateTree.update([1, 1], {'text-type': 'heading1'});
     expect(attributes != null, true);
     expect(attributes!['text-type'], 'check-box');
-    final updatedNode = stateTree.nodeAtPath([1, 0]);
+    final updatedNode = stateTree.nodeAtPath([1, 1]);
     expect(updatedNode != null, true);
     expect(updatedNode!.attributes['text-type'], 'heading1');
   });