2021-08-06 00:40:45 +00:00
|
|
|
pub mod helper;
|
|
|
|
|
|
|
|
use crate::helper::{TestOp::*, *};
|
2021-08-10 03:22:57 +00:00
|
|
|
use flowy_ot::{client::RECORD_THRESHOLD, core::Interval};
|
2021-08-06 00:40:45 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_insert() {
|
2021-08-06 15:06:27 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-06 00:40:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_insert2() {
|
2021-08-06 00:40:45 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-06 00:40:45 +00:00
|
|
|
Insert(0, "456", 0),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-06 00:40:45 +00:00
|
|
|
}
|
2021-08-06 14:25:09 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_insert() {
|
2021-08-06 14:25:09 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-06 14:25:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_insert_with_lagging() {
|
2021-08-06 14:25:09 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-06 14:25:09 +00:00
|
|
|
Insert(0, "456", 3),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-06 14:25:09 +00:00
|
|
|
AssertStr(0, "123456\n"),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123456\n"}]"#),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123456\n"}]"#),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-06 14:25:09 +00:00
|
|
|
}
|
2021-08-07 01:19:18 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_attributes() {
|
2021-08-07 01:19:18 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Undo(0),
|
2021-08-10 03:22:57 +00:00
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_attributes_with_lagging() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Wait(RECORD_THRESHOLD),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Undo(0),
|
2021-08-07 01:19:18 +00:00
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-07 01:19:18 +00:00
|
|
|
}
|
2021-08-08 14:29:16 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_attributes() {
|
2021-08-08 14:29:16 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Undo(0),
|
2021-08-10 03:22:57 +00:00
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
2021-08-08 14:29:16 +00:00
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#" [{"insert":"123","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-08 14:29:16 +00:00
|
|
|
}
|
2021-08-09 03:29:37 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_attributes_with_lagging() {
|
2021-08-09 03:29:37 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-09 03:29:37 +00:00
|
|
|
Bold(0, Interval::new(0, 3), true),
|
2021-08-10 03:22:57 +00:00
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123\n"}]"#),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_delete() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"123"}]"#),
|
2021-08-09 03:29:37 +00:00
|
|
|
Delete(0, Interval::new(0, 3)),
|
2021-08-10 03:22:57 +00:00
|
|
|
AssertOpsJson(0, r#"[]"#),
|
2021-08-09 03:29:37 +00:00
|
|
|
Undo(0),
|
2021-08-10 03:22:57 +00:00
|
|
|
AssertOpsJson(0, r#"[{"insert":"123"}]"#),
|
|
|
|
];
|
|
|
|
OpTester::new().run_script(ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_delete2() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Delete(0, Interval::new(0, 1)),
|
2021-08-09 03:29:37 +00:00
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
2021-08-10 03:22:57 +00:00
|
|
|
{"insert":"23","attributes":{"bold":"true"}},
|
2021-08-09 03:29:37 +00:00
|
|
|
{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
2021-08-10 03:22:57 +00:00
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
2021-08-09 03:29:37 +00:00
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-09 03:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_delete2_with_lagging() {
|
2021-08-09 03:29:37 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-09 03:29:37 +00:00
|
|
|
Bold(0, Interval::new(0, 3), true),
|
2021-08-10 03:22:57 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-09 03:29:37 +00:00
|
|
|
Delete(0, Interval::new(0, 1)),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"23","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"123","attributes":{"bold":"true"}},
|
|
|
|
{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-09 03:29:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_delete() {
|
2021-08-09 03:29:37 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
2021-08-14 08:44:39 +00:00
|
|
|
Wait(RECORD_THRESHOLD),
|
2021-08-09 03:29:37 +00:00
|
|
|
Delete(0, Interval::new(0, 3)),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
Undo(0),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-09 03:29:37 +00:00
|
|
|
}
|
2021-08-10 03:22:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_replace() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Replace(0, Interval::new(0, 2), "ab"),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"ab"},
|
|
|
|
{"insert":"3","attributes":{"bold":"true"}},{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"\n"}]"#),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_undo_replace_with_lagging() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Wait(RECORD_THRESHOLD),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Wait(RECORD_THRESHOLD),
|
|
|
|
Replace(0, Interval::new(0, 2), "ab"),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"ab"},
|
|
|
|
{"insert":"3","attributes":{"bold":"true"}},{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"123","attributes":{"bold":"true"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-08-16 07:02:57 +00:00
|
|
|
fn history_redo_replace() {
|
2021-08-10 03:22:57 +00:00
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123", 0),
|
|
|
|
Bold(0, Interval::new(0, 3), true),
|
|
|
|
Replace(0, Interval::new(0, 2), "ab"),
|
|
|
|
Undo(0),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[
|
|
|
|
{"insert":"ab"},
|
|
|
|
{"insert":"3","attributes":{"bold":"true"}},{"insert":"\n"}]
|
|
|
|
"#,
|
|
|
|
),
|
|
|
|
];
|
2021-08-11 15:34:35 +00:00
|
|
|
OpTester::new().run_script_with_newline(ops);
|
2021-08-10 03:22:57 +00:00
|
|
|
}
|
2021-08-16 07:02:57 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn history_undo_add_header() {
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, "123456", 0),
|
|
|
|
Header(0, Interval::new(0, 6), 1, true),
|
|
|
|
Insert(0, "\n", 3),
|
|
|
|
Insert(0, "\n", 4),
|
|
|
|
Undo(0),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"123"},{"insert":"\n\n","attributes":{"header":"1"}},{"insert":"456"},{"insert":"\n","attributes":{"header":"1"}}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
OpTester::new().run_script_with_newline(ops);
|
|
|
|
}
|
2021-08-16 15:07:40 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn history_undo_add_link() {
|
|
|
|
let site = "https://appflowy.io";
|
|
|
|
let ops = vec![
|
|
|
|
Insert(0, site, 0),
|
|
|
|
Wait(RECORD_THRESHOLD),
|
|
|
|
Link(0, Interval::new(0, site.len()), site, true),
|
|
|
|
Undo(0),
|
|
|
|
AssertOpsJson(0, r#"[{"insert":"https://appflowy.io\n"}]"#),
|
|
|
|
Redo(0),
|
|
|
|
AssertOpsJson(
|
|
|
|
0,
|
|
|
|
r#"[{"insert":"https://appflowy.io","attributes":{"link":"https://appflowy.io"}},{"insert":"\n"}]"#,
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
OpTester::new().run_script_with_newline(ops);
|
|
|
|
}
|