Merge pull request #20694 from overleaf/em-tracked-changes-accept-timestamp

Fix history timestamp when accepting tracked changes

GitOrigin-RevId: d68aff0996e7d639f3dd4a68784c0dc0482c55ab
This commit is contained in:
Eric Mc Sween 2024-09-30 08:07:15 -04:00 committed by Copybot
parent 6c2cf20125
commit 4b7f58861a
3 changed files with 25 additions and 9 deletions

View file

@ -230,6 +230,7 @@ const RangesManager = {
op: [op],
meta: {
...change.metadata,
ts: Date.now(),
doc_length: docLength,
pathname,
},

View file

@ -13,6 +13,7 @@ export type Update = {
meta?: {
tc?: boolean
user_id?: string
ts?: number
}
projectHistoryId?: string
}
@ -79,6 +80,7 @@ export type HistoryUpdate = {
doc: string
v?: number
meta?: {
ts?: number
pathname?: string
doc_length?: number
history_doc_length?: number

View file

@ -757,6 +757,7 @@ describe('RangesManager', function () {
describe('getHistoryUpdatesForAcceptedChanges', function () {
beforeEach(function () {
this.clock = sinon.useFakeTimers()
this.RangesManager = SandboxedModule.require(MODULE_PATH, {
requires: {
'@overleaf/ranges-tracker': (this.RangesTracker =
@ -766,6 +767,10 @@ describe('RangesManager', function () {
})
})
afterEach(function () {
this.clock.restore()
})
it('should create history updates for accepted track inserts', function () {
// 'one two three four five' <-- text before changes
const ranges = {
@ -777,6 +782,8 @@ describe('RangesManager', function () {
}
const lines = ['loremone two thipsumree four five']
const now = Date.now()
const result = this.RangesManager.getHistoryUpdatesForAcceptedChanges({
docId: this.doc_id,
acceptedChangeIds: ranges.changes.map(change => change.id),
@ -793,7 +800,7 @@ describe('RangesManager', function () {
user_id: TEST_USER_ID,
doc_length: 33,
pathname: '',
ts: ranges.changes[0].metadata.ts,
ts: now,
},
op: [
{
@ -809,7 +816,7 @@ describe('RangesManager', function () {
user_id: TEST_USER_ID,
doc_length: 33,
pathname: '',
ts: ranges.changes[1].metadata.ts,
ts: now,
},
op: [
{
@ -833,6 +840,8 @@ describe('RangesManager', function () {
}
const lines = ['one four five']
const now = Date.now()
const result = this.RangesManager.getHistoryUpdatesForAcceptedChanges({
docId: this.doc_id,
acceptedChangeIds: ranges.changes.map(change => change.id),
@ -850,7 +859,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 23,
pathname: '',
ts: ranges.changes[0].metadata.ts,
ts: now,
},
op: [
{
@ -866,7 +875,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 20,
pathname: '',
ts: ranges.changes[1].metadata.ts,
ts: now,
},
op: [
{
@ -889,6 +898,8 @@ describe('RangesManager', function () {
}
const lines = ['one four five']
const now = Date.now()
const result = this.RangesManager.getHistoryUpdatesForAcceptedChanges({
docId: this.doc_id,
acceptedChangeIds: [ranges.changes[1].id],
@ -906,7 +917,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 23,
pathname: '',
ts: ranges.changes[1].metadata.ts,
ts: now,
},
op: [
{
@ -932,6 +943,8 @@ describe('RangesManager', function () {
}
const lines = ['one xxx four ']
const now = Date.now()
const result = this.RangesManager.getHistoryUpdatesForAcceptedChanges({
docId: this.doc_id,
acceptedChangeIds: [
@ -954,7 +967,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 27,
pathname: '',
ts: ranges.changes[0].metadata.ts,
ts: now,
},
op: [
{
@ -970,7 +983,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 24,
pathname: '',
ts: ranges.changes[2].metadata.ts,
ts: now,
},
op: [
{
@ -988,7 +1001,7 @@ describe('RangesManager', function () {
doc_length: 15,
history_doc_length: 24,
pathname: '',
ts: ranges.changes[3].metadata.ts,
ts: now,
},
op: [
{
@ -1011,7 +1024,7 @@ function makeRanges(ops) {
changes.push({
id: id.toString(),
op,
metadata: { user_id: TEST_USER_ID, ts: new Date(ts) },
metadata: { user_id: TEST_USER_ID, ts: new Date(ts).toISOString() },
})
id += 1
ts += 1000 // use a unique timestamp for each change