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

89 lines
2.3 KiB
Rust
Raw Normal View History

2021-07-20 07:51:49 +00:00
use crate::helper::*;
2021-07-25 00:13:59 +00:00
use flowy_workspace::entities::{
2021-07-31 02:50:56 +00:00
app::{QueryAppRequest, UpdateAppRequest},
view::*,
};
#[test]
fn app_create_success() {
let app = create_app("App A", "AppFlowy Github Project");
2021-07-20 07:51:49 +00:00
dbg!(&app);
}
2021-07-20 06:03:21 +00:00
#[test]
#[should_panic]
fn app_delete_success() {
let app = create_app("App A", "AppFlowy Github Project");
delete_app(&app.id);
let query = QueryAppRequest::new(&app.id);
let _ = read_app(query);
}
2021-07-20 07:51:49 +00:00
#[test]
fn app_create_and_then_get_success() {
let app = create_app("App A", "AppFlowy Github Project");
let query = QueryAppRequest::new(&app.id);
let app_from_db = read_app(query);
2021-07-20 07:51:49 +00:00
assert_eq!(app_from_db, app);
2021-07-20 06:03:21 +00:00
}
#[test]
2021-07-20 07:51:49 +00:00
fn app_create_with_view_and_then_get_success() {
let app = create_app("App A", "AppFlowy Github Project");
2021-07-20 07:51:49 +00:00
let request_a = CreateViewRequest {
2021-07-28 05:41:39 +00:00
belong_to_id: app.id.clone(),
2021-07-20 07:51:49 +00:00
name: "View A".to_string(),
desc: "".to_string(),
thumbnail: None,
2021-07-22 09:39:44 +00:00
view_type: ViewType::Doc,
};
2021-07-20 07:51:49 +00:00
let request_b = CreateViewRequest {
2021-07-28 05:41:39 +00:00
belong_to_id: app.id.clone(),
2021-07-20 07:51:49 +00:00
name: "View B".to_string(),
desc: "".to_string(),
thumbnail: None,
2021-07-22 09:39:44 +00:00
view_type: ViewType::Doc,
2021-07-20 07:51:49 +00:00
};
let view_a = create_view_with_request(request_a);
let view_b = create_view_with_request(request_b);
2021-07-20 07:51:49 +00:00
let query = QueryAppRequest::new(&app.id).set_read_views(true);
let view_from_db = read_app(query);
assert_eq!(view_from_db.belongings[0], view_a);
assert_eq!(view_from_db.belongings[1], view_b);
}
#[test]
fn app_update_with_trash_flag_and_read_with_trash_flag_success() {
let app_id = create_app_with_trash_flag();
let query = QueryAppRequest::new(&app_id).set_is_trash(true);
let _ = read_app(query);
}
#[test]
#[should_panic]
fn app_update_with_trash_flag_and_read_without_trash_flag_fail() {
let app_id = create_app_with_trash_flag();
let query = QueryAppRequest::new(&app_id);
let _ = read_app(query);
}
pub fn create_app_with_trash_flag() -> String {
let app = create_app("App A", "AppFlowy Github Project");
let request = UpdateAppRequest {
app_id: app.id.clone(),
workspace_id: None,
name: None,
desc: None,
color_style: None,
is_trash: Some(true),
};
update_app(request);
app.id
}