mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-07-09 18:16:17 +00:00

* refactor: using tokio-postgres * chore: update * chore: update env * chore: update * chore: upgrade supabase and add logout button * refactor: update * chore: update * refactor: using message queue to handle the pg connection * refactor: move test * refactor: update sql * chore: create pg database when user login * chore: update scheme * chore: generic user service * chore: update * chore: create statistics * chore: create snapshot * chore: add test * chore: add database cloud service * chore: add document cloud service * chore: update interface * test: add document test * refactor: document interface * chore: fix test * chore: update * chore: update test * test: add test * test: add test * test: add test * chore: update collab rev * fix: flutter analyzer * chore: update * chore: update * chore: update * fix: tests * chore: update * chore: update collab rev * ci: rust fmt --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
59 lines
1.5 KiB
Rust
59 lines
1.5 KiB
Rust
use std::collections::HashMap;
|
|
|
|
use collab_document::blocks::{Block, BlockAction, BlockActionPayload, BlockActionType};
|
|
|
|
use flowy_document2::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(&doc_id, Some(data.clone()));
|
|
|
|
// open a document
|
|
let document = test.get_document(&doc_id).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: text_block,
|
|
parent_id: Some(page_id),
|
|
prev_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);
|
|
}
|