2023-04-04 00:41:16 +00:00
|
|
|
use collab_folder::core::ViewLayout;
|
2023-06-05 08:09:18 +00:00
|
|
|
|
2023-04-04 00:41:16 +00:00
|
|
|
use flowy_folder2::entities::*;
|
|
|
|
use flowy_folder2::event_map::FolderEvent::*;
|
2023-05-23 15:55:21 +00:00
|
|
|
use flowy_test::event_builder::EventBuilder;
|
|
|
|
use flowy_test::FlowyCoreTest;
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
pub enum FolderScript {
|
|
|
|
// Workspace
|
|
|
|
ReadAllWorkspaces,
|
|
|
|
CreateWorkspace {
|
|
|
|
name: String,
|
|
|
|
desc: String,
|
|
|
|
},
|
|
|
|
AssertWorkspace(WorkspacePB),
|
|
|
|
ReadWorkspace(Option<String>),
|
|
|
|
|
|
|
|
// App
|
2023-06-05 05:10:14 +00:00
|
|
|
CreateParentView {
|
2023-04-04 00:41:16 +00:00
|
|
|
name: String,
|
|
|
|
desc: String,
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
AssertParentView(ViewPB),
|
|
|
|
ReloadParentView(String),
|
|
|
|
UpdateParentView {
|
2023-04-04 00:41:16 +00:00
|
|
|
name: Option<String>,
|
|
|
|
desc: Option<String>,
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
DeleteParentView,
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
// View
|
|
|
|
CreateView {
|
|
|
|
name: String,
|
|
|
|
desc: String,
|
|
|
|
layout: ViewLayout,
|
|
|
|
},
|
|
|
|
AssertView(ViewPB),
|
|
|
|
ReadView(String),
|
|
|
|
UpdateView {
|
|
|
|
name: Option<String>,
|
|
|
|
desc: Option<String>,
|
|
|
|
},
|
|
|
|
DeleteView,
|
|
|
|
DeleteViews(Vec<String>),
|
2023-07-26 08:49:50 +00:00
|
|
|
MoveView {
|
|
|
|
view_id: String,
|
|
|
|
new_parent_id: String,
|
|
|
|
prev_view_id: Option<String>,
|
|
|
|
},
|
2023-04-04 00:41:16 +00:00
|
|
|
|
|
|
|
// Trash
|
|
|
|
RestoreAppFromTrash,
|
|
|
|
RestoreViewFromTrash,
|
|
|
|
ReadTrash,
|
|
|
|
DeleteAllTrash,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct FolderTest {
|
2023-05-23 15:55:21 +00:00
|
|
|
pub sdk: FlowyCoreTest,
|
2023-04-04 00:41:16 +00:00
|
|
|
pub all_workspace: Vec<WorkspacePB>,
|
|
|
|
pub workspace: WorkspacePB,
|
|
|
|
pub parent_view: ViewPB,
|
|
|
|
pub child_view: ViewPB,
|
|
|
|
pub trash: Vec<TrashPB>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FolderTest {
|
|
|
|
pub async fn new() -> Self {
|
2023-05-23 15:55:21 +00:00
|
|
|
let sdk = FlowyCoreTest::new();
|
2023-04-04 00:41:16 +00:00
|
|
|
let _ = sdk.init_user().await;
|
|
|
|
let workspace = create_workspace(&sdk, "FolderWorkspace", "Folder test workspace").await;
|
|
|
|
let parent_view = create_app(&sdk, &workspace.id, "Folder App", "Folder test app").await;
|
|
|
|
let view = create_view(
|
|
|
|
&sdk,
|
|
|
|
&parent_view.id,
|
|
|
|
"Folder View",
|
|
|
|
"Folder test view",
|
|
|
|
ViewLayout::Document,
|
|
|
|
)
|
|
|
|
.await;
|
|
|
|
Self {
|
|
|
|
sdk,
|
|
|
|
all_workspace: vec![],
|
|
|
|
workspace,
|
|
|
|
parent_view,
|
|
|
|
child_view: view,
|
|
|
|
trash: vec![],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_scripts(&mut self, scripts: Vec<FolderScript>) {
|
|
|
|
for script in scripts {
|
|
|
|
self.run_script(script).await;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn run_script(&mut self, script: FolderScript) {
|
|
|
|
let sdk = &self.sdk;
|
|
|
|
match script {
|
|
|
|
FolderScript::ReadAllWorkspaces => {
|
|
|
|
let all_workspace = read_workspace(sdk, None).await;
|
|
|
|
self.all_workspace = all_workspace;
|
|
|
|
},
|
|
|
|
FolderScript::CreateWorkspace { name, desc } => {
|
|
|
|
let workspace = create_workspace(sdk, &name, &desc).await;
|
|
|
|
self.workspace = workspace;
|
|
|
|
},
|
|
|
|
FolderScript::AssertWorkspace(workspace) => {
|
|
|
|
assert_eq!(self.workspace, workspace, "Workspace not equal");
|
|
|
|
},
|
|
|
|
FolderScript::ReadWorkspace(workspace_id) => {
|
|
|
|
let workspace = read_workspace(sdk, workspace_id).await.pop().unwrap();
|
|
|
|
self.workspace = workspace;
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderScript::CreateParentView { name, desc } => {
|
2023-04-04 00:41:16 +00:00
|
|
|
let app = create_app(sdk, &self.workspace.id, &name, &desc).await;
|
|
|
|
self.parent_view = app;
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderScript::AssertParentView(app) => {
|
2023-04-04 00:41:16 +00:00
|
|
|
assert_eq!(self.parent_view, app, "App not equal");
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderScript::ReloadParentView(parent_view_id) => {
|
|
|
|
let parent_view = read_view(sdk, &parent_view_id).await;
|
|
|
|
self.parent_view = parent_view;
|
2023-04-04 00:41:16 +00:00
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderScript::UpdateParentView { name, desc } => {
|
2023-04-04 00:41:16 +00:00
|
|
|
update_view(sdk, &self.parent_view.id, name, desc).await;
|
|
|
|
},
|
2023-06-05 05:10:14 +00:00
|
|
|
FolderScript::DeleteParentView => {
|
2023-04-04 00:41:16 +00:00
|
|
|
delete_view(sdk, vec![self.parent_view.id.clone()]).await;
|
|
|
|
},
|
|
|
|
FolderScript::CreateView { name, desc, layout } => {
|
|
|
|
let view = create_view(sdk, &self.parent_view.id, &name, &desc, layout).await;
|
|
|
|
self.child_view = view;
|
|
|
|
},
|
2023-07-26 08:49:50 +00:00
|
|
|
FolderScript::MoveView {
|
|
|
|
view_id,
|
|
|
|
new_parent_id,
|
|
|
|
prev_view_id,
|
|
|
|
} => {
|
|
|
|
move_view(sdk, view_id, new_parent_id, prev_view_id).await;
|
|
|
|
},
|
2023-04-04 00:41:16 +00:00
|
|
|
FolderScript::AssertView(view) => {
|
|
|
|
assert_eq!(self.child_view, view, "View not equal");
|
|
|
|
},
|
|
|
|
FolderScript::ReadView(view_id) => {
|
|
|
|
let view = read_view(sdk, &view_id).await;
|
|
|
|
self.child_view = view;
|
|
|
|
},
|
|
|
|
FolderScript::UpdateView { name, desc } => {
|
|
|
|
update_view(sdk, &self.child_view.id, name, desc).await;
|
|
|
|
},
|
|
|
|
FolderScript::DeleteView => {
|
|
|
|
delete_view(sdk, vec![self.child_view.id.clone()]).await;
|
|
|
|
},
|
|
|
|
FolderScript::DeleteViews(view_ids) => {
|
|
|
|
delete_view(sdk, view_ids).await;
|
|
|
|
},
|
|
|
|
FolderScript::RestoreAppFromTrash => {
|
|
|
|
restore_app_from_trash(sdk, &self.parent_view.id).await;
|
|
|
|
},
|
|
|
|
FolderScript::RestoreViewFromTrash => {
|
|
|
|
restore_view_from_trash(sdk, &self.child_view.id).await;
|
|
|
|
},
|
|
|
|
FolderScript::ReadTrash => {
|
|
|
|
let trash = read_trash(sdk).await;
|
|
|
|
self.trash = trash.items;
|
|
|
|
},
|
|
|
|
FolderScript::DeleteAllTrash => {
|
|
|
|
delete_all_trash(sdk).await;
|
|
|
|
self.trash = vec![];
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn create_workspace(sdk: &FlowyCoreTest, name: &str, desc: &str) -> WorkspacePB {
|
2023-04-04 00:41:16 +00:00
|
|
|
let request = CreateWorkspacePayloadPB {
|
|
|
|
name: name.to_owned(),
|
|
|
|
desc: desc.to_owned(),
|
|
|
|
};
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(CreateWorkspace)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<WorkspacePB>()
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn read_workspace(sdk: &FlowyCoreTest, workspace_id: Option<String>) -> Vec<WorkspacePB> {
|
2023-04-04 00:41:16 +00:00
|
|
|
let request = WorkspaceIdPB {
|
|
|
|
value: workspace_id,
|
|
|
|
};
|
2023-05-23 15:55:21 +00:00
|
|
|
let repeated_workspace = EventBuilder::new(sdk.clone())
|
2023-06-05 05:10:14 +00:00
|
|
|
.event(ReadAllWorkspaces)
|
2023-04-04 00:41:16 +00:00
|
|
|
.payload(request.clone())
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<RepeatedWorkspacePB>();
|
|
|
|
|
|
|
|
let workspaces;
|
|
|
|
if let Some(workspace_id) = &request.value {
|
|
|
|
workspaces = repeated_workspace
|
|
|
|
.items
|
|
|
|
.into_iter()
|
|
|
|
.filter(|workspace| &workspace.id == workspace_id)
|
|
|
|
.collect::<Vec<WorkspacePB>>();
|
|
|
|
debug_assert_eq!(workspaces.len(), 1);
|
|
|
|
} else {
|
|
|
|
workspaces = repeated_workspace.items;
|
|
|
|
}
|
|
|
|
|
|
|
|
workspaces
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn create_app(sdk: &FlowyCoreTest, workspace_id: &str, name: &str, desc: &str) -> ViewPB {
|
2023-04-04 00:41:16 +00:00
|
|
|
let create_view_request = CreateViewPayloadPB {
|
2023-05-31 06:08:54 +00:00
|
|
|
parent_view_id: workspace_id.to_owned(),
|
2023-04-04 00:41:16 +00:00
|
|
|
name: name.to_string(),
|
|
|
|
desc: desc.to_string(),
|
|
|
|
thumbnail: None,
|
|
|
|
layout: ViewLayout::Document.into(),
|
|
|
|
initial_data: vec![],
|
2023-06-03 05:40:12 +00:00
|
|
|
meta: Default::default(),
|
|
|
|
set_as_current: true,
|
2023-04-04 00:41:16 +00:00
|
|
|
};
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(CreateView)
|
|
|
|
.payload(create_view_request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<ViewPB>()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn create_view(
|
2023-05-23 15:55:21 +00:00
|
|
|
sdk: &FlowyCoreTest,
|
2023-04-04 00:41:16 +00:00
|
|
|
app_id: &str,
|
|
|
|
name: &str,
|
|
|
|
desc: &str,
|
|
|
|
layout: ViewLayout,
|
|
|
|
) -> ViewPB {
|
|
|
|
let request = CreateViewPayloadPB {
|
2023-05-31 06:08:54 +00:00
|
|
|
parent_view_id: app_id.to_string(),
|
2023-04-04 00:41:16 +00:00
|
|
|
name: name.to_string(),
|
|
|
|
desc: desc.to_string(),
|
|
|
|
thumbnail: None,
|
|
|
|
layout: layout.into(),
|
|
|
|
initial_data: vec![],
|
2023-06-03 05:40:12 +00:00
|
|
|
meta: Default::default(),
|
|
|
|
set_as_current: true,
|
2023-04-04 00:41:16 +00:00
|
|
|
};
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(CreateView)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<ViewPB>()
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn read_view(sdk: &FlowyCoreTest, view_id: &str) -> ViewPB {
|
2023-06-05 05:10:14 +00:00
|
|
|
let view_id = ViewIdPB::from(view_id);
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(ReadView)
|
|
|
|
.payload(view_id)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<ViewPB>()
|
|
|
|
}
|
|
|
|
|
2023-07-26 08:49:50 +00:00
|
|
|
pub async fn move_view(
|
|
|
|
sdk: &FlowyCoreTest,
|
|
|
|
view_id: String,
|
|
|
|
parent_id: String,
|
|
|
|
prev_view_id: Option<String>,
|
|
|
|
) {
|
|
|
|
let request = MoveNestedViewPayloadPB {
|
|
|
|
view_id,
|
|
|
|
new_parent_id: parent_id,
|
|
|
|
prev_view_id,
|
|
|
|
};
|
|
|
|
EventBuilder::new(sdk.clone())
|
|
|
|
.event(MoveNestedView)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|
2023-04-04 00:41:16 +00:00
|
|
|
pub async fn update_view(
|
2023-05-23 15:55:21 +00:00
|
|
|
sdk: &FlowyCoreTest,
|
2023-04-04 00:41:16 +00:00
|
|
|
view_id: &str,
|
|
|
|
name: Option<String>,
|
|
|
|
desc: Option<String>,
|
|
|
|
) {
|
|
|
|
let request = UpdateViewPayloadPB {
|
|
|
|
view_id: view_id.to_string(),
|
|
|
|
name,
|
|
|
|
desc,
|
2023-06-14 14:16:33 +00:00
|
|
|
..Default::default()
|
2023-04-04 00:41:16 +00:00
|
|
|
};
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(UpdateView)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn delete_view(sdk: &FlowyCoreTest, view_ids: Vec<String>) {
|
2023-04-04 00:41:16 +00:00
|
|
|
let request = RepeatedViewIdPB { items: view_ids };
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(DeleteView)
|
|
|
|
.payload(request)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn read_trash(sdk: &FlowyCoreTest) -> RepeatedTrashPB {
|
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(ReadTrash)
|
|
|
|
.async_send()
|
|
|
|
.await
|
|
|
|
.parse::<RepeatedTrashPB>()
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn restore_app_from_trash(sdk: &FlowyCoreTest, app_id: &str) {
|
2023-04-04 00:41:16 +00:00
|
|
|
let id = TrashIdPB {
|
|
|
|
id: app_id.to_owned(),
|
|
|
|
};
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(PutbackTrash)
|
|
|
|
.payload(id)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn restore_view_from_trash(sdk: &FlowyCoreTest, view_id: &str) {
|
2023-04-04 00:41:16 +00:00
|
|
|
let id = TrashIdPB {
|
|
|
|
id: view_id.to_owned(),
|
|
|
|
};
|
2023-05-23 15:55:21 +00:00
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(PutbackTrash)
|
|
|
|
.payload(id)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
2023-05-23 15:55:21 +00:00
|
|
|
pub async fn delete_all_trash(sdk: &FlowyCoreTest) {
|
|
|
|
EventBuilder::new(sdk.clone())
|
2023-04-04 00:41:16 +00:00
|
|
|
.event(DeleteAllTrash)
|
|
|
|
.async_send()
|
|
|
|
.await;
|
|
|
|
}
|