mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-28 23:43:46 -05:00
63ff16843c
* [overleaf-editor-core] Introduce ScanOp and subclasses * [overleaf-editor-core] Remove unused methods * [overleaf-editor-core] Add tests for ScanOps * [overleaf-editor-core] Simplify merge * [overleaf-editor-core] Make ApplyContexts mutable * [overleaf-editor-core] Remove unnecessary containsNonBmpChars check * [overleaf-editor-core] Revert to using reduce * [overleaf-editor-core] Modify inputCursor after using it * [overleaf-editor-core] Rename DeleteOp to RemoveOp * [overleaf-editor-core] Remove useless constructor * [overleaf-editor-core] Mutate in mergeWith * [overleaf-editor-core] Add check for out-of-bounds retain * [overleaf-editor-core] Move error import GitOrigin-RevId: d07bd58177579638551257d56f087e8967e5b52f
55 lines
1.9 KiB
JavaScript
55 lines
1.9 KiB
JavaScript
const { expect } = require('chai')
|
|
const EditOperationBuilder = require('../lib/operation/edit_operation_builder')
|
|
const TextOperation = require('../lib/operation/text_operation')
|
|
const EditOperationTransformer = require('../lib/operation/edit_operation_transformer')
|
|
const EditOperation = require('../lib/operation/edit_operation')
|
|
const randomTextOperation = require('./support/random_text_operation')
|
|
const random = require('./support/random')
|
|
|
|
describe('EditOperation', function () {
|
|
it('Cannot be instantiated', function () {
|
|
expect(() => new EditOperation()).to.throw(
|
|
'Cannot instantiate abstract class'
|
|
)
|
|
})
|
|
})
|
|
|
|
describe('EditOperationTransformer', function () {
|
|
it('Transforms two TextOperations', function () {
|
|
const a = new TextOperation().insert('foo')
|
|
const b = new TextOperation().insert('bar')
|
|
const [aPrime, bPrime] = EditOperationTransformer.transform(a, b)
|
|
expect(aPrime).to.be.an.instanceof(TextOperation)
|
|
expect(bPrime).to.be.an.instanceof(TextOperation)
|
|
})
|
|
})
|
|
|
|
describe('EditOperationBuilder', function () {
|
|
it('Constructs TextOperation from JSON', function () {
|
|
const raw = {
|
|
textOperation: [1, 'foo', 3],
|
|
}
|
|
const op = EditOperationBuilder.fromJSON(raw)
|
|
expect(op).to.be.an.instanceof(TextOperation)
|
|
expect(op.toJSON()).to.deep.equal(raw)
|
|
})
|
|
|
|
it('Throws error for unsupported operation', function () {
|
|
const raw = {
|
|
unsupportedOperation: {
|
|
op: 'foo',
|
|
},
|
|
}
|
|
expect(() => EditOperationBuilder.fromJSON(raw)).to.throw(
|
|
'Unsupported operation in EditOperationBuilder.fromJSON'
|
|
)
|
|
})
|
|
|
|
it('Constructs TextOperation from JSON (randomised)', function () {
|
|
const str = random.string(50)
|
|
const randomOperation = randomTextOperation(str)
|
|
const op = EditOperationBuilder.fromJSON(randomOperation.toJSON())
|
|
expect(op).to.be.an.instanceof(TextOperation)
|
|
expect(op.equals(randomOperation)).to.be.true
|
|
})
|
|
})
|