Skip to content

Commit 1801a47

Browse files
committed
feat: test update nodes
1 parent 0def48d commit 1801a47

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

shared-lib/lib-ot/tests/main.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use lib_ot::core::{DocumentTree, NodeData, TransactionBuilder};
1+
use lib_ot::core::{DocumentTree, NodeData, Position, TransactionBuilder};
22
use std::collections::HashMap;
33

44
#[test]
@@ -36,7 +36,7 @@ fn test_documents() {
3636
}
3737

3838
#[test]
39-
fn test_transform_paths() {
39+
fn test_inserts_nodes() {
4040
let mut document = DocumentTree::new();
4141
let transaction = {
4242
let mut tb = TransactionBuilder::new(&document);
@@ -54,3 +54,30 @@ fn test_transform_paths() {
5454
};
5555
document.apply(transaction);
5656
}
57+
58+
#[test]
59+
fn test_update_nodes() {
60+
let mut document = DocumentTree::new();
61+
let transaction = {
62+
let mut tb = TransactionBuilder::new(&document);
63+
tb.insert_nodes(&vec![0].into(), &vec![NodeData::new("text")]);
64+
tb.insert_nodes(&vec![1].into(), &vec![NodeData::new("text")]);
65+
tb.insert_nodes(&vec![2].into(), &vec![NodeData::new("text")]);
66+
tb.finalize()
67+
};
68+
document.apply(transaction);
69+
70+
let transaction = {
71+
let mut tb = TransactionBuilder::new(&document);
72+
tb.update_attributes(&vec![1].into(), HashMap::from([
73+
("bolded".into(), Some("true".into())),
74+
]));
75+
tb.finalize()
76+
};
77+
document.apply(transaction);
78+
79+
let node = document.node_at_path(&Position(vec![1])).unwrap();
80+
let node_data = document.arena.get(node).unwrap().get();
81+
let is_bold = node_data.attributes.borrow().0.get("bolded").unwrap().clone();
82+
assert_eq!(is_bold.unwrap(), "true");
83+
}

0 commit comments

Comments
 (0)