2021-09-27 15:23:23 +00:00
|
|
|
use crate::document::helper::{DocScript, DocumentTest};
|
2021-10-04 06:24:35 +00:00
|
|
|
use flowy_document::services::doc::{Document, FlowyDoc};
|
|
|
|
use flowy_ot::core::Delta;
|
2021-09-27 15:23:23 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
2021-10-04 06:24:35 +00:00
|
|
|
async fn sync_doc_insert_text() {
|
2021-09-27 15:23:23 +00:00
|
|
|
let test = DocumentTest::new().await;
|
2021-09-29 09:40:34 +00:00
|
|
|
test.run_scripts(vec![
|
2021-10-03 03:33:19 +00:00
|
|
|
DocScript::ConnectWs,
|
2021-10-04 06:24:35 +00:00
|
|
|
DocScript::OpenDoc,
|
2021-09-29 09:40:34 +00:00
|
|
|
DocScript::SendText(0, "abc"),
|
|
|
|
DocScript::SendText(3, "123"),
|
|
|
|
DocScript::SendText(6, "efg"),
|
|
|
|
DocScript::AssertClient(r#"[{"insert":"abc123efg\n"}]"#),
|
|
|
|
DocScript::AssertServer(r#"[{"insert":"abc123efg\n"}]"#),
|
|
|
|
])
|
|
|
|
.await;
|
2021-09-27 15:23:23 +00:00
|
|
|
}
|
2021-09-30 09:24:02 +00:00
|
|
|
|
|
|
|
#[actix_rt::test]
|
2021-10-04 06:24:35 +00:00
|
|
|
async fn sync_open_empty_doc_and_sync_from_server() {
|
2021-09-30 09:24:02 +00:00
|
|
|
let test = DocumentTest::new().await;
|
2021-10-04 06:24:35 +00:00
|
|
|
let mut document = Document::new::<FlowyDoc>();
|
|
|
|
document.insert(0, "123").unwrap();
|
|
|
|
document.insert(3, "456").unwrap();
|
|
|
|
let json = document.to_json();
|
2021-09-30 09:24:02 +00:00
|
|
|
|
|
|
|
test.run_scripts(vec![
|
2021-10-04 06:24:35 +00:00
|
|
|
DocScript::SetServerDocument(json, 3),
|
|
|
|
DocScript::OpenDoc,
|
|
|
|
DocScript::AssertClient(r#"[{"insert":"123456\n"}]"#),
|
|
|
|
DocScript::AssertServer(r#"[{"insert":"123456\n"}]"#),
|
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn sync_open_empty_doc_and_sync_from_server_using_ws() {
|
|
|
|
let test = DocumentTest::new().await;
|
|
|
|
let mut document = Document::new::<FlowyDoc>();
|
|
|
|
document.insert(0, "123").unwrap();
|
|
|
|
let json = document.to_json();
|
|
|
|
|
|
|
|
test.run_scripts(vec![
|
|
|
|
DocScript::OpenDoc,
|
|
|
|
DocScript::SetServerDocument(json, 3),
|
2021-09-30 09:24:02 +00:00
|
|
|
DocScript::ConnectWs,
|
2021-10-04 09:38:56 +00:00
|
|
|
DocScript::AssertClient(r#"[{"insert":"\n123\n"}]"#),
|
2021-10-04 06:24:35 +00:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|
|
|
|
|
|
|
|
#[actix_rt::test]
|
|
|
|
async fn sync_open_non_empty_doc_and_sync_with_sever() {
|
|
|
|
let test = DocumentTest::new().await;
|
|
|
|
let mut document = Document::new::<FlowyDoc>();
|
|
|
|
document.insert(0, "123").unwrap();
|
|
|
|
let json = document.to_json();
|
|
|
|
|
|
|
|
test.run_scripts(vec![
|
|
|
|
DocScript::OpenDoc,
|
|
|
|
DocScript::SetServerDocument(json, 3),
|
2021-09-30 09:24:02 +00:00
|
|
|
DocScript::SendText(0, "abc"),
|
2021-10-04 06:24:35 +00:00
|
|
|
DocScript::ConnectWs,
|
2021-10-04 09:38:56 +00:00
|
|
|
DocScript::AssertClient(r#"[{"insert":"abc\n123\n"}]"#),
|
|
|
|
DocScript::AssertServer(r#"[{"insert":"abc\n123\n"}]"#),
|
2021-09-30 09:24:02 +00:00
|
|
|
])
|
|
|
|
.await;
|
|
|
|
}
|