Explorar o código

chore: udpate test

appflowy %!s(int64=2) %!d(string=hai) anos
pai
achega
e711bfce1d

+ 1 - 1
shared-lib/lib-ot/src/core/document/document.rs

@@ -84,7 +84,7 @@ impl DocumentTree {
         counter
     }
 
-    fn child_at_index_of_path(&self, at_node: NodeId, index: usize) -> Option<NodeId> {
+    pub fn child_at_index_of_path(&self, at_node: NodeId, index: usize) -> Option<NodeId> {
         let children = at_node.children(&self.arena);
 
         for (counter, child) in children.enumerate() {

+ 13 - 1
shared-lib/lib-ot/tests/main.rs

@@ -1,4 +1,4 @@
-use lib_ot::core::{DocumentTree, NodeAttributes, NodeSubTree, Path, TransactionBuilder};
+use lib_ot::core::{DocumentOperation, DocumentTree, NodeAttributes, NodeSubTree, Path, TransactionBuilder};
 use lib_ot::errors::OTErrorCode;
 use std::collections::HashMap;
 
@@ -85,6 +85,18 @@ fn test_inserts_subtrees() {
     assert_eq!(data.node_type, "image");
 }
 
+#[test]
+fn test_insert_node() {
+    let node = NodeSubTree::new("text");
+    let root_path: Path = vec![0].into();
+    let op = DocumentOperation::Insert {path: root_path.clone(),nodes: vec![node.clone()] };
+    let mut document = DocumentTree::new();
+    document.apply_op(&op).unwrap();
+    let node_id = document.node_at_path(&root_path).unwrap();
+
+    assert!(document.child_at_index_of_path(node_id, 0).is_some());
+}
+
 #[test]
 fn test_update_nodes() {
     let mut document = DocumentTree::new();