From 14317e84d04f73338cc73903ff04e2c607a45c32 Mon Sep 17 00:00:00 2001 From: Brad Hards Date: Mon, 27 Feb 2017 09:15:04 +1100 Subject: [PATCH] Fix regression introduced in #2743. --- 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 0671f68fe..4e4a6b428 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 19c865585..d7345aa12 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); + }); });