overleaf/libraries/overleaf-editor-core/test/tracked_change.test.js
Domagoj Kriskovic 2440f89be5 [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation (#16871)
* [overleaf-editor-core] AddCommentOperation and DeleteCommentOperation

* added add comment op test

* delete comment op test

* import core to escape circle deps

* desctructure in tests

* require directly in builder

* invert of add comment is always delete comment

* no merging on compose

* NoOp if comment is not found

* use comment.clone()

* update test

* change CommentRawData type

* jsdoc assert type

* fix formating

* EditNoOperation

* return other in compose

* use ReturnType

* Revert "use ReturnType"

This reverts commit 2c7e04f1541310e9fc08963170a783a437ed1992.

* transorm add comment operation

* transform delete comment operation

* moved comment.js

* format fix

* fix transform addComment and textoperation

* fix merge

* test more complex test operations

* change to else if

* move range.js

* fix types

* fix AddComment and TextOperation transform

* fixed AddComment-TextOperation trasform, added test

* deletecommentoperation should win

* should not delete comment

* remove unused function, fix type

* fix format

* add resolved for existing comment

* transform EditNoOperation

* fix test description

* change the order of EditNoOperation

* fix DeleteCommentOperation-DeleteCommentOperation transform

* fix types after merging main

* refactor operation types

GitOrigin-RevId: 6f127763a6dc50d4fe3524d9b25dc7526b6b0028
2024-02-19 09:04:15 +00:00

55 lines
1.6 KiB
JavaScript

// @ts-check
const TrackedChange = require('../lib/file_data/tracked_change')
const Range = require('../lib/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',
},
})
})
})