From 543be477e615c35f9af76301e6eca8370c582ae7 Mon Sep 17 00:00:00 2001 From: Artur Arseniev Date: Thu, 31 Mar 2016 00:33:48 +0200 Subject: [PATCH] Update states visibility on change of classe collection --- src/class_manager/view/ClassTagsView.js | 11 +++++++++++ .../specs/class_manager/view/ClassTagsView.js | 19 ++++++++++++++++++- 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/class_manager/view/ClassTagsView.js b/src/class_manager/view/ClassTagsView.js index 0bc7ff4dc..ac05fefb4 100644 --- a/src/class_manager/view/ClassTagsView.js +++ b/src/class_manager/view/ClassTagsView.js @@ -29,10 +29,19 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'], this.listenTo( this.collection, 'add', this.addNew); this.listenTo( this.collection, 'reset', this.renderClasses); + this.listenTo( this.collection, 'remove', this.tagRemoved); this.delegateEvents(); }, + /** + * Triggered when a tag is removed from collection + * @param {Object} model Removed model + */ + tagRemoved: function(model){ + this.updateStateVis(); + }, + /** * Create select input with states * @return {string} String of options @@ -135,6 +144,8 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'], if(lenA > lenB) this.target.trigger('targetClassAdded'); + + this.updateStateVis(); } } this.endNewTag(); diff --git a/test/specs/class_manager/view/ClassTagsView.js b/test/specs/class_manager/view/ClassTagsView.js index 161c0277a..30e934bd1 100644 --- a/test/specs/class_manager/view/ClassTagsView.js +++ b/test/specs/class_manager/view/ClassTagsView.js @@ -131,12 +131,29 @@ define([path + 'ClassTagsView', 'ClassManager/model/ClassTags'], this.$statesC.css('display').should.equal('none'); }); - it("States are visible in case more tags inside", function() { + it("States are visible in case of more tags inside", function() { this.coll.add({ label: 'test' }); this.view.updateStateVis(); this.$statesC.css('display').should.equal('block'); }); + it("Update state visibility on new tag", function() { + sinon.stub(this.view, "updateStateVis"); + sinon.stub(this.target, "get").returns(this.targetStub); + this.view.compTarget = this.compTargetStub; + this.view.addNewTag('test'); + this.view.updateStateVis.called.should.equal(true); + }); + + it("Update state visibility on removing of the tag", function() { + sinon.stub(this.target, "get").returns(this.targetStub); + this.view.compTarget = this.compTargetStub; + this.view.addNewTag('test'); + sinon.stub(this.view, "updateStateVis"); + this.coll.remove(this.coll.at(0)); + this.view.updateStateVis.calledOnce.should.equal(true); + }); + it("Output correctly state options", function() { var view = new ClassTagsView({ config : {