AppFlowy/frontend/rust-lib/flowy-document2/tests/document/util.rs
qinluhe 973cd9194d
feat: Support ui update when receive doc changes (#2270)
* fix: add  method

* fix: update text block and doc title

* fix: support ui update when receive doc changes

* fix: modify the subscribe change

* chore: add test for document manager

* chore: add test for document manager

* chore: add insert and update test for document manager

* fix: load document data

* fix: add update page block test

* fix: try fix again

* fix: node can not rerender when the node data change

* fix: it should cover all content when the text delta updated

* fix: add insert and delete operation in left menu

* fix: put the UI Actions in async thunks

* fix: remove log

* fix: split text block

* fix: review code

---------

Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
Co-authored-by: nathan <nathan@appflowy.io>
2023-04-24 14:25:00 +08:00

48 lines
1.1 KiB
Rust

use std::sync::Arc;
use collab_persistence::CollabKV;
use flowy_document2::manager::DocumentUser;
use parking_lot::Once;
use tempfile::TempDir;
use tracing_subscriber::{fmt::Subscriber, util::SubscriberInitExt, EnvFilter};
pub struct FakeUser {
kv: Arc<CollabKV>,
}
impl FakeUser {
pub fn new() -> Self {
Self { kv: db() }
}
}
impl DocumentUser for FakeUser {
fn user_id(&self) -> Result<i64, flowy_error::FlowyError> {
Ok(1)
}
fn token(&self) -> Result<String, flowy_error::FlowyError> {
Ok("1".to_string())
}
fn kv_db(&self) -> Result<std::sync::Arc<CollabKV>, flowy_error::FlowyError> {
Ok(self.kv.clone())
}
}
pub fn db() -> Arc<CollabKV> {
static START: Once = Once::new();
START.call_once(|| {
std::env::set_var("RUST_LOG", "collab_persistence=trace");
let subscriber = Subscriber::builder()
.with_env_filter(EnvFilter::from_default_env())
.with_ansi(true)
.finish();
subscriber.try_init().unwrap();
});
let tempdir = TempDir::new().unwrap();
let path = tempdir.into_path();
Arc::new(CollabKV::open(path).unwrap())
}