mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: test insert sub trees
This commit is contained in:
@ -5,7 +5,10 @@ use crate::core::{NodeAttributes, NodeSubTree, TextDelta};
|
||||
#[serde(tag = "type")]
|
||||
pub enum DocumentOperation {
|
||||
#[serde(rename = "insert-operation")]
|
||||
Insert { path: Position, nodes: Vec<Box<NodeSubTree>> },
|
||||
Insert {
|
||||
path: Position,
|
||||
nodes: Vec<Box<NodeSubTree>>,
|
||||
},
|
||||
#[serde(rename = "update-operation")]
|
||||
Update {
|
||||
path: Position,
|
||||
@ -14,7 +17,10 @@ pub enum DocumentOperation {
|
||||
old_attributes: NodeAttributes,
|
||||
},
|
||||
#[serde(rename = "delete-operation")]
|
||||
Delete { path: Position, nodes: Vec<Box<NodeSubTree>> },
|
||||
Delete {
|
||||
path: Position,
|
||||
nodes: Vec<Box<NodeSubTree>>,
|
||||
},
|
||||
#[serde(rename = "text-edit-operation")]
|
||||
TextEdit {
|
||||
path: Position,
|
||||
@ -160,7 +166,25 @@ mod tests {
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"node_type":"text","attributes":{}}]}"#
|
||||
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{}}]}"#
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_serialize_insert_sub_trees() {
|
||||
let insert = DocumentOperation::Insert {
|
||||
path: Position(vec![0, 1]),
|
||||
nodes: vec![Box::new(NodeSubTree {
|
||||
node_type: "text".into(),
|
||||
attributes: NodeAttributes::new(),
|
||||
delta: None,
|
||||
children: vec![Box::new(NodeSubTree::new("text".into()))],
|
||||
})],
|
||||
};
|
||||
let result = serde_json::to_string(&insert).unwrap();
|
||||
assert_eq!(
|
||||
result,
|
||||
r#"{"type":"insert-operation","path":[0,1],"nodes":[{"type":"text","attributes":{},"children":[{"type":"text","attributes":{}}]}]}"#
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ impl NodeData {
|
||||
|
||||
#[derive(Clone, serde::Serialize, serde::Deserialize)]
|
||||
pub struct NodeSubTree {
|
||||
#[serde(rename = "type")]
|
||||
pub node_type: String,
|
||||
pub attributes: NodeAttributes,
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
@ -1,7 +1,7 @@
|
||||
use crate::core::document::position::Position;
|
||||
use crate::core::{DocumentOperation, DocumentTree, NodeAttributes, NodeSubTree};
|
||||
use std::collections::HashMap;
|
||||
use indextree::NodeId;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct Transaction {
|
||||
pub operations: Vec<DocumentOperation>,
|
||||
@ -86,7 +86,7 @@ impl<'a> TransactionBuilder<'a> {
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Box::new(NodeSubTree {
|
||||
node_type: node_data.node_type.clone(),
|
||||
|
Reference in New Issue
Block a user