mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-13 20:16:10 +00:00

* feat: support incremental to update textblock's delta * fix: update test code * fix: remove console * fix: update test * feat: integrate increamental delta in Flutter * fix: delete quill editor * fix: delete quill editor * feat: add csharp in codeblock (#3371) * chore: pt-PT & pt-BR translation updated (#3353) * chore: Ensure Cargo.lock Is Updated Alongside Changes to Cargo.toml (#3361) * ci: add cargo check workflow * ci: test cargo.toml * fix: update test * fix: code review * fix: update cargo.toml and cargo.lock * fix: code review * fix: rust format --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io> Co-authored-by: Mayur Mahajan <47064215+MayurSMahajan@users.noreply.github.com> Co-authored-by: Carlos Silva <mtbf99@gmail.com>
62 lines
1.6 KiB
Rust
62 lines
1.6 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use collab_document::blocks::{Block, BlockAction, BlockActionPayload, BlockActionType};
|
|
use collab_document::document_data::{default_document_data, PARAGRAPH_BLOCK_TYPE};
|
|
|
|
use crate::document::util::{gen_document_id, gen_id, DocumentTest};
|
|
|
|
#[tokio::test]
|
|
async fn undo_redo_test() {
|
|
let test = DocumentTest::new();
|
|
|
|
let doc_id: String = gen_document_id();
|
|
let data = default_document_data();
|
|
|
|
// create a document
|
|
_ = test
|
|
.create_document(test.user.user_id().unwrap(), &doc_id, Some(data.clone()))
|
|
.await;
|
|
|
|
// open a document
|
|
let document = test.get_document(&doc_id).await.unwrap();
|
|
let document = document.lock();
|
|
let page_block = document.get_block(&data.page_id).unwrap();
|
|
let page_id = page_block.id;
|
|
let text_block_id = gen_id();
|
|
|
|
// insert a text block
|
|
let text_block = Block {
|
|
id: text_block_id.clone(),
|
|
ty: PARAGRAPH_BLOCK_TYPE.to_string(),
|
|
parent: page_id.clone(),
|
|
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),
|
|
prev_id: None,
|
|
delta: None,
|
|
text_id: None,
|
|
},
|
|
};
|
|
document.apply_action(vec![insert_text_action]);
|
|
|
|
let can_undo = document.can_undo();
|
|
assert!(can_undo);
|
|
// undo the insert
|
|
let undo = document.undo();
|
|
assert!(undo);
|
|
assert_eq!(document.get_block(&text_block_id), None);
|
|
|
|
let can_redo = document.can_redo();
|
|
assert!(can_redo);
|
|
// redo the insert
|
|
let redo = document.redo();
|
|
assert!(redo);
|
|
}
|