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

129 lines
3.2 KiB
Rust
Raw Normal View History

2021-08-31 15:01:46 +00:00
pub use flowy_test::builder::AnnieTestBuilder;
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-08-29 14:00:42 +00:00
pub fn create_workspace(name: &str, desc: &str) -> (String, Workspace) {
2021-08-31 15:01:46 +00:00
let builder = AnnieTestBuilder::new();
2021-08-29 14:00:42 +00:00
let user_id = builder.user_detail.as_ref().unwrap().id.clone();
2021-07-20 06:03:21 +00:00
let request = CreateWorkspaceRequest {
name: name.to_owned(),
desc: desc.to_owned(),
2021-08-29 14:00:42 +00:00
user_id: user_id.clone(),
2021-07-20 06:03:21 +00:00
};
2021-08-29 14:00:42 +00:00
let workspace = builder
2021-07-20 06:03:21 +00:00
.event(CreateWorkspace)
.request(request)
.sync_send()
.parse::<Workspace>();
2021-08-29 14:00:42 +00:00
(user_id, workspace)
2021-07-20 06:03:21 +00:00
}
2021-08-29 14:00:42 +00:00
pub fn read_workspaces(request: QueryWorkspaceRequest) -> Option<Workspace> {
2021-08-31 15:01:46 +00:00
let mut repeated_workspace = AnnieTestBuilder::new()
.event(ReadWorkspaces)
.request(request)
.sync_send()
2021-08-29 14:00:42 +00:00
.parse::<RepeatedWorkspace>();
2021-08-29 14:00:42 +00:00
debug_assert_eq!(repeated_workspace.len(), 1);
repeated_workspace
.drain(..1)
.collect::<Vec<Workspace>>()
.pop()
}
2021-08-29 14:00:42 +00:00
pub fn create_app(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-08-31 15:01:46 +00:00
let app = AnnieTestBuilder::new()
2021-07-20 06:03:21 +00:00
.event(CreateApp)
.request(create_app_request)
.sync_send()
.parse::<App>();
app
}
pub fn delete_app(app_id: &str) {
let delete_app_request = DeleteAppRequest {
app_id: app_id.to_string(),
};
2021-07-20 06:03:21 +00:00
2021-08-31 15:01:46 +00:00
AnnieTestBuilder::new()
.event(DeleteApp)
.request(delete_app_request)
.sync_send();
2021-07-20 06:03:21 +00:00
}
2021-07-20 07:51:49 +00:00
pub fn update_app(request: UpdateAppRequest) {
2021-08-31 15:01:46 +00:00
AnnieTestBuilder::new()
.event(UpdateApp)
.request(request)
.sync_send();
}
pub fn read_app(request: QueryAppRequest) -> App {
2021-08-31 15:01:46 +00:00
let app = AnnieTestBuilder::new()
.event(ReadApp)
2021-07-20 07:51:49 +00:00
.request(request)
.sync_send()
.parse::<App>();
app
}
pub fn create_view_with_request(request: CreateViewRequest) -> View {
2021-08-31 15:01:46 +00:00
let view = AnnieTestBuilder::new()
2021-07-20 07:51:49 +00:00
.event(CreateView)
.request(request)
.sync_send()
.parse::<View>();
view
}
pub fn create_view() -> View {
2021-08-29 14:00:42 +00:00
let workspace = create_workspace("Workspace", "").1;
let app = create_app("App A", "AppFlowy Github Project", &workspace.id);
let request = CreateViewRequest {
belong_to_id: app.id.clone(),
name: "View A".to_string(),
desc: "".to_string(),
thumbnail: None,
view_type: ViewType::Doc,
};
create_view_with_request(request)
}
pub fn update_view(request: UpdateViewRequest) {
2021-08-31 15:01:46 +00:00
AnnieTestBuilder::new()
.event(UpdateView)
.request(request)
.sync_send();
}
pub fn read_view(request: QueryViewRequest) -> View {
2021-08-31 15:01:46 +00:00
AnnieTestBuilder::new()
.event(ReadView)
.request(request)
.sync_send()
.parse::<View>()
}