2023-06-15 10:37:51 +08:00
|
|
|
use std::{collections::HashMap, vec};
|
2023-05-16 14:58:24 +08:00
|
|
|
|
2023-07-05 20:57:09 +08:00
|
|
|
use collab_document::blocks::{Block, BlockAction, BlockActionPayload, BlockActionType};
|
|
|
|
|
|
|
|
use flowy_document2::document_data::PARAGRAPH_BLOCK_TYPE;
|
|
|
|
|
2023-06-15 10:37:51 +08:00
|
|
|
use crate::document::util;
|
|
|
|
use crate::document::util::gen_id;
|
2023-05-16 14:58:24 +08:00
|
|
|
|
2023-07-05 20:57:09 +08:00
|
|
|
#[tokio::test]
|
|
|
|
async fn document_apply_insert_block_with_empty_parent_id() {
|
2023-06-15 10:37:51 +08:00
|
|
|
let (_, document, page_id) = util::create_and_open_empty_document();
|
2023-05-16 14:58:24 +08:00
|
|
|
|
|
|
|
// create a text block with no parent
|
2023-06-15 10:37:51 +08:00
|
|
|
let text_block_id = gen_id();
|
2023-05-16 14:58:24 +08:00
|
|
|
let text_block = Block {
|
|
|
|
id: text_block_id.clone(),
|
2023-06-03 20:43:46 +08:00
|
|
|
ty: PARAGRAPH_BLOCK_TYPE.to_string(),
|
2023-05-16 14:58:24 +08:00
|
|
|
parent: "".to_string(),
|
2023-06-15 10:37:51 +08:00
|
|
|
children: gen_id(),
|
2023-05-16 14:58:24 +08:00
|
|
|
external_id: None,
|
|
|
|
external_type: None,
|
|
|
|
data: HashMap::new(),
|
|
|
|
};
|
|
|
|
let insert_text_action = BlockAction {
|
|
|
|
action: BlockActionType::Insert,
|
|
|
|
payload: BlockActionPayload {
|
|
|
|
block: text_block,
|
|
|
|
parent_id: Some(page_id.clone()),
|
|
|
|
prev_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);
|
|
|
|
}
|