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

114 lines
3.2 KiB
Rust
Raw Normal View History

2021-09-04 07:12:53 +00:00
use flowy_test::prelude::*;
2021-07-20 06:03:21 +00:00
use flowy_workspace::{
2021-07-20 07:51:49 +00:00
entities::{app::*, view::*, workspace::*},
event::WorkspaceEvent::*,
2021-07-20 06:03:21 +00:00
};
pub(crate) fn invalid_workspace_name_test_case() -> Vec<String> {
vec!["", "1234".repeat(100).as_str()]
.iter()
.map(|s| s.to_string())
.collect::<Vec<_>>()
}
2021-07-20 06:03:21 +00:00
2021-09-04 07:12:53 +00:00
pub fn create_workspace(sdk: &FlowyTestSDK, name: &str, desc: &str) -> Workspace {
2021-07-20 06:03:21 +00:00
let request = CreateWorkspaceRequest {
name: name.to_owned(),
desc: desc.to_owned(),
};
let workspace = WorkspaceTest::new(sdk.clone())
2021-09-03 04:44:48 +00:00
.event(CreateWorkspace)
.request(request)
.sync_send()
.parse::<Workspace>();
2021-09-02 15:32:37 +00:00
workspace
2021-07-20 06:03:21 +00:00
}
2021-09-04 07:12:53 +00:00
pub fn read_workspaces(sdk: &FlowyTestSDK, request: QueryWorkspaceRequest) -> Option<Workspace> {
let mut repeated_workspace = WorkspaceTest::new(sdk.clone())
.event(ReadWorkspaces)
.request(request)
.sync_send()
2021-08-29 14:00:42 +00:00
.parse::<RepeatedWorkspace>();
debug_assert_eq!(repeated_workspace.len(), 1, "Default workspace not found");
2021-09-02 09:43:10 +00:00
repeated_workspace.drain(..1).collect::<Vec<Workspace>>().pop()
}
2021-09-04 07:12:53 +00:00
pub fn create_app(sdk: &FlowyTestSDK, name: &str, desc: &str, workspace_id: &str) -> App {
2021-07-20 06:03:21 +00:00
let create_app_request = CreateAppRequest {
2021-08-29 14:00:42 +00:00
workspace_id: workspace_id.to_owned(),
2021-07-20 06:03:21 +00:00
name: name.to_string(),
desc: desc.to_string(),
color_style: Default::default(),
};
let app = WorkspaceTest::new(sdk.clone())
2021-07-20 06:03:21 +00:00
.event(CreateApp)
.request(create_app_request)
.sync_send()
.parse::<App>();
app
}
2021-09-04 07:12:53 +00:00
pub fn delete_app(sdk: &FlowyTestSDK, app_id: &str) {
let delete_app_request = DeleteAppRequest {
app_id: app_id.to_string(),
};
2021-07-20 06:03:21 +00:00
WorkspaceTest::new(sdk.clone())
2021-09-04 07:12:53 +00:00
.event(DeleteApp)
.request(delete_app_request)
.sync_send();
2021-07-20 06:03:21 +00:00
}
2021-07-20 07:51:49 +00:00
2021-09-04 07:12:53 +00:00
pub fn update_app(sdk: &FlowyTestSDK, request: UpdateAppRequest) {
WorkspaceTest::new(sdk.clone()).event(UpdateApp).request(request).sync_send();
2021-09-04 07:12:53 +00:00
}
2021-09-04 07:12:53 +00:00
pub fn read_app(sdk: &FlowyTestSDK, request: QueryAppRequest) -> App {
let app = WorkspaceTest::new(sdk.clone())
.event(ReadApp)
.request(request)
.sync_send()
.parse::<App>();
2021-07-20 07:51:49 +00:00
app
}
2021-09-04 07:12:53 +00:00
pub fn create_view_with_request(sdk: &FlowyTestSDK, request: CreateViewRequest) -> View {
let view = WorkspaceTest::new(sdk.clone())
2021-07-20 07:51:49 +00:00
.event(CreateView)
.request(request)
.sync_send()
.parse::<View>();
view
}
2021-09-04 07:12:53 +00:00
pub fn create_view(sdk: &FlowyTestSDK, workspace_id: &str) -> View {
let app = create_app(sdk, "App A", "AppFlowy Github Project", workspace_id);
let request = CreateViewRequest {
belong_to_id: app.id.clone(),
name: "View A".to_string(),
desc: "".to_string(),
2021-09-02 15:32:37 +00:00
thumbnail: Some("http://1.png".to_string()),
view_type: ViewType::Doc,
};
2021-09-04 07:12:53 +00:00
create_view_with_request(sdk, request)
}
2021-09-04 07:12:53 +00:00
pub fn update_view(sdk: &FlowyTestSDK, request: UpdateViewRequest) {
WorkspaceTest::new(sdk.clone()).event(UpdateView).request(request).sync_send();
2021-09-04 07:12:53 +00:00
}
2021-09-04 07:12:53 +00:00
pub fn read_view(sdk: &FlowyTestSDK, request: QueryViewRequest) -> View {
WorkspaceTest::new(sdk.clone())
.event(ReadView)
.request(request)
.sync_send()
.parse::<View>()
}