| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164 | use super::script::{NodeScript::*, *};use lib_ot::core::AttributeBuilder;use lib_ot::{    core::{NodeData, Path},    text_delta::TextDeltaBuilder,};#[test]fn editor_deserialize_node_test() {    let mut test = NodeTest::new();    let node: NodeData = serde_json::from_str(EXAMPLE_JSON).unwrap();    let path: Path = 0.into();    let expected_delta = TextDeltaBuilder::new()        .insert("👋 ")        .insert_with_attributes(            "Welcome to ",            AttributeBuilder::new().insert("href", "appflowy.io").build(),        )        .insert_with_attributes(            "AppFlowy Editor",            AttributeBuilder::new().insert("italic", true).build(),        )        .build();    test.run_scripts(vec![        InsertNode {            path,            node_data: node.clone(),            rev_id: 1,        },        AssertNumberOfNodesAtPath { path: None, len: 1 },        AssertNumberOfNodesAtPath {            path: Some(0.into()),            len: 14,        },        AssertNumberOfNodesAtPath {            path: Some(0.into()),            len: 14,        },        AssertNodeDelta {            path: vec![0, 1].into(),            expected: expected_delta,        },        AssertNodeData {            path: vec![0, 0].into(),            expected: Some(node.children[0].clone()),        },        AssertNodeData {            path: vec![0, 3].into(),            expected: Some(node.children[3].clone()),        },    ]);}#[allow(dead_code)]const EXAMPLE_JSON: &str = r#"{  "type": "editor",  "children": [    {      "type": "image",      "attributes": {        "image_src": "https://s1.ax1x.com/2022/08/26/v2sSbR.jpg",        "align": "center"      }    },    {      "type": "text",      "attributes": {        "subtype": "heading",        "heading": "h1"      },      "body": {        "delta": [          {            "insert": "👋 "          },          {            "insert": "Welcome to ",            "attributes": {              "href": "appflowy.io"            }          },          {            "insert": "AppFlowy Editor",            "attributes": {              "italic": true            }          }        ]      }    },    { "type": "text", "delta": [] },    {      "type": "text",      "body": {        "delta": [            { "insert": "AppFlowy Editor is a " },            { "insert": "highly customizable", "attributes": { "bold": true } },            { "insert": " " },            { "insert": "rich-text editor", "attributes": { "italic": true } },            { "insert": " for " },            { "insert": "Flutter", "attributes": { "underline": true } }        ]      }    },    {      "type": "text",      "attributes": { "checkbox": true, "subtype": "checkbox" },      "body": {        "delta": [{ "insert": "Customizable" }]      }    },    {      "type": "text",      "attributes": { "checkbox": true, "subtype": "checkbox" },      "delta": [{ "insert": "Test-covered" }]    },    {      "type": "text",      "attributes": { "checkbox": false, "subtype": "checkbox" },      "delta": [{ "insert": "more to come!" }]    },    { "type": "text", "delta": [] },    {      "type": "text",      "attributes": { "subtype": "quote" },      "delta": [{ "insert": "Here is an exmaple you can give it a try" }]    },    { "type": "text", "delta": [] },    {      "type": "text",      "delta": [        { "insert": "You can also use " },        {          "insert": "AppFlowy Editor",          "attributes": {            "italic": true,            "bold": true,            "backgroundColor": "0x6000BCF0"          }        },        { "insert": " as a component to build your own app." }      ]    },    { "type": "text", "delta": [] },    {      "type": "text",      "attributes": { "subtype": "bulleted-list" },      "delta": [{ "insert": "Use / to insert blocks" }]    },    {      "type": "text",      "attributes": { "subtype": "bulleted-list" },      "delta": [        {          "insert": "Select text to trigger to the toolbar to format your notes."        }      ]    }  ]}"#;
 |