Merge pull request #20869 from overleaf/em-ranges-tracker-duplicate-ids

Fix handling of duplicate change ids in RangesTracker

GitOrigin-RevId: 1a75d1dc7e7931c459d2d004973f34d931100d33
This commit is contained in:
Eric Mc Sween
2024-10-14 11:05:30 +00:00
committed by Copybot
parent 139fde750a
commit 16d3d59bc1
5 changed files with 39 additions and 26 deletions
-1
View File
@@ -1 +0,0 @@
// There are no tests yet
@@ -0,0 +1,29 @@
const { expect } = require('chai')
const RangesTracker = require('../..')
describe('RangesTracker', function () {
describe('with duplicate change ids', function () {
beforeEach(function () {
this.changes = [
{ id: 'id1', op: { p: 1, i: 'hello' } },
{ id: 'id2', op: { p: 10, i: 'world' } },
{ id: 'id3', op: { p: 20, i: '!!!' } },
{ id: 'id1', op: { p: 30, d: 'duplicate' } },
]
this.rangesTracker = new RangesTracker(this.changes, this.comments)
})
it('getChanges() returns all changes with the given ids', function () {
expect(this.rangesTracker.getChanges(['id1', 'id2'])).to.deep.equal([
this.changes[0],
this.changes[1],
this.changes[3],
])
})
it('removeChangeIds() removes all changes with the given ids', function () {
this.rangesTracker.removeChangeIds(['id1', 'id2'])
expect(this.rangesTracker.changes).to.deep.equal([this.changes[2]])
})
})
})