|
|
@@ -28,6 +28,101 @@ describe('RangesTracker', function () {
|
|
|
})
|
|
|
})
|
|
|
|
|
|
+ describe('with duplicate tracked insert ids', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.comments = []
|
|
|
+ this.changes = [
|
|
|
+ { id: 'id1', op: { p: 10, i: 'one' } },
|
|
|
+ { id: 'id1', op: { p: 20, i: 'two' } },
|
|
|
+ { id: 'id1', op: { p: 30, d: 'three' } },
|
|
|
+ ]
|
|
|
+ this.rangesTracker = new RangesTracker(this.changes, this.comments)
|
|
|
+ })
|
|
|
+
|
|
|
+ it("deleting one tracked insert doesn't delete the others", function () {
|
|
|
+ this.rangesTracker.applyOp({ p: 20, d: 'two', fixedRemoveChange: true })
|
|
|
+ expect(this.rangesTracker.changes).to.deep.equal([
|
|
|
+ this.changes[0],
|
|
|
+ this.changes[2],
|
|
|
+ ])
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ describe('with duplicate tracked delete ids', function () {
|
|
|
+ beforeEach(function () {
|
|
|
+ this.comments = []
|
|
|
+ this.changes = [
|
|
|
+ { id: 'id1', op: { p: 10, d: 'one' } },
|
|
|
+ { id: 'id1', op: { p: 20, d: 'two' } },
|
|
|
+ { id: 'id1', op: { p: 30, d: 'three' } },
|
|
|
+ ]
|
|
|
+ this.rangesTracker = new RangesTracker(this.changes, this.comments)
|
|
|
+ })
|
|
|
+
|
|
|
+ it('deleting over tracked deletes in tracked changes mode removes the tracked deletes covered', function () {
|
|
|
+ this.rangesTracker.track_changes = true
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 15,
|
|
|
+ d: '567890123456789012345',
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ expect(this.rangesTracker.changes.map(c => c.op)).to.deep.equal([
|
|
|
+ { p: 10, d: 'one' },
|
|
|
+ { p: 15, d: '56789two0123456789three012345' },
|
|
|
+ ])
|
|
|
+ })
|
|
|
+
|
|
|
+ it('a tracked delete between two tracked deletes joins them into a single tracked delete', function () {
|
|
|
+ this.rangesTracker.track_changes = true
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 20,
|
|
|
+ d: '0123456789',
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ expect(this.rangesTracker.changes.map(c => c.op)).to.deep.equal([
|
|
|
+ { p: 10, d: 'one' },
|
|
|
+ { p: 20, d: 'two0123456789three' },
|
|
|
+ ])
|
|
|
+ })
|
|
|
+
|
|
|
+ it("rejecting one tracked delete doesn't reject the others", function () {
|
|
|
+ this.rangesTracker.track_changes = true
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 20,
|
|
|
+ i: 'two',
|
|
|
+ u: true,
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ expect(this.rangesTracker.changes.map(c => c.op)).to.deep.equal([
|
|
|
+ { p: 10, d: 'one' },
|
|
|
+ { p: 33, d: 'three' },
|
|
|
+ ])
|
|
|
+ })
|
|
|
+
|
|
|
+ it("rejecting all tracked deletes doesn't introduce tracked inserts", function () {
|
|
|
+ this.rangesTracker.track_changes = true
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 10,
|
|
|
+ i: 'one',
|
|
|
+ u: true,
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 23,
|
|
|
+ i: 'two',
|
|
|
+ u: true,
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ this.rangesTracker.applyOp({
|
|
|
+ p: 36,
|
|
|
+ i: 'three',
|
|
|
+ u: true,
|
|
|
+ fixedRemoveChange: true,
|
|
|
+ })
|
|
|
+ expect(this.rangesTracker.changes.map(c => c.op)).to.deep.equal([])
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
describe('with multiple tracked deletes at the same position', function () {
|
|
|
beforeEach(function () {
|
|
|
this.comments = []
|