[client]: add test

This commit is contained in:
appflowy 2021-10-18 22:46:05 +08:00
parent 98836f821b
commit fc498fbc8e
8 changed files with 68 additions and 33 deletions

View File

@ -38,10 +38,7 @@ import 'widget/menu_trash.dart';
//
//
// MenuApp
//
//
// AppListenBloc Receive view changes
//
//
class HomeMenu extends StatelessWidget {
final Function(HomeStackContext) pageContextChanged;

View File

@ -1,6 +1,7 @@
use crate::helper::*;
use flowy_workspace::entities::{
app::{AppIdentifier, DeleteAppParams, UpdateAppParams},
trash::{TrashIdentifier, TrashIdentifiers, TrashType},
view::{UpdateViewParams, ViewIdentifier},
workspace::{CreateWorkspaceParams, DeleteWorkspaceParams, QueryWorkspaceParams, UpdateWorkspaceParams},
};
@ -173,11 +174,25 @@ async fn view_delete() {
}
#[actix_rt::test]
async fn view_delete_and_then_delete_the_trash_record() {
async fn trash_delete() {
let test = ViewTest::new().await;
test.server.create_view_trash(&test.view.id).await;
test.server.delete_view_trash(&test.view.id).await;
let identifier = TrashIdentifier {
id: test.view.id.clone(),
ty: TrashType::View,
};
test.server.delete_view_trash(vec![identifier].into()).await;
assert_eq!(test.server.read_trash().await.is_empty(), true);
}
#[actix_rt::test]
async fn trash_delete_all() {
let test = ViewTest::new().await;
test.server.create_view_trash(&test.view.id).await;
test.server.delete_view_trash(TrashIdentifiers::all()).await;
assert_eq!(test.server.read_trash().await.is_empty(), true);
}

View File

@ -133,14 +133,10 @@ impl TestUserServer {
.unwrap();
}
pub async fn delete_view_trash(&self, trash_id: &str) {
pub async fn delete_view_trash(&self, trash_identifiers: TrashIdentifiers) {
let url = format!("{}/api/trash", self.http_addr());
let identifier = TrashIdentifier {
id: trash_id.to_string(),
ty: TrashType::View,
};
delete_trash_request(self.user_token(), vec![identifier].into(), &url)
delete_trash_request(self.user_token(), trash_identifiers, &url)
.await
.unwrap();
}

View File

@ -82,12 +82,17 @@ impl ViewTest {
}
}
pub async fn delete(&self) {
let request = DeleteViewRequest {
view_ids: vec![self.view.id.clone()],
};
pub async fn delete_view(&self, view_ids: Vec<String>) {
let request = DeleteViewRequest { view_ids };
delete_view(&self.sdk, request).await;
}
pub async fn delete_all_view(&self) {
FlowyWorkspaceTest::new(self.sdk.clone())
.event(DeleteAll)
.async_send()
.await;
}
}
pub fn invalid_workspace_name_test_case() -> Vec<String> {
@ -123,11 +128,12 @@ async fn open_workspace(sdk: &FlowyTestSDK, workspace_id: &str) {
.await;
}
pub fn read_workspace(sdk: &FlowyTestSDK, request: QueryWorkspaceRequest) -> Option<Workspace> {
pub async fn read_workspace(sdk: &FlowyTestSDK, request: QueryWorkspaceRequest) -> Option<Workspace> {
let mut repeated_workspace = FlowyWorkspaceTest::new(sdk.clone())
.event(ReadWorkspaces)
.request(request.clone())
.sync_send()
.async_send()
.await
.parse::<RepeatedWorkspace>();
let mut workspaces;
@ -162,7 +168,7 @@ pub async fn create_app(sdk: &FlowyTestSDK, name: &str, desc: &str, workspace_id
app
}
pub fn delete_app(sdk: &FlowyTestSDK, app_id: &str) {
pub async fn delete_app(sdk: &FlowyTestSDK, app_id: &str) {
let delete_app_request = DeleteAppRequest {
app_id: app_id.to_string(),
};
@ -170,7 +176,8 @@ pub fn delete_app(sdk: &FlowyTestSDK, app_id: &str) {
FlowyWorkspaceTest::new(sdk.clone())
.event(DeleteApp)
.request(delete_app_request)
.sync_send();
.async_send()
.await;
}
pub async fn update_app(sdk: &FlowyTestSDK, request: UpdateAppRequest) {
@ -181,11 +188,12 @@ pub async fn update_app(sdk: &FlowyTestSDK, request: UpdateAppRequest) {
.await;
}
pub fn read_app(sdk: &FlowyTestSDK, request: QueryAppRequest) -> App {
pub async fn read_app(sdk: &FlowyTestSDK, request: QueryAppRequest) -> App {
let app = FlowyWorkspaceTest::new(sdk.clone())
.event(ReadApp)
.request(request)
.sync_send()
.async_send()
.await
.parse::<App>();
app

View File

@ -2,7 +2,7 @@ use crate::{entities::app::parser::AppId, errors::*};
use flowy_derive::ProtoBuf;
use std::convert::TryInto;
#[derive(Default, ProtoBuf)]
#[derive(Default, ProtoBuf, Clone)]
pub struct QueryAppRequest {
#[pb(index = 1)]
pub app_id: String,

View File

@ -5,16 +5,16 @@ use flowy_workspace::entities::{app::QueryAppRequest, view::*};
#[should_panic]
async fn app_delete() {
let test = AppTest::new().await;
delete_app(&test.sdk, &test.app.id);
delete_app(&test.sdk, &test.app.id).await;
let query = QueryAppRequest::new(&test.app.id);
let _ = read_app(&test.sdk, query);
let _ = read_app(&test.sdk, query).await;
}
#[tokio::test]
async fn app_read() {
let test = AppTest::new().await;
let query = QueryAppRequest::new(&test.app.id);
let app_from_db = read_app(&test.sdk, query);
let app_from_db = read_app(&test.sdk, query).await;
assert_eq!(app_from_db, test.app);
}
@ -41,7 +41,7 @@ async fn app_create_with_view() {
let view_b = create_view_with_request(&test.sdk, request_b).await;
let query = QueryAppRequest::new(&test.app.id);
let view_from_db = read_app(&test.sdk, query);
let view_from_db = read_app(&test.sdk, query).await;
assert_eq!(view_from_db.belongings[0], view_a);
assert_eq!(view_from_db.belongings[1], view_b);

View File

@ -1,8 +1,10 @@
use flowy_test::{workspace::*, FlowyTest};
use flowy_workspace::entities::{
app::QueryAppRequest,
trash::{TrashIdentifier, TrashType},
view::*,
};
use tokio::time::{sleep, Duration};
#[tokio::test]
#[should_panic]
@ -11,18 +13,18 @@ async fn view_delete() {
let _ = test.init_user();
let test = ViewTest::new(&test).await;
test.delete().await;
test.delete_view(vec![test.view.id.clone()]).await;
let query = QueryViewRequest::new(&test.view.id);
let _ = read_view(&test.sdk, query).await;
}
#[tokio::test]
async fn view_delete_and_putback() {
async fn view_delete_then_putback() {
let test = FlowyTest::setup();
let _ = test.init_user();
let test = ViewTest::new(&test).await;
test.delete().await;
test.delete_view(vec![test.view.id.clone()]).await;
putback_trash(
&test.sdk,
TrashIdentifier {
@ -37,6 +39,23 @@ async fn view_delete_and_putback() {
assert_eq!(&view, &test.view);
}
#[tokio::test]
async fn view_delete_all() {
let test = FlowyTest::setup();
let _ = test.init_user();
let test = ViewTest::new(&test).await;
let _ = create_view(&test.sdk, &test.app.id).await;
let _ = create_view(&test.sdk, &test.app.id).await;
let query = QueryAppRequest::new(&test.app.id);
let app = read_app(&test.sdk, query.clone()).await;
assert_eq!(app.belongings.len(), 3);
test.delete_all_view().await;
sleep(Duration::from_secs(1)).await;
assert_eq!(read_app(&test.sdk, query).await.belongings.len(), 0);
}
#[tokio::test]
async fn view_open_doc() {
let test = FlowyTest::setup();

View File

@ -8,7 +8,7 @@ use flowy_workspace::{
#[tokio::test]
async fn workspace_read_all() {
let test = WorkspaceTest::new().await;
let workspace = read_workspace(&test.sdk, QueryWorkspaceRequest::new()).unwrap();
let workspace = read_workspace(&test.sdk, QueryWorkspaceRequest::new()).await.unwrap();
assert_eq!(test.workspace, workspace);
}
@ -16,7 +16,7 @@ async fn workspace_read_all() {
async fn workspace_read() {
let test = WorkspaceTest::new().await;
let request = QueryWorkspaceRequest::new().workspace_id(&test.workspace.id);
let workspace = read_workspace(&test.sdk, request).unwrap();
let workspace = read_workspace(&test.sdk, request).await.unwrap();
assert_eq!(test.workspace, workspace);
}
@ -25,7 +25,7 @@ async fn workspace_create_with_apps() {
let test = WorkspaceTest::new().await;
let app = create_app(&test.sdk, "App A", "AppFlowy Github Project", &test.workspace.id).await;
let request = QueryWorkspaceRequest::new().workspace_id(&test.workspace.id);
let workspace_from_db = read_workspace(&test.sdk, request).unwrap();
let workspace_from_db = read_workspace(&test.sdk, request).await.unwrap();
assert_eq!(&app, workspace_from_db.apps.first_or_crash());
}