Merge pull request #20421 from overleaf/em-history-limit-tracked-deletes
Do not count tracked deletes towards size limit in history GitOrigin-RevId: 0185e6df80d8f3433aa489a1c90f5a6499af5ef4
This commit is contained in:
@@ -7,16 +7,15 @@ const TextOperation = ot.TextOperation
|
||||
|
||||
describe('HollowStringFileData', function () {
|
||||
it('validates string length when edited', function () {
|
||||
const maxLength = TextOperation.MAX_STRING_LENGTH
|
||||
const fileData = new HollowStringFileData(maxLength)
|
||||
expect(fileData.getStringLength()).to.equal(maxLength)
|
||||
const length = 200
|
||||
const fileData = new HollowStringFileData(length)
|
||||
|
||||
expect(() => {
|
||||
fileData.edit(new TextOperation().retain(maxLength).insert('x'))
|
||||
}).to.throw(TextOperation.TooLongError)
|
||||
expect(fileData.getStringLength()).to.equal(maxLength)
|
||||
fileData.edit(new TextOperation().retain(length + 10).insert('x'))
|
||||
}).to.throw(TextOperation.ApplyError)
|
||||
expect(fileData.getStringLength()).to.equal(length)
|
||||
|
||||
fileData.edit(new TextOperation().retain(maxLength - 1).remove(1))
|
||||
expect(fileData.getStringLength()).to.equal(maxLength - 1)
|
||||
fileData.edit(new TextOperation().retain(length).insert('x'))
|
||||
expect(fileData.getStringLength()).to.equal(length + 1)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -178,7 +178,7 @@ describe('LazyStringFileData', function () {
|
||||
expect(fileData.getStringLength()).to.equal(0)
|
||||
expect(fileData.getOperations()).to.have.length(0)
|
||||
|
||||
const longString = _.repeat('a', TextOperation.MAX_STRING_LENGTH)
|
||||
const longString = _.repeat('a', 1000)
|
||||
fileData.edit(new TextOperation().insert(longString))
|
||||
expect(fileData.getHash()).not.to.exist
|
||||
expect(fileData.getByteLength()).to.equal(longString.length) // approximate
|
||||
@@ -186,8 +186,10 @@ describe('LazyStringFileData', function () {
|
||||
expect(fileData.getOperations()).to.have.length(1)
|
||||
|
||||
expect(() => {
|
||||
fileData.edit(new TextOperation().retain(longString.length).insert('x'))
|
||||
}).to.throw(TextOperation.TooLongError)
|
||||
fileData.edit(
|
||||
new TextOperation().retain(longString.length - 123).insert('x')
|
||||
)
|
||||
}).to.throw(TextOperation.ApplyError)
|
||||
expect(fileData.getHash()).not.to.exist
|
||||
expect(fileData.getByteLength()).to.equal(longString.length) // approximate
|
||||
expect(fileData.getStringLength()).to.equal(longString.length)
|
||||
|
||||
@@ -5,7 +5,10 @@ const { expect } = require('chai')
|
||||
const _ = require('lodash')
|
||||
|
||||
const ot = require('..')
|
||||
const Range = require('../lib/range')
|
||||
const StringFileData = require('../lib/file_data/string_file_data')
|
||||
const TrackedChange = require('../lib/file_data/tracked_change')
|
||||
const TrackingProps = require('../lib/file_data/tracking_props')
|
||||
const TextOperation = ot.TextOperation
|
||||
|
||||
describe('StringFileData', function () {
|
||||
@@ -20,7 +23,10 @@ describe('StringFileData', function () {
|
||||
})
|
||||
|
||||
it('validates string length when edited', function () {
|
||||
const longString = _.repeat('a', TextOperation.MAX_STRING_LENGTH)
|
||||
const longString = _.repeat(
|
||||
'a',
|
||||
TextOperation.MAX_STRING_LENGTH_EXCLUDING_TRACKED_DELETES
|
||||
)
|
||||
const fileData = new StringFileData(longString)
|
||||
expect(fileData.getByteLength()).to.equal(longString.length)
|
||||
expect(fileData.getStringLength()).to.equal(longString.length)
|
||||
@@ -36,6 +42,38 @@ describe('StringFileData', function () {
|
||||
expect(fileData.getStringLength()).to.equal(longString.length - 1)
|
||||
})
|
||||
|
||||
it('ignores tracked deletes when checking the max string length', function () {
|
||||
const longString = _.repeat(
|
||||
'a',
|
||||
TextOperation.MAX_STRING_LENGTH_EXCLUDING_TRACKED_DELETES
|
||||
)
|
||||
const fileData = new StringFileData(longString)
|
||||
fileData.trackedChanges.add(
|
||||
new TrackedChange(
|
||||
new Range(123, 100),
|
||||
new TrackingProps('delete', 'some-user', new Date())
|
||||
)
|
||||
)
|
||||
fileData.trackedChanges.add(
|
||||
new TrackedChange(
|
||||
new Range(456, 50),
|
||||
new TrackingProps('insert', 'some-user', new Date())
|
||||
)
|
||||
)
|
||||
|
||||
// Add text the same length as the tracked delete
|
||||
fileData.edit(
|
||||
new TextOperation().retain(longString.length).insert('x'.repeat(100))
|
||||
)
|
||||
|
||||
// Add more text
|
||||
expect(() => {
|
||||
fileData.edit(
|
||||
new TextOperation().retain(longString.length + 100).insert('x')
|
||||
)
|
||||
}).to.throw(TextOperation.TooLongError)
|
||||
})
|
||||
|
||||
it('getComments() should return an empty array', function () {
|
||||
const fileData = new StringFileData('test')
|
||||
expect(fileData.getComments().toRaw()).to.eql([])
|
||||
|
||||
Reference in New Issue
Block a user