2021-09-04 01:00:15 +00:00
|
|
|
use flowy_test::builder::DocTestBuilder;
|
2021-07-23 06:37:18 +00:00
|
|
|
|
2021-07-31 15:22:17 +00:00
|
|
|
use flowy_document::{entities::doc::*, event::EditorEvent::*};
|
2021-07-23 06:37:18 +00:00
|
|
|
use flowy_infra::uuid;
|
2021-09-04 07:12:53 +00:00
|
|
|
use flowy_test::prelude::*;
|
2021-07-23 06:37:18 +00:00
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub fn create_doc(sdk: &FlowyTestSDK, name: &str, desc: &str, text: &str) -> DocInfo {
|
2021-07-23 06:37:18 +00:00
|
|
|
let request = CreateDocRequest {
|
|
|
|
id: uuid(),
|
|
|
|
name: name.to_owned(),
|
|
|
|
desc: desc.to_owned(),
|
2021-07-23 08:45:29 +00:00
|
|
|
text: text.to_owned(),
|
2021-07-23 06:37:18 +00:00
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
let doc = DocTestBuilder::new(sdk.clone())
|
2021-07-23 06:37:18 +00:00
|
|
|
.event(CreateDoc)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
2021-07-24 06:05:49 +00:00
|
|
|
.parse::<DocInfo>();
|
2021-09-03 08:43:03 +00:00
|
|
|
doc
|
2021-07-23 06:37:18 +00:00
|
|
|
}
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub fn save_doc(sdk: &FlowyTestSDK, desc: &DocInfo, content: &str) {
|
2021-07-23 06:37:18 +00:00
|
|
|
let request = UpdateDocRequest {
|
|
|
|
id: desc.id.clone(),
|
|
|
|
name: Some(desc.name.clone()),
|
|
|
|
desc: Some(desc.desc.clone()),
|
2021-07-23 08:45:29 +00:00
|
|
|
text: Some(content.to_owned()),
|
2021-07-23 06:37:18 +00:00
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
let _ = DocTestBuilder::new(sdk.clone()).event(UpdateDoc).request(request).sync_send();
|
2021-07-24 06:05:49 +00:00
|
|
|
}
|
|
|
|
|
2021-09-03 08:43:03 +00:00
|
|
|
// #[allow(dead_code)]
|
|
|
|
// pub fn read_doc(doc_id: &str) -> DocInfo {
|
|
|
|
// let request = QueryDocRequest {
|
|
|
|
// doc_id: doc_id.to_string(),
|
|
|
|
// };
|
|
|
|
//
|
|
|
|
// let doc = AnnieTestBuilder::new()
|
|
|
|
// .event(ReadDocInfo)
|
|
|
|
// .request(request)
|
|
|
|
// .sync_send()
|
|
|
|
// .parse::<DocInfo>();
|
|
|
|
//
|
|
|
|
// doc
|
|
|
|
// }
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
pub(crate) fn read_doc_data(sdk: &FlowyTestSDK, doc_id: &str, path: &str) -> DocData {
|
2021-07-24 06:05:49 +00:00
|
|
|
let request = QueryDocDataRequest {
|
|
|
|
doc_id: doc_id.to_string(),
|
|
|
|
path: path.to_string(),
|
|
|
|
};
|
|
|
|
|
2021-09-04 07:12:53 +00:00
|
|
|
let doc = DocTestBuilder::new(sdk.clone())
|
2021-07-24 06:05:49 +00:00
|
|
|
.event(ReadDocData)
|
|
|
|
.request(request)
|
|
|
|
.sync_send()
|
|
|
|
.parse::<DocData>();
|
2021-07-23 06:37:18 +00:00
|
|
|
|
|
|
|
doc
|
|
|
|
}
|