overleaf/libraries/overleaf-editor-core/test/tracked_change.test.js
Mathias Jakobsen ad0a8be0af Merge pull request #16807 from overleaf/mj-tracked-changes-history
[overleaf-editor-core] Add TrackedChangeList to StringFileData

GitOrigin-RevId: b2abce4860c5be6189beafca575de04e880b08f5
2024-02-06 09:03:54 +00:00

55 lines
1.7 KiB
JavaScript

// @ts-check
const TrackedChange = require('../lib/file_data/tracked_change')
const Range = require('../lib/file_data/range')
const TrackingProps = require('../lib/file_data/tracking_props')
const { expect } = require('chai')
describe('TrackedChange', function () {
it('should survive serialization', function () {
const trackedChange = new TrackedChange(
new Range(1, 2),
new TrackingProps('insert', 'user1', new Date('2024-01-01T00:00:00.000Z'))
)
const newTrackedChange = TrackedChange.fromRaw(trackedChange.toRaw())
expect(newTrackedChange).to.be.instanceOf(TrackedChange)
expect(newTrackedChange).to.deep.equal(trackedChange)
})
it('can be created from a raw object', function () {
const trackedChange = TrackedChange.fromRaw({
range: { pos: 1, length: 2 },
tracking: {
type: 'insert',
userId: 'user1',
ts: '2024-01-01T00:00:00.000Z',
},
})
expect(trackedChange).to.be.instanceOf(TrackedChange)
expect(trackedChange).to.deep.equal(
new TrackedChange(
new Range(1, 2),
new TrackingProps(
'insert',
'user1',
new Date('2024-01-01T00:00:00.000Z')
)
)
)
})
it('can be serialized to a raw object', function () {
const change = new TrackedChange(
new Range(1, 2),
new TrackingProps('insert', 'user1', new Date('2024-01-01T00:00:00.000Z'))
)
expect(change).to.be.instanceOf(TrackedChange)
expect(change.toRaw()).to.deep.equal({
range: { pos: 1, length: 2 },
tracking: {
type: 'insert',
userId: 'user1',
ts: '2024-01-01T00:00:00.000Z',
},
})
})
})