mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-13 12:06:03 +00:00

* chore: bump version 0.2.0 * test: add migration test * feat: support exporting document data to afdoc format (#2610) * feat: support exporting document data to afdoc format * feat: export database * fix: resolve comment issues * fix: add error tips when exporting files failed --------- Co-authored-by: nathan <nathan@appflowy.io> * feat: rename delta * feat: add built-in readme * fix: use independent children id * fix: comment typo * chore: add icons * fix: floating toolbar style * fix: markdown export test * chore: disbale moveup/movedown action * fix: unit test --------- Co-authored-by: nathan <nathan@appflowy.io>
103 lines
2.4 KiB
Rust
103 lines
2.4 KiB
Rust
use flowy_document2::parser::json::block::Block;
|
|
use serde_json::json;
|
|
|
|
#[test]
|
|
fn test_empty_data_and_children() {
|
|
let json = json!({
|
|
"type": "page",
|
|
});
|
|
let block = serde_json::from_value::<Block>(json).unwrap();
|
|
assert_eq!(block.ty, "page");
|
|
assert!(block.data.is_empty());
|
|
assert!(block.children.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_data() {
|
|
let json = json!({
|
|
"type": "todo_list",
|
|
"data": {
|
|
"delta": [{ "insert": "Click anywhere and just start typing." }],
|
|
"checked": false
|
|
}
|
|
});
|
|
let block = serde_json::from_value::<Block>(json).unwrap();
|
|
assert_eq!(block.ty, "todo_list");
|
|
assert_eq!(block.data.len(), 2);
|
|
assert_eq!(block.data.get("checked").unwrap(), false);
|
|
assert_eq!(
|
|
block.data.get("delta").unwrap().to_owned(),
|
|
json!([{ "insert": "Click anywhere and just start typing." }])
|
|
);
|
|
assert!(block.children.is_empty());
|
|
}
|
|
|
|
#[test]
|
|
fn test_children() {
|
|
let json = json!({
|
|
"type": "page",
|
|
"children": [
|
|
{
|
|
"type": "heading",
|
|
"data": {
|
|
"delta": [{ "insert": "Welcome to AppFlowy!" }],
|
|
"level": 1
|
|
}
|
|
},
|
|
{
|
|
"type": "todo_list",
|
|
"data": {
|
|
"delta": [{ "insert": "Welcome to AppFlowy!" }],
|
|
"checked": false
|
|
}
|
|
}
|
|
]});
|
|
let block = serde_json::from_value::<Block>(json).unwrap();
|
|
assert!(block.data.is_empty());
|
|
assert_eq!(block.ty, "page");
|
|
assert_eq!(block.children.len(), 2);
|
|
// heading
|
|
let heading = &block.children[0];
|
|
assert_eq!(heading.ty, "heading");
|
|
assert_eq!(heading.data.len(), 2);
|
|
|
|
// todo_list
|
|
let todo_list = &block.children[1];
|
|
assert_eq!(todo_list.ty, "todo_list");
|
|
assert_eq!(todo_list.data.len(), 2);
|
|
}
|
|
|
|
#[test]
|
|
fn test_nested_children() {
|
|
let json = json!({
|
|
"type": "page",
|
|
"children": [
|
|
{
|
|
"type": "paragraph",
|
|
"children": [
|
|
{
|
|
"type": "paragraph",
|
|
"children": [
|
|
{
|
|
"type": "paragraph",
|
|
"children": [
|
|
{
|
|
"type": "paragraph"
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
}
|
|
]
|
|
});
|
|
let block = serde_json::from_value::<Block>(json).unwrap();
|
|
assert!(block.data.is_empty());
|
|
assert_eq!(block.ty, "page");
|
|
assert_eq!(
|
|
block.children[0].children[0].children[0].children[0].ty,
|
|
"paragraph"
|
|
);
|
|
}
|