From f6e33a59d5e49f4a4688b4098fd1fe26cb0aac1d Mon Sep 17 00:00:00 2001
From: "Nathan.fooo" <86001920+appflowy@users.noreply.github.com>
Date: Wed, 5 Jun 2024 12:40:31 +0800
Subject: [PATCH] chore: fix document test (#5470)

* chore: fix document test
---
 frontend/rust-lib/flowy-document/Cargo.toml                   | 1 +
 .../flowy-document/tests/document/document_redo_undo_test.rs  | 1 +
 .../rust-lib/flowy-document/tests/document/document_test.rs   | 4 ++++
 frontend/rust-lib/flowy-document/tests/document/util.rs       | 1 +
 4 files changed, 7 insertions(+)

diff --git a/frontend/rust-lib/flowy-document/Cargo.toml b/frontend/rust-lib/flowy-document/Cargo.toml
index 813d87d589675..1b2cf3c593423 100644
--- a/frontend/rust-lib/flowy-document/Cargo.toml
+++ b/frontend/rust-lib/flowy-document/Cargo.toml
@@ -45,6 +45,7 @@ getrandom = { version = "0.2", features = ["js"] }
 tempfile = "3.4.0"
 tracing-subscriber = { version = "0.3.3", features = ["env-filter"] }
 collab-integrate = { workspace = true }
+tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
 
 [build-dependencies]
 flowy-codegen.workspace = true
diff --git a/frontend/rust-lib/flowy-document/tests/document/document_redo_undo_test.rs b/frontend/rust-lib/flowy-document/tests/document/document_redo_undo_test.rs
index 54be6a2d52a5d..fc8268fd7158b 100644
--- a/frontend/rust-lib/flowy-document/tests/document/document_redo_undo_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/document/document_redo_undo_test.rs
@@ -22,6 +22,7 @@ async fn undo_redo_test() {
     .await;
 
   // open a document
+  test.open_document(&doc_id).await.unwrap();
   let document = test.get_document(&doc_id).await.unwrap();
   let document = document.lock();
   let page_block = document.get_block(&data.page_id).unwrap();
diff --git a/frontend/rust-lib/flowy-document/tests/document/document_test.rs b/frontend/rust-lib/flowy-document/tests/document/document_test.rs
index 1296bc3c7c1a7..754cba2ef03a3 100644
--- a/frontend/rust-lib/flowy-document/tests/document/document_test.rs
+++ b/frontend/rust-lib/flowy-document/tests/document/document_test.rs
@@ -20,6 +20,7 @@ async fn restore_document() {
     .unwrap();
   let data_a = test.get_document_data(&doc_id).await.unwrap();
   assert_eq!(data_a, data);
+  test.open_document(&doc_id).await.unwrap();
 
   let data_b = test
     .get_document(&doc_id)
@@ -59,6 +60,7 @@ async fn document_apply_insert_action() {
   _ = test.create_document(uid, &doc_id, Some(data.clone())).await;
 
   // open a document
+  test.open_document(&doc_id).await.unwrap();
   let document = test.get_document(&doc_id).await.unwrap();
   let page_block = document.lock().get_block(&data.page_id).unwrap();
 
@@ -112,6 +114,7 @@ async fn document_apply_update_page_action() {
   _ = test.create_document(uid, &doc_id, Some(data.clone())).await;
 
   // open a document
+  test.open_document(&doc_id).await.unwrap();
   let document = test.get_document(&doc_id).await.unwrap();
   let page_block = document.lock().get_block(&data.page_id).unwrap();
 
@@ -155,6 +158,7 @@ async fn document_apply_update_action() {
   _ = test.create_document(uid, &doc_id, Some(data.clone())).await;
 
   // open a document
+  test.open_document(&doc_id).await.unwrap();
   let document = test.get_document(&doc_id).await.unwrap();
   let page_block = document.lock().get_block(&data.page_id).unwrap();
 
diff --git a/frontend/rust-lib/flowy-document/tests/document/util.rs b/frontend/rust-lib/flowy-document/tests/document/util.rs
index 4367b4d157a53..b08a7ec079aa0 100644
--- a/frontend/rust-lib/flowy-document/tests/document/util.rs
+++ b/frontend/rust-lib/flowy-document/tests/document/util.rs
@@ -123,6 +123,7 @@ pub async fn create_and_open_empty_document() -> (DocumentTest, Arc<MutexDocumen
     .await
     .unwrap();
 
+  test.open_document(&doc_id).await.unwrap();
   let document = test.get_document(&doc_id).await.unwrap();
 
   (test, document, data.page_id)