forked from FirebaseExtended/firepad
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathoperation-meta.spec.ts
72 lines (66 loc) · 2.84 KB
/
operation-meta.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { Cursor } from "../src/cursor";
import { OperationMeta } from "../src/operation-meta";
import { TextOperation } from "../src/text-operation";
describe("Operation Metadata", () => {
describe("#clone", () => {
it("should create deep clone of Operation Metadata object", () => {
const cursorBefore = new Cursor(1, 4);
const cursorAfter = new Cursor(2, 8);
const operationMeta = new OperationMeta(cursorBefore, cursorAfter);
expect(operationMeta.clone()).toEqual(operationMeta);
});
});
describe("#invert", () => {
it("should swap properties of Operation Metadata object", () => {
const cursorBefore = new Cursor(1, 4);
const cursorAfter = new Cursor(2, 8);
const operationMeta = new OperationMeta(cursorBefore, cursorAfter);
const invertMeta = new OperationMeta(cursorAfter, cursorBefore);
expect(operationMeta.invert()).toEqual(invertMeta);
});
});
describe("#compose", () => {
it("should merge properties of two Operation Metadata object", () => {
const cursorBefore = new Cursor(1, 4);
const cursorAfter = new Cursor(2, 8);
const operationMeta = new OperationMeta(cursorBefore, cursorAfter);
const cursorBeforeOther = new Cursor(3, 3);
const cursorAfterOther = new Cursor(4, 9);
const operationMetaOther = new OperationMeta(
cursorBeforeOther,
cursorAfterOther
);
const composedMeta = new OperationMeta(cursorBefore, cursorAfterOther);
expect(operationMeta.compose(operationMetaOther)).toEqual(composedMeta);
});
});
describe("#transform", () => {
it("should transform properties of Operation Metadata object", () => {
const cursorBefore = new Cursor(1, 4);
const cursorAfter = new Cursor(2, 8);
const operationMeta = new OperationMeta(cursorBefore, cursorAfter);
const operation = new TextOperation().insert("Hello World", null); // 11 letters inserted.
const cursorBeforeTransformed = new Cursor(12, 15);
const cursorAfterTransformed = new Cursor(13, 19);
const transformedMeta = new OperationMeta(
cursorBeforeTransformed,
cursorAfterTransformed
);
expect(operationMeta.transform(operation)).toEqual(transformedMeta);
});
it("should not throw error for null values", () => {
const operationMeta = new OperationMeta(null, null);
const operation = new TextOperation().retain(12, null);
const fn = () => operationMeta.transform(operation);
expect(fn).not.toThrowError();
});
});
describe("#getCursor", () => {
it("should return final position of the Cursor", () => {
const cursorBefore = new Cursor(1, 4);
const cursorAfter = new Cursor(2, 8);
const operationMeta = new OperationMeta(cursorBefore, cursorAfter);
expect(operationMeta.getCursor()).toEqual(cursorAfter);
});
});
});