mirror of
				https://github.com/AppFlowy-IO/AppFlowy.git
				synced 2025-11-04 12:03:28 +00:00 
			
		
		
		
	* chore: move to latest appflowy collab version * chore: filter mapping * chore: remove mutex folder * chore: cleanup borrow checker issues * chore: fixed flowy user crate compilation errors * chore: removed parking lot crate * chore: adjusting non locking approach * chore: remove with folder method * chore: fix folder manager * chore: fixed workspace database compilation errors * chore: initialize database plugins * chore: fix locks in flowy core * chore: remove supabase * chore: async traits * chore: add mutexes in dart ffi * chore: post rebase fixes * chore: remove supabase dart code * chore: fix deadlock * chore: fix page_id is empty * chore: use data source to init collab * chore: fix user awareness test * chore: fix database deadlock * fix: initialize user awareness * chore: fix open workspace test * chore: fix import csv * chore: fix update row meta deadlock * chore: fix document size test * fix: timestamp set/get type convert * fix: calculation * chore: revert Arc to Rc * chore: attach plugin to database and database row * chore: async get row * chore: clippy * chore: fix tauri build * chore: clippy * fix: duplicate view deadlock * chore: fmt * chore: tauri build --------- Co-authored-by: nathan <nathan@appflowy.io>
		
			
				
	
	
		
			67 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			Rust
		
	
	
	
	
	
			
		
		
	
	
			67 lines
		
	
	
		
			1.7 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(&doc_id);
 | 
						|
 | 
						|
  // create a document
 | 
						|
  _ = test
 | 
						|
    .create_document(
 | 
						|
      test.user_service.user_id().unwrap(),
 | 
						|
      &doc_id,
 | 
						|
      Some(data.clone()),
 | 
						|
    )
 | 
						|
    .await;
 | 
						|
 | 
						|
  // open a document
 | 
						|
  test.open_document(&doc_id).await.unwrap();
 | 
						|
  let document = test.editable_document(&doc_id).await.unwrap();
 | 
						|
  let mut document = document.write().await;
 | 
						|
  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]).unwrap();
 | 
						|
 | 
						|
  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);
 | 
						|
}
 |