AppFlowy/frontend/rust-lib/flowy-folder/tests/workspace/helper.rs

212 lines
5.8 KiB
Rust
Raw Normal View History

2022-02-25 14:27:44 +00:00
use flowy_collaboration::entities::document_info::BlockInfo;
2022-01-30 02:33:21 +00:00
use flowy_folder::event_map::FolderEvent::*;
2022-02-24 12:36:24 +00:00
use flowy_folder_data_model::entities::view::{RepeatedViewId, ViewId};
2022-02-24 13:49:18 +00:00
use flowy_folder_data_model::entities::workspace::WorkspaceId;
use flowy_folder_data_model::entities::{
2022-02-24 13:49:18 +00:00
app::{App, AppId, CreateAppPayload, UpdateAppPayload},
2022-01-22 10:48:43 +00:00
trash::{RepeatedTrash, TrashId, TrashType},
2022-02-28 14:38:53 +00:00
view::{CreateViewPayload, UpdateViewPayload, View, ViewDataType},
2022-02-24 13:49:18 +00:00
workspace::{CreateWorkspacePayload, RepeatedWorkspace, Workspace},
2022-01-22 10:48:43 +00:00
};
use flowy_test::{event_builder::*, FlowySDKTest};
pub async fn create_workspace(sdk: &FlowySDKTest, name: &str, desc: &str) -> Workspace {
2022-02-24 13:49:18 +00:00
let request = CreateWorkspacePayload {
2022-01-22 10:48:43 +00:00
name: name.to_owned(),
desc: desc.to_owned(),
};
let workspace = FolderEventBuilder::new(sdk.clone())
.event(CreateWorkspace)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<Workspace>();
workspace
}
pub async fn read_workspace(sdk: &FlowySDKTest, workspace_id: Option<String>) -> Vec<Workspace> {
2022-02-24 13:49:18 +00:00
let request = WorkspaceId { value: workspace_id };
2022-01-22 10:48:43 +00:00
let repeated_workspace = FolderEventBuilder::new(sdk.clone())
.event(ReadWorkspaces)
2022-02-24 13:49:18 +00:00
.payload(request.clone())
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<RepeatedWorkspace>();
let workspaces;
2022-02-24 13:49:18 +00:00
if let Some(workspace_id) = &request.value {
2022-01-22 10:48:43 +00:00
workspaces = repeated_workspace
.into_inner()
.into_iter()
.filter(|workspace| &workspace.id == workspace_id)
.collect::<Vec<Workspace>>();
debug_assert_eq!(workspaces.len(), 1);
} else {
workspaces = repeated_workspace.items;
}
workspaces
}
pub async fn create_app(sdk: &FlowySDKTest, workspace_id: &str, name: &str, desc: &str) -> App {
2022-02-24 13:49:18 +00:00
let create_app_request = CreateAppPayload {
2022-01-22 10:48:43 +00:00
workspace_id: workspace_id.to_owned(),
name: name.to_string(),
desc: desc.to_string(),
color_style: Default::default(),
};
let app = FolderEventBuilder::new(sdk.clone())
.event(CreateApp)
2022-02-24 13:49:18 +00:00
.payload(create_app_request)
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<App>();
app
}
pub async fn read_app(sdk: &FlowySDKTest, app_id: &str) -> App {
2022-02-24 13:49:18 +00:00
let request = AppId {
value: app_id.to_owned(),
2022-01-22 10:48:43 +00:00
};
let app = FolderEventBuilder::new(sdk.clone())
.event(ReadApp)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<App>();
app
}
pub async fn update_app(sdk: &FlowySDKTest, app_id: &str, name: Option<String>, desc: Option<String>) {
2022-02-24 13:49:18 +00:00
let request = UpdateAppPayload {
2022-01-22 10:48:43 +00:00
app_id: app_id.to_string(),
name,
desc,
color_style: None,
is_trash: None,
};
FolderEventBuilder::new(sdk.clone())
.event(UpdateApp)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
pub async fn delete_app(sdk: &FlowySDKTest, app_id: &str) {
let request = AppId {
2022-02-24 13:49:18 +00:00
value: app_id.to_string(),
2022-01-22 10:48:43 +00:00
};
FolderEventBuilder::new(sdk.clone())
.event(DeleteApp)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
2022-03-01 15:38:26 +00:00
pub async fn create_view(sdk: &FlowySDKTest, app_id: &str, name: &str, desc: &str, data_type: ViewDataType) -> View {
2022-02-24 13:49:18 +00:00
let request = CreateViewPayload {
2022-01-22 10:48:43 +00:00
belong_to_id: app_id.to_string(),
name: name.to_string(),
desc: desc.to_string(),
thumbnail: None,
2022-03-01 15:38:26 +00:00
data_type,
2022-02-28 14:38:53 +00:00
ext_data: "".to_string(),
2022-03-01 08:05:45 +00:00
plugin_type: 0,
2022-01-22 10:48:43 +00:00
};
let view = FolderEventBuilder::new(sdk.clone())
.event(CreateView)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<View>();
view
}
2022-02-24 12:36:24 +00:00
pub async fn read_view(sdk: &FlowySDKTest, view_id: &str) -> View {
2022-02-24 13:49:18 +00:00
let view_id: ViewId = view_id.into();
2022-01-22 10:48:43 +00:00
FolderEventBuilder::new(sdk.clone())
.event(ReadView)
2022-02-24 13:49:18 +00:00
.payload(view_id)
2022-01-22 10:48:43 +00:00
.async_send()
.await
.parse::<View>()
}
pub async fn update_view(sdk: &FlowySDKTest, view_id: &str, name: Option<String>, desc: Option<String>) {
2022-02-24 13:49:18 +00:00
let request = UpdateViewPayload {
2022-01-22 10:48:43 +00:00
view_id: view_id.to_string(),
name,
desc,
thumbnail: None,
};
FolderEventBuilder::new(sdk.clone())
.event(UpdateView)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
pub async fn delete_view(sdk: &FlowySDKTest, view_ids: Vec<String>) {
2022-02-24 12:36:24 +00:00
let request = RepeatedViewId { items: view_ids };
2022-01-22 10:48:43 +00:00
FolderEventBuilder::new(sdk.clone())
.event(DeleteView)
2022-02-24 13:49:18 +00:00
.payload(request)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
2022-02-25 14:27:44 +00:00
pub async fn open_document(sdk: &FlowySDKTest, view_id: &str) -> BlockInfo {
2022-02-24 13:49:18 +00:00
let view_id: ViewId = view_id.into();
2022-01-22 10:48:43 +00:00
FolderEventBuilder::new(sdk.clone())
2022-02-24 12:36:24 +00:00
.event(OpenView)
2022-02-24 13:49:18 +00:00
.payload(view_id)
2022-01-22 10:48:43 +00:00
.async_send()
.await
2022-02-25 14:27:44 +00:00
.parse::<BlockInfo>()
2022-01-22 10:48:43 +00:00
}
pub async fn read_trash(sdk: &FlowySDKTest) -> RepeatedTrash {
FolderEventBuilder::new(sdk.clone())
.event(ReadTrash)
.async_send()
.await
.parse::<RepeatedTrash>()
}
pub async fn restore_app_from_trash(sdk: &FlowySDKTest, app_id: &str) {
let id = TrashId {
id: app_id.to_owned(),
ty: TrashType::TrashApp,
2022-01-22 10:48:43 +00:00
};
FolderEventBuilder::new(sdk.clone())
.event(PutbackTrash)
2022-02-24 13:49:18 +00:00
.payload(id)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
pub async fn restore_view_from_trash(sdk: &FlowySDKTest, view_id: &str) {
let id = TrashId {
id: view_id.to_owned(),
ty: TrashType::TrashView,
2022-01-22 10:48:43 +00:00
};
FolderEventBuilder::new(sdk.clone())
.event(PutbackTrash)
2022-02-24 13:49:18 +00:00
.payload(id)
2022-01-22 10:48:43 +00:00
.async_send()
.await;
}
pub async fn delete_all_trash(sdk: &FlowySDKTest) {
FolderEventBuilder::new(sdk.clone())
.event(DeleteAllTrash)
.async_send()
.await;
}