Browse Source

Fix ButtonView tests

pull/1446/head
Artur Arseniev 8 years ago
parent
commit
1c76491220
  1. 7
      src/panels/view/ButtonView.js
  2. 5
      test/specs/panels/view/ButtonView.js

7
src/panels/view/ButtonView.js

@ -41,7 +41,9 @@ module.exports = Backbone.View.extend({
updateClassName() { updateClassName() {
const { model, pfx } = this; const { model, pfx } = this;
const cls = model.get('className'); const cls = model.get('className');
this.$el.attr('class', `${pfx}btn ${cls ? cls : ''}`.trim()); const attrCls = model.get('attributes').class;
const classStr = `${attrCls ? attrCls : ''} ${pfx}btn ${cls ? cls : ''}`;
this.$el.attr('class', classStr.trim());
}, },
/** /**
@ -51,6 +53,7 @@ module.exports = Backbone.View.extend({
* */ * */
updateAttributes() { updateAttributes() {
this.$el.attr(this.model.get('attributes')); this.$el.attr(this.model.get('attributes'));
this.updateClassName();
}, },
/** /**
@ -154,11 +157,9 @@ module.exports = Backbone.View.extend({
const { $el } = this; const { $el } = this;
$el.empty(); $el.empty();
this.updateAttributes(); this.updateAttributes();
$el.attr('class', this.className);
label && $el.append(label); label && $el.append(label);
this.checkActive(); this.checkActive();
this.updateDisable(); this.updateDisable();
this.updateClassName();
return this; return this;
} }

5
test/specs/panels/view/ButtonView.js

@ -3,7 +3,7 @@ const Button = require('panels/model/Button');
module.exports = { module.exports = {
run() { run() {
describe.only('ButtonView', () => { describe('ButtonView', () => {
var fixtures; var fixtures;
var model; var model;
var view; var view;
@ -58,13 +58,12 @@ module.exports = {
test('Disable the button', () => { test('Disable the button', () => {
model.set('disable', true, { silent: true }); model.set('disable', true, { silent: true });
view.updateDisable(); view.updateDisable();
expect(view.el.getAttribute('class')).toEqual(btnClass + ' active'); expect(view.el.getAttribute('class')).toEqual(btnClass + ' disabled');
}); });
test('Enable the disabled button', () => { test('Enable the disabled button', () => {
model.set('disable', true, { silent: true }); model.set('disable', true, { silent: true });
view.updateDisable(); view.updateDisable();
expect(view.el.getAttribute('class')).toEqual(btnClass + ' active');
model.set('disable', false, { silent: true }); model.set('disable', false, { silent: true });
view.updateDisable(); view.updateDisable();
expect(view.el.getAttribute('class')).toEqual(btnClass); expect(view.el.getAttribute('class')).toEqual(btnClass);

Loading…
Cancel
Save