chore: implement document editor trait (#1321)

This commit is contained in:
Nathan.fooo
2022-10-20 15:33:18 +08:00
committed by GitHub
parent f1a5726fcb
commit 7dbd9fe8cd
12 changed files with 274 additions and 57 deletions

View File

@ -14,7 +14,7 @@ async fn text_block_sync_current_rev_id_check() {
AssertNextSyncRevId(None),
AssertJson(r#"[{"insert":"123\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -28,7 +28,7 @@ async fn text_block_sync_state_check() {
AssertRevisionState(3, RevisionState::Ack),
AssertJson(r#"[{"insert":"123\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -40,7 +40,7 @@ async fn text_block_sync_insert_test() {
AssertJson(r#"[{"insert":"123\n"}]"#),
AssertNextSyncRevId(None),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -52,7 +52,7 @@ async fn text_block_sync_insert_in_chinese() {
InsertText("", offset),
AssertJson(r#"[{"insert":"你好\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -64,7 +64,7 @@ async fn text_block_sync_insert_with_emoji() {
InsertText("☺️", offset),
AssertJson(r#"[{"insert":"😁☺️\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -76,7 +76,7 @@ async fn text_block_sync_delete_in_english() {
Delete(Interval::new(0, 2)),
AssertJson(r#"[{"insert":"3\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -89,7 +89,7 @@ async fn text_block_sync_delete_in_chinese() {
Delete(Interval::new(0, offset)),
AssertJson(r#"[{"insert":"好\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}
#[tokio::test]
@ -101,5 +101,5 @@ async fn text_block_sync_replace_test() {
Replace(Interval::new(0, 3), "abc"),
AssertJson(r#"[{"insert":"abc\n"}]"#),
];
OldDocumentEditorTest::new().await.run_scripts(scripts).await;
DeltaDocumentEditorTest::new().await.run_scripts(scripts).await;
}

View File

@ -1,4 +1,4 @@
use flowy_document::old_editor::editor::OldDocumentEditor;
use flowy_document::old_editor::editor::DeltaDocumentEditor;
use flowy_document::TEXT_BLOCK_SYNC_INTERVAL_IN_MILLIS;
use flowy_revision::disk::RevisionState;
use flowy_test::{helper::ViewTest, FlowySDKTest};
@ -17,18 +17,18 @@ pub enum EditorScript {
AssertJson(&'static str),
}
pub struct OldDocumentEditorTest {
pub struct DeltaDocumentEditorTest {
pub sdk: FlowySDKTest,
pub editor: Arc<OldDocumentEditor>,
pub editor: Arc<DeltaDocumentEditor>,
}
impl OldDocumentEditorTest {
impl DeltaDocumentEditorTest {
pub async fn new() -> Self {
let sdk = FlowySDKTest::default();
let _ = sdk.init_user().await;
let test = ViewTest::new_document_view(&sdk).await;
let document_editor = sdk.document_manager.open_document_editor(&test.view.id).await.unwrap();
let editor = match document_editor.as_any().downcast_ref::<Arc<OldDocumentEditor>>() {
let editor = match document_editor.as_any().downcast_ref::<Arc<DeltaDocumentEditor>>() {
None => panic!(),
Some(editor) => editor.clone(),
};