mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
test: Folder event test (#2709)
* test: add event tests * test: add folder event test * ci: rust fmt
This commit is contained in:
@ -3,7 +3,9 @@ use parking_lot::RwLock;
|
||||
use std::env::temp_dir;
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::event_builder::EventBuilder;
|
||||
use flowy_core::{AppFlowyCore, AppFlowyCoreConfig};
|
||||
use flowy_folder2::entities::{CreateViewPayloadPB, RepeatedViewIdPB, ViewPB, WorkspaceSettingPB};
|
||||
use flowy_user::entities::{AuthTypePB, UserProfilePB};
|
||||
|
||||
use crate::user_event::{async_sign_up, init_user_setting, SignUpContext};
|
||||
@ -36,6 +38,12 @@ impl FlowyCoreTest {
|
||||
Self::default()
|
||||
}
|
||||
|
||||
pub async fn new_with_user() -> Self {
|
||||
let test = Self::default();
|
||||
test.sign_up().await;
|
||||
test
|
||||
}
|
||||
|
||||
pub async fn sign_up(&self) -> SignUpContext {
|
||||
let auth_type = self.auth_type.read().clone();
|
||||
async_sign_up(self.inner.dispatcher(), auth_type).await
|
||||
@ -51,6 +59,46 @@ impl FlowyCoreTest {
|
||||
init_user_setting(self.inner.dispatcher()).await;
|
||||
context.user_profile
|
||||
}
|
||||
|
||||
pub async fn get_current_workspace(&self) -> WorkspaceSettingPB {
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::GetCurrentWorkspace)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<flowy_folder2::entities::WorkspaceSettingPB>()
|
||||
}
|
||||
|
||||
pub async fn delete_view(&self, view_id: &str) {
|
||||
let payload = RepeatedViewIdPB {
|
||||
items: vec![view_id.to_string()],
|
||||
};
|
||||
|
||||
// delete the view. the view will be moved to trash
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::DeleteView)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn create_view(&self, parent_id: &str, name: String) -> ViewPB {
|
||||
let payload = CreateViewPayloadPB {
|
||||
parent_view_id: parent_id.to_string(),
|
||||
name,
|
||||
desc: "".to_string(),
|
||||
thumbnail: None,
|
||||
layout: Default::default(),
|
||||
initial_data: vec![],
|
||||
meta: Default::default(),
|
||||
set_as_current: false,
|
||||
};
|
||||
EventBuilder::new(self.clone())
|
||||
.event(flowy_folder2::event_map::FolderEvent::CreateView)
|
||||
.payload(payload)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<flowy_folder2::entities::ViewPB>()
|
||||
}
|
||||
}
|
||||
|
||||
impl std::ops::Deref for FlowyCoreTest {
|
||||
@ -60,3 +108,13 @@ impl std::ops::Deref for FlowyCoreTest {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
|
||||
// pub struct TestNotificationSender {
|
||||
// pub(crate) sender: tokio::sync::mpsc::Sender<()>,
|
||||
// }
|
||||
//
|
||||
// impl NotificationSender for TestNotificationSender {
|
||||
// fn send_subject(&self, subject: SubscribeObject) -> Result<(), String> {
|
||||
// todo!()
|
||||
// }
|
||||
// }
|
||||
|
Reference in New Issue
Block a user