overleaf/services/document-updater/test/unit/js/UtilsTests.js
Eric Mc Sween 8e662b33fb Merge pull request #17711 from overleaf/em-resync-tracked-deletes
Include tracked deletes in resync doc update

GitOrigin-RevId: 410f9435f92ff44184f60a2695be27d7b819a1e2
2024-04-09 08:04:40 +00:00

27 lines
1 KiB
JavaScript

// @ts-check
const { expect } = require('chai')
const Utils = require('../../../app/js/Utils')
describe('Utils', function () {
describe('addTrackedDeletesToContent', function () {
it("doesn't modify text without tracked deletes", function () {
const content = 'the quick brown fox'
const trackedChanges = []
const result = Utils.addTrackedDeletesToContent(content, trackedChanges)
expect(result).to.equal(content)
})
it('adds tracked deletes to text but skips tracked inserts', function () {
const content = 'the brown fox jumps over the dog'
const metadata = { user_id: 'user1', ts: new Date().toString() }
const trackedChanges = [
{ id: 'tc1', op: { d: 'quick ', p: 4 }, metadata },
{ id: 'tc2', op: { i: 'brown ', p: 5 }, metadata },
{ id: 'tc3', op: { d: 'lazy ', p: 29 }, metadata },
]
const result = Utils.addTrackedDeletesToContent(content, trackedChanges)
expect(result).to.equal('the quick brown fox jumps over the lazy dog')
})
})
})