Browse Source

Update states visibility on change of classe collection

pull/16/head
Artur Arseniev 10 years ago
parent
commit
543be477e6
  1. 11
      src/class_manager/view/ClassTagsView.js
  2. 19
      test/specs/class_manager/view/ClassTagsView.js

11
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();

19
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 : {

Loading…
Cancel
Save