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
|
|
|
};
|
2021-07-14 13:12:52 +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(),
|
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
let workspace = WorkspaceTestBuilder::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 = WorkspaceTestBuilder::new(sdk.clone())
|
2021-08-30 08:18:58 +00:00
|
|
|
.event(ReadWorkspaces)
|
2021-07-29 09:27:59 +00:00
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
2021-08-29 14:00:42 +00:00
|
|
|
.parse::<RepeatedWorkspace>();
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2021-09-03 08:43:03 +00:00
|
|
|
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-07-29 09:27:59 +00:00
|
|
|
}
|
|
|
|
|
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(),
|
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
let app = WorkspaceTestBuilder::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) {
|
2021-07-29 09:27:59 +00:00
|
|
|
let delete_app_request = DeleteAppRequest {
|
|
|
|
app_id: app_id.to_string(),
|
|
|
|
};
|
2021-07-20 06:03:21 +00:00
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
WorkspaceTestBuilder::new(sdk.clone())
|
|
|
|
.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) {
|
|
|
|
WorkspaceTestBuilder::new(sdk.clone()).event(UpdateApp).request(request).sync_send();
|
|
|
|
}
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub fn read_app(sdk: &FlowyTestSDK, request: QueryAppRequest) -> App {
|
|
|
|
let app = WorkspaceTestBuilder::new(sdk.clone())
|
2021-09-03 08:43:03 +00:00
|
|
|
.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 = WorkspaceTestBuilder::new(sdk.clone())
|
2021-07-20 07:51:49 +00:00
|
|
|
.event(CreateView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<View>();
|
|
|
|
|
|
|
|
view
|
|
|
|
}
|
2021-07-29 09:27:59 +00:00
|
|
|
|
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);
|
2021-07-29 09:27:59 +00:00
|
|
|
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()),
|
2021-07-29 09:27:59 +00:00
|
|
|
view_type: ViewType::Doc,
|
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
create_view_with_request(sdk, request)
|
2021-07-29 09:27:59 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub fn update_view(sdk: &FlowyTestSDK, request: UpdateViewRequest) {
|
|
|
|
WorkspaceTestBuilder::new(sdk.clone())
|
|
|
|
.event(UpdateView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send();
|
|
|
|
}
|
2021-07-29 09:27:59 +00:00
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub fn read_view(sdk: &FlowyTestSDK, request: QueryViewRequest) -> View {
|
|
|
|
WorkspaceTestBuilder::new(sdk.clone())
|
2021-09-03 08:43:03 +00:00
|
|
|
.event(ReadView)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<View>()
|
|
|
|
}
|