Nathan.fooo 5facb61e23
refactor: crates (#4258)
* chore: rename flowy-folder2 to flowy-folder

* chore: rename flowy-document2 to flowy-document

* chore: fix test

* chore: move lib-infra crate

* chore: remove shared-lib

* chore: fix clippy
2023-12-31 07:29:40 +08:00

40 lines
1.2 KiB
Rust

use std::{collections::HashMap, vec};
use collab_document::blocks::{Block, BlockAction, BlockActionPayload, BlockActionType};
use collab_document::document_data::PARAGRAPH_BLOCK_TYPE;
use crate::document::util;
use crate::document::util::gen_id;
#[tokio::test]
async fn document_apply_insert_block_with_empty_parent_id() {
let (_, document, page_id) = util::create_and_open_empty_document().await;
// create a text block with no parent
let text_block_id = gen_id();
let text_block = Block {
id: text_block_id.clone(),
ty: PARAGRAPH_BLOCK_TYPE.to_string(),
parent: "".to_string(),
children: gen_id(),
external_id: None,
external_type: None,
data: HashMap::new(),
};
let insert_text_action = BlockAction {
action: BlockActionType::Insert,
payload: BlockActionPayload {
block: Some(text_block),
parent_id: Some(page_id.clone()),
prev_id: None,
delta: None,
text_id: None,
},
};
document.lock().apply_action(vec![insert_text_action]);
// read the text block and it's parent id should be the page id
let block = document.lock().get_block(&text_block_id).unwrap();
assert_eq!(block.parent, page_id);
}