From 3df8107467bdcf88f1c9f55836dc33a12be21f1f Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Tue, 28 Feb 2017 09:03:30 +1100 Subject: [PATCH] Fix regression introduced in #2743. (#2796) --- lib/timeline/component/item/Item.js | 5 ++ test/PointItem.test.js | 100 ++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) diff --git a/lib/timeline/component/item/Item.js b/lib/timeline/component/item/Item.js index f12d44d2..6713a7ac 100644 --- a/lib/timeline/component/item/Item.js +++ b/lib/timeline/component/item/Item.js @@ -461,6 +461,11 @@ Item.prototype._updateEditStatus = function() { updateGroup: this.data.editable, remove: this.data.editable } + } else if (typeof this.data.editable === 'object') { + // TODO: in vis.js 5.0, we should change this to not reset options from the timeline configuration. + // Basically just remove the next line... + this.editable = {}; + util.selectiveExtend(['updateTime', 'updateGroup', 'remove'], this.editable, this.data.editable); } } } diff --git a/test/PointItem.test.js b/test/PointItem.test.js index 19c86558..d7345aa1 100644 --- a/test/PointItem.test.js +++ b/test/PointItem.test.js @@ -165,4 +165,104 @@ describe('Timeline PointItem', function () { assert.equal(pointItem.dom.dot.className, "vis-item vis-dot vis-editable"); assert.equal(pointItem.dom.point.className, "vis-item vis-point vis-editable"); }); + + it('should redraw() and then have the correct property for an editable: {updateTime} override item (with boolean option)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: true}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, undefined); + }); + + it('should redraw() and then have the correct property for an editable: {updateTime} override item (with boolean option false)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true}}, null, {editable: false}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, undefined); + }); + + it('should redraw() and then have the correct property for an editable: {updateGroup} override item (with boolean option)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: true}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, undefined); + assert.equal(pointItem.editable.updateGroup, true); + assert.equal(pointItem.editable.remove, undefined); + }); + + it('should redraw() and then have the correct property for an editable: {updateGroup} override item (with boolean option false)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateGroup: true}}, null, {editable: false}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, undefined); + assert.equal(pointItem.editable.updateGroup, true); + assert.equal(pointItem.editable.remove, undefined); + }); + + it('should redraw() and then have the correct property for an editable: {remove} override item (with boolean option)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: true}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, undefined); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, true); + }); + + it('should redraw() and then have the correct property for an editable: {remove} override item (with boolean option false)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {remove: true}}, null, {editable: false}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, undefined); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, true); + }); + + it('should redraw() and then have the correct property for an editable: {updateTime, remove} override item (with boolean option)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: true}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, true); + }); + + it('should redraw() and then have the correct property for an editable: {updateTime, remove} override item (with boolean option false)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, remove: true}}, null, {editable: false}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, undefined); + assert.equal(pointItem.editable.remove, true); + }); + + it('should redraw() and then have the correct property for an editable: {updateTime, updateGroup, remove} override item (with boolean option)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: true}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, true); + assert.equal(pointItem.editable.remove, true); + }); + + it('should redraw() and then have the correct property for an editable: {updateTime, updateGroup, remove} override item (with boolean option false)', function() { + var pointItem = new PointItem({start: now.toDate(), editable: {updateTime: true, updateGroup: true, remove: true}}, null, {editable: false}); + var parent = TestSupport.buildMockItemSet(); + pointItem.setParent(parent); + pointItem.redraw(); + assert.equal(pointItem.editable.updateTime, true); + assert.equal(pointItem.editable.updateGroup, true); + assert.equal(pointItem.editable.remove, true); + }); });