2020-05-06 06:11:36 -04:00
|
|
|
const sinon = require('sinon')
|
2021-04-01 15:51:00 -04:00
|
|
|
const { expect } = require('chai')
|
2020-05-06 06:11:36 -04:00
|
|
|
const modulePath = '../../../../app/js/DiffCodec.js'
|
|
|
|
const SandboxedModule = require('sandboxed-module')
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2020-05-06 06:11:36 -04:00
|
|
|
describe('DiffCodec', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.callback = sinon.stub()
|
2024-04-02 09:49:33 -04:00
|
|
|
this.DiffCodec = SandboxedModule.require(modulePath)
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2024-04-02 09:49:33 -04:00
|
|
|
describe('diffAsShareJsOps', function () {
|
|
|
|
it('should insert new text correctly', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.before = ['hello world']
|
|
|
|
this.after = ['hello beautiful world']
|
2024-04-02 09:49:33 -04:00
|
|
|
const ops = this.DiffCodec.diffAsShareJsOp(this.before, this.after)
|
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{
|
|
|
|
i: 'beautiful ',
|
|
|
|
p: 6,
|
|
|
|
},
|
|
|
|
])
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2024-04-02 09:49:33 -04:00
|
|
|
it('should shift later inserts by previous inserts', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.before = ['the boy played with the ball']
|
|
|
|
this.after = ['the tall boy played with the red ball']
|
2024-04-02 09:49:33 -04:00
|
|
|
const ops = this.DiffCodec.diffAsShareJsOp(this.before, this.after)
|
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{ i: 'tall ', p: 4 },
|
|
|
|
{ i: 'red ', p: 29 },
|
|
|
|
])
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2024-04-02 09:49:33 -04:00
|
|
|
it('should delete text correctly', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.before = ['hello beautiful world']
|
|
|
|
this.after = ['hello world']
|
2024-04-02 09:49:33 -04:00
|
|
|
const ops = this.DiffCodec.diffAsShareJsOp(this.before, this.after)
|
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{
|
|
|
|
d: 'beautiful ',
|
|
|
|
p: 6,
|
|
|
|
},
|
|
|
|
])
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
2014-02-12 05:40:42 -05:00
|
|
|
|
2024-04-02 09:49:33 -04:00
|
|
|
it('should shift later deletes by the first deletes', function () {
|
2020-05-06 06:11:36 -04:00
|
|
|
this.before = ['the tall boy played with the red ball']
|
|
|
|
this.after = ['the boy played with the ball']
|
2024-04-02 09:49:33 -04:00
|
|
|
const ops = this.DiffCodec.diffAsShareJsOp(this.before, this.after)
|
|
|
|
expect(ops).to.deep.equal([
|
|
|
|
{ d: 'tall ', p: 4 },
|
|
|
|
{ d: 'red ', p: 24 },
|
|
|
|
])
|
2020-05-06 06:11:36 -04:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|