Skip to content

Commit afd14a4

Browse files
committed
fix (OT-server): tests
1 parent 8e7f12b commit afd14a4

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

packages/collaboration-manager/src/BatchedOperation.spec.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import { createDataKey, IndexBuilder, TextRange } from '@editorjs/model';
1+
import { createDataKey, Index, IndexBuilder, type TextRange } from '@editorjs/model';
22
import { BatchedOperation } from './BatchedOperation.js';
33
import type { SerializedOperation } from './Operation.js';
44
import { Operation, OperationType } from './Operation.js';
55

6-
const createIndexByRange = (range: TextRange) => new IndexBuilder()
6+
const createIndexByRange = (range: TextRange): Index => new IndexBuilder()
77
.addBlockIndex(0)
88
.addDataKey(createDataKey('key'))
99
.addTextRange(range)
1010
.build();
1111

12-
const templateIndex = createIndexByRange([0, 0])
12+
const templateIndex = createIndexByRange([0, 0]);
1313

1414
const userId = 'user';
1515

@@ -98,16 +98,18 @@ describe('Batch', () => {
9898
expect(transformedBatch).not.toBeNull();
9999
expect(transformedBatch!.operations.length).toBe(2);
100100
// Check if text ranges were shifted by 1 due to insertion
101+
/* eslint-disable @typescript-eslint-no-magic-numbers */
101102
expect(transformedBatch!.operations[0].index.textRange![0]).toBe(2);
102103
expect(transformedBatch!.operations[1].index.textRange![0]).toBe(3);
104+
/* eslint-enable @typescript-eslint-no-magic-numbers */
103105
});
104106

105107
it('should return batch with Neutral operations if no operations can be transformed', () => {
106108
const op = new Operation(OperationType.Insert, createIndexByRange([1, 1]), { payload: 'a' }, userId);
107109

108110
const batch = new BatchedOperation(op);
109111

110-
const deleteIndex = createIndexByRange([0, 2])
112+
const deleteIndex = createIndexByRange([0, 2]);
111113

112114
// An operation that would make transformation impossible
113115
const againstOp = new Operation(OperationType.Delete, deleteIndex, { payload: 'a' }, 'other-user');

packages/collaboration-manager/src/CollaborationManager.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ describe('CollaborationManager', () => {
10261026
// Create local delete operation
10271027
const localIndex = new IndexBuilder().addBlockIndex(0)
10281028
.addDataKey(createDataKey('text'))
1029-
.addTextRange([0, 7])
1029+
.addTextRange([0, 0])
10301030
.build();
10311031

10321032
const localOp = new Operation(OperationType.Insert, localIndex, {

packages/collaboration-manager/src/OperationsTransformer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,10 +170,13 @@ export class OperationsTransformer {
170170
return Operation.from(operation);
171171
}
172172

173+
const sameInput = index.dataKey === againstIndex.dataKey;
174+
const sameBlock = index.blockIndex === againstIndex.blockIndex;
175+
173176
/**
174177
* Check that againstOp affects current operation
175178
*/
176-
if (index.dataKey === againstIndex.dataKey && index.blockIndex === againstIndex.blockIndex && againstIndex.textRange![0] >= index.textRange![1]) {
179+
if (sameInput && sameBlock && againstIndex.textRange![0] > index.textRange![1]) {
177180
return Operation.from(operation);
178181
}
179182

@@ -220,6 +223,7 @@ export class OperationsTransformer {
220223

221224
switch (intersectionType) {
222225
case (RangeIntersectionType.None):
226+
case (RangeIntersectionType.Left):
223227
newIndexBuilder.addTextRange([index.textRange![0] + insertedLength, index.textRange![1] + insertedLength]);
224228
break;
225229

packages/collaboration-manager/src/utils/getRangesIntersectionType.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ export function getRangesIntersectionType(range: TextRange, rangeToCompare: Text
2525
/**
2626
* Range is fully on the left or right of the range to compare
2727
*/
28-
if (end <= startToCompare || start >= endToCompare) {
28+
if (end < startToCompare || start > endToCompare) {
2929
return RangeIntersectionType.None;
3030
}
3131

3232
/**
3333
* Range includes the range to compare
3434
* If two ranges are the same, intersection type is "includes"
3535
*/
36-
if (start <= startToCompare && end >= endToCompare) {
36+
if (start <= startToCompare && end >= endToCompare && start != end) {
3737
return RangeIntersectionType.Includes;
3838
}
3939

0 commit comments

Comments
 (0)