easy-richtextarea 3.0.154 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,82 @@
1
+ "use strict";
2
+
3
+ const { assert } = require("chai"),
4
+ { arrayUtilities } = require("necessary"),
5
+ { types, InsertOperation, DeleteOperation, generateOperations } = require("../../lib/main"); ///
6
+
7
+ const helpers = require("../helpers");
8
+
9
+ const{ first, second } = arrayUtilities,
10
+ { insertType, deleteType } = types;
11
+
12
+ describe("generateOperations", () => {
13
+ describe("the working and editable contents are the same", () => {
14
+ it("generates a zero length array of operations", () => {
15
+ const workingContent = helpers.content(),
16
+ editableContent = workingContent,
17
+ operations = generateOperations(workingContent, editableContent);
18
+
19
+ assert.lengthOf(operations, 0);
20
+ });
21
+ });
22
+
23
+ describe("the the working content is a subset of the editable content", () => {
24
+ it("generates a array of operations containing an insert operation", () => {
25
+ const workingContent = helpers.content(),
26
+ editableContent = `123${workingContent}`,
27
+ operations = generateOperations(workingContent, editableContent);
28
+
29
+ assert.lengthOf(operations, 1);
30
+
31
+ const firstOperation = first(operations),
32
+ insertOperation = InsertOperation.fromStringAndPosition("123", 0),
33
+ operation = firstOperation, ///
34
+ expectedOperation = insertOperation, ///
35
+ operationJSON = operation.toJSON(),
36
+ expectedOperationJSON = expectedOperation.toJSON();
37
+
38
+ assert.deepEqual(operationJSON, expectedOperationJSON);
39
+ });
40
+ });
41
+
42
+ describe("the editable content is a subset of the the working content", () => {
43
+ it("generates array of operations containing a delete operation", () => {
44
+ const editableContent = helpers.content(),
45
+ workingContent = `xyz${editableContent}`,
46
+ operations = generateOperations(workingContent, editableContent);
47
+
48
+ assert.lengthOf(operations, 1);
49
+
50
+ const firstOperation = first(operations),
51
+ deleteOperation = DeleteOperation.fromLengthAndPosition(3, 0),
52
+ operation = firstOperation, ///
53
+ expectedOperation = deleteOperation, ///
54
+ operationJSON = operation.toJSON(),
55
+ expectedOperationJSON = expectedOperation.toJSON();
56
+
57
+ assert.deepEqual(operationJSON, expectedOperationJSON);
58
+ });
59
+ });
60
+
61
+ describe("the the working and editable contents are different", () => {
62
+ it("generates array of operations containing one delete operation followed by an insert operation", () => {
63
+ const workingContent = helpers.content(),
64
+ editableContent = helpers.content(),
65
+ operations = generateOperations(workingContent, editableContent);
66
+
67
+ assert.lengthOf(operations, 2);
68
+
69
+ const firstOperation = first(operations),
70
+ secondOperation = second(operations),
71
+ firstOperationJSON = firstOperation.toJSON(),
72
+ secondOperationJSON = secondOperation.toJSON(),
73
+ firstOperationType = firstOperationJSON["type"],
74
+ secondOperationType = secondOperationJSON["type"],
75
+ expectedFirstOperationType = deleteType, ///
76
+ expectedSecondOperationType = insertType; ///
77
+
78
+ assert.deepEqual(firstOperationType, expectedFirstOperationType);
79
+ assert.deepEqual(secondOperationType, expectedSecondOperationType);
80
+ });
81
+ });
82
+ });
@@ -0,0 +1,130 @@
1
+ "use strict";
2
+
3
+ const { assert } = require("chai"),
4
+ { transformContent, operationsFromJSON, transformOperations } = require("../../lib/main"); ///
5
+
6
+ const helpers = require("../helpers");
7
+
8
+ describe("transformOperations", () => {
9
+ describe("for two empty sequences of operations", () => {
10
+ it("The intentions are preserved", () => {
11
+ const firstOperationsJSON = [],
12
+ secondOperationsJSON = [],
13
+ firstOperations = operationsFromJSON(firstOperationsJSON),
14
+ secondOperations = operationsFromJSON(secondOperationsJSON);
15
+
16
+ assertIntentionsPreserved(firstOperations, secondOperations);
17
+ });
18
+ });
19
+
20
+ describe("for an array containing one operation and an empty sequence", () => {
21
+ it("The intentions are preserved", () => {
22
+ const firstOperationsJSON = [{
23
+ "type": "insert",
24
+ "string": "xyz",
25
+ "position": 1
26
+ }],
27
+ secondOperationsJSON = [],
28
+ firstOperations = operationsFromJSON(firstOperationsJSON),
29
+ secondOperations = operationsFromJSON(secondOperationsJSON);
30
+
31
+ assertIntentionsPreserved(firstOperations, secondOperations);
32
+ });
33
+ });
34
+
35
+ describe("for two sequences each containing one operation", () => {
36
+ it("The intentions are preserved", () => {
37
+ const firstOperationsJSON = [{
38
+ "type": "insert",
39
+ "string": "xyz",
40
+ "position": 1
41
+ }],
42
+ secondOperationsJSON = [{
43
+ "type": "delete",
44
+ "length": 2,
45
+ "position": 1
46
+ }],
47
+ firstOperations = operationsFromJSON(firstOperationsJSON),
48
+ secondOperations = operationsFromJSON(secondOperationsJSON);
49
+
50
+ assertIntentionsPreserved(firstOperations, secondOperations);
51
+ });
52
+ });
53
+
54
+ describe("for an array containing one operation and a sequence containing two operations", () => {
55
+ it("The intentions are preserved", () => {
56
+ const firstOperationsJSON = [{
57
+ "type": "insert",
58
+ "string": "xyz",
59
+ "position": 1,
60
+ }],
61
+ secondOperationsJSON = [{
62
+ "type": "insert",
63
+ "string": "abc",
64
+ "position": 3
65
+ },
66
+ {
67
+ "type": "delete",
68
+ "length": 2,
69
+ "position": 1,
70
+ }],
71
+ firstOperations = operationsFromJSON(firstOperationsJSON),
72
+ secondOperations = operationsFromJSON(secondOperationsJSON);
73
+
74
+ assertIntentionsPreserved(firstOperations, secondOperations);
75
+ });
76
+ });
77
+
78
+ describe("for two sequences each containing two operations", () => {
79
+ it("The intentions are preserved", () => {
80
+ const firstOperationsJSON = [{
81
+ "type": "delete",
82
+ "length": 6,
83
+ "position": 0
84
+ },
85
+ {
86
+ "type": "insert",
87
+ "string": "JQ",
88
+ "position": 0
89
+ }],
90
+ secondOperationsJSON = [{
91
+ "type": "delete",
92
+ "length": 4,
93
+ "position": 0
94
+ },
95
+ {
96
+ "type": "insert",
97
+ "string": "bkW",
98
+ "position": 0
99
+ }],
100
+ firstOperations = operationsFromJSON(firstOperationsJSON),
101
+ secondOperations = operationsFromJSON(secondOperationsJSON);
102
+
103
+ assertIntentionsPreserved(firstOperations, secondOperations);
104
+ });
105
+ });
106
+
107
+ describe("for two sequences each containing a hundred operations", () => {
108
+ it("The intentions are preserved", () => {
109
+ const content = helpers.content(100),
110
+ firstOperations = helpers.operations(content, 100),
111
+ secondOperations = helpers.operations(content, 100);
112
+
113
+ assertIntentionsPreserved(firstOperations, secondOperations);
114
+ });
115
+ });
116
+ });
117
+
118
+ function assertIntentionsPreserved(firstOperations, secondOperations) {
119
+ const content = helpers.content(100),
120
+ transformedFirstOperations = transformOperations(firstOperations, secondOperations),
121
+ transformedSecondOperations = transformOperations(secondOperations, firstOperations);
122
+
123
+ firstOperations = firstOperations.concat(transformedSecondOperations);
124
+ secondOperations = secondOperations.concat(transformedFirstOperations);
125
+
126
+ const firstTransformedContent = transformContent(content, firstOperations),
127
+ secondTransformedContent = transformContent(content, secondOperations);
128
+
129
+ assert.equal(firstTransformedContent, secondTransformedContent);
130
+ }