Merge pull request #21643 from overleaf/em-tracked-deletes-at-same-position

Improve handling of tracked delete rejections

GitOrigin-RevId: 79308539f5e7af70f6292a0fd6352e882eac84dd
This commit is contained in:
Eric Mc Sween
2024-11-07 09:04:45 +00:00
committed by Copybot
parent c9a6724790
commit bc1e3dacda
2 changed files with 66 additions and 7 deletions
@@ -4,6 +4,7 @@ const RangesTracker = require('../..')
describe('RangesTracker', function () {
describe('with duplicate change ids', function () {
beforeEach(function () {
this.comments = []
this.changes = [
{ id: 'id1', op: { p: 1, i: 'hello' } },
{ id: 'id2', op: { p: 10, i: 'world' } },
@@ -26,4 +27,45 @@ describe('RangesTracker', function () {
expect(this.rangesTracker.changes).to.deep.equal([this.changes[2]])
})
})
describe('with multiple tracked deletes at the same position', function () {
beforeEach(function () {
this.comments = []
this.changes = [
{ id: 'id1', op: { p: 33, d: 'before' } },
{ id: 'id2', op: { p: 50, d: 'right before' } },
{ id: 'id3', op: { p: 50, d: 'this one' } },
{ id: 'id4', op: { p: 50, d: 'right after' } },
{ id: 'id5', op: { p: 75, d: 'long after' } },
]
this.rangesTracker = new RangesTracker(this.changes, this.comments)
})
it('preserves the text order when rejecting changes', function () {
this.rangesTracker.applyOp(
{ p: 50, i: 'this one', u: true },
{ user_id: 'user-id' }
)
expect(this.rangesTracker.changes).to.deep.equal([
{ id: 'id1', op: { p: 33, d: 'before' } },
{ id: 'id2', op: { p: 50, d: 'right before' } },
{ id: 'id4', op: { p: 58, d: 'right after' } },
{ id: 'id5', op: { p: 83, d: 'long after' } },
])
})
it('moves all tracked deletes after the insert if not rejecting changes', function () {
this.rangesTracker.applyOp(
{ p: 50, i: 'some other text', u: true },
{ user_id: 'user-id' }
)
expect(this.rangesTracker.changes).to.deep.equal([
{ id: 'id1', op: { p: 33, d: 'before' } },
{ id: 'id2', op: { p: 65, d: 'right before' } },
{ id: 'id3', op: { p: 65, d: 'this one' } },
{ id: 'id4', op: { p: 65, d: 'right after' } },
{ id: 'id5', op: { p: 90, d: 'long after' } },
])
})
})
})