mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
[client]: add putback test
This commit is contained in:
parent
2513853ea4
commit
ab36f520de
@ -1,7 +1,12 @@
|
||||
use crate::prelude::*;
|
||||
use flowy_document::entities::doc::Doc;
|
||||
use flowy_workspace::{
|
||||
entities::{app::*, view::*, workspace::*},
|
||||
entities::{
|
||||
app::*,
|
||||
trash::{RepeatedTrash, TrashIdentifier},
|
||||
view::*,
|
||||
workspace::*,
|
||||
},
|
||||
event::WorkspaceEvent::*,
|
||||
};
|
||||
|
||||
@ -233,6 +238,22 @@ pub async fn delete_view(sdk: &FlowyTestSDK, request: DeleteViewRequest) {
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn read_trash(sdk: &FlowyTestSDK) -> RepeatedTrash {
|
||||
FlowyWorkspaceTest::new(sdk.clone())
|
||||
.event(ReadTrash)
|
||||
.async_send()
|
||||
.await
|
||||
.parse::<RepeatedTrash>()
|
||||
}
|
||||
|
||||
pub async fn putback_trash(sdk: &FlowyTestSDK, id: TrashIdentifier) {
|
||||
FlowyWorkspaceTest::new(sdk.clone())
|
||||
.event(PutbackTrash)
|
||||
.request(id)
|
||||
.async_send()
|
||||
.await;
|
||||
}
|
||||
|
||||
pub async fn open_view(sdk: &FlowyTestSDK, request: OpenViewRequest) -> Doc {
|
||||
FlowyWorkspaceTest::new(sdk.clone())
|
||||
.event(OpenView)
|
||||
|
@ -50,7 +50,7 @@ impl WorkspaceError {
|
||||
static_workspace_error!(view_data, ErrorCode::ViewDataInvalid);
|
||||
static_workspace_error!(unauthorized, ErrorCode::UserUnauthorized);
|
||||
static_workspace_error!(internal, ErrorCode::InternalError);
|
||||
static_workspace_error!(not_found, ErrorCode::RecordNotFound);
|
||||
static_workspace_error!(record_not_found, ErrorCode::RecordNotFound);
|
||||
static_workspace_error!(ws, ErrorCode::WsConnectError);
|
||||
|
||||
pub fn context<T: Debug>(mut self, error: T) -> Self {
|
||||
|
@ -83,6 +83,12 @@ impl ViewController {
|
||||
pub(crate) async fn read_view(&self, params: ViewIdentifier) -> Result<View, WorkspaceError> {
|
||||
let conn = self.database.db_connection()?;
|
||||
let view_table = ViewTableSql::read_view(¶ms.view_id, &*conn)?;
|
||||
|
||||
let trash_ids = self.trash_can.trash_ids(&conn)?;
|
||||
if trash_ids.contains(&view_table.id) {
|
||||
return Err(WorkspaceError::record_not_found());
|
||||
}
|
||||
|
||||
let view: View = view_table.into();
|
||||
let _ = self.read_view_on_server(params);
|
||||
Ok(view)
|
||||
|
@ -191,7 +191,7 @@ impl WorkspaceController {
|
||||
// Opti: fetch single workspace from local db
|
||||
let mut repeated_workspace = self.read_local_workspaces(Some(workspace_id.clone()), user_id, conn)?;
|
||||
if repeated_workspace.is_empty() {
|
||||
return Err(WorkspaceError::not_found().context(format!("{} workspace not found", workspace_id)));
|
||||
return Err(WorkspaceError::record_not_found().context(format!("{} workspace not found", workspace_id)));
|
||||
}
|
||||
|
||||
debug_assert_eq!(repeated_workspace.len(), 1);
|
||||
@ -313,9 +313,8 @@ fn set_current_workspace(workspace: &str) { KV::set_str(CURRENT_WORKSPACE_ID, wo
|
||||
|
||||
fn get_current_workspace() -> Result<String, WorkspaceError> {
|
||||
match KV::get_str(CURRENT_WORKSPACE_ID) {
|
||||
None => {
|
||||
Err(WorkspaceError::not_found().context("Current workspace not found or should call open workspace first"))
|
||||
},
|
||||
None => Err(WorkspaceError::record_not_found()
|
||||
.context("Current workspace not found or should call open workspace first")),
|
||||
Some(workspace_id) => Ok(workspace_id),
|
||||
}
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
use flowy_test::{workspace::*, FlowyTest};
|
||||
use flowy_workspace::entities::view::*;
|
||||
use flowy_workspace::entities::{trash::TrashIdentifier, view::*};
|
||||
|
||||
#[tokio::test]
|
||||
#[should_panic]
|
||||
async fn view_move_to_trash() {
|
||||
async fn view_delete() {
|
||||
let test = FlowyTest::setup();
|
||||
let _ = test.init_user();
|
||||
|
||||
@ -13,6 +13,26 @@ async fn view_move_to_trash() {
|
||||
let _ = read_view(&test.sdk, query).await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn view_delete_and_putback() {
|
||||
let test = FlowyTest::setup();
|
||||
let _ = test.init_user();
|
||||
|
||||
let test = ViewTest::new(&test).await;
|
||||
test.delete().await;
|
||||
putback_trash(
|
||||
&test.sdk,
|
||||
TrashIdentifier {
|
||||
id: test.view.id.clone(),
|
||||
},
|
||||
)
|
||||
.await;
|
||||
|
||||
let query = QueryViewRequest::new(&test.view.id);
|
||||
let view = read_view(&test.sdk, query).await;
|
||||
assert_eq!(&view, &test.view);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn view_open_doc() {
|
||||
let test = FlowyTest::setup();
|
||||
|
Loading…
Reference in New Issue
Block a user