Skip to content

Commit

Permalink
added tests for button
Browse files Browse the repository at this point in the history
  • Loading branch information
mob8607 committed Oct 13, 2013
1 parent 364e76b commit 1de74a2
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 4 deletions.
4 changes: 3 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"expect": false,
"beforeEach": false,
"afterEach": false,
"sinon": false
"sinon": false,
"runs": false,
"waitsFor": false
},
"bitwise": true,
"camelcase": true,
Expand Down
3 changes: 1 addition & 2 deletions husky_components/button/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ define([], function() {
type.bindDomEvents.call(this);
},
bindDomEvents: function() {
// FIXME if not events would be triggered multiple times
this.$el.off('click');
this.$el.on('click', this.clickEvent.bind(this));
},
Expand Down Expand Up @@ -100,7 +99,7 @@ define([], function() {
},

initialize: function() {
this.sandbox.logger.log('initialize', this);
this.sandbox.logger.log('initialize');
this.sandbox.logger.log(arguments);

// extend default options
Expand Down
2 changes: 1 addition & 1 deletion husky_components/navigation/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ define(['jquery'], function($) {
initialize: function() {

sandbox = this.sandbox;
sandbox.logger.log('initialize', this);
sandbox.logger.log('initialize');
sandbox.logger.log(arguments);

this.$navigation = $('<div/>', {
Expand Down
74 changes: 74 additions & 0 deletions tests/components/ButtonSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
define(['husky'], function(husky) {

'use strict';

var app, $button;

ddescribe('Button', function() {
$('body').append('<div id="button">');
app = husky({ debug: { enable: true }});

beforeEach(function() {
runs(function() {
app.start(document.body).then(function() {
app.sandbox.start([
{ name: 'button@husky', options: { el: '#button', text: 'myText', instanceName: 'instance' } }
]);
});
});

waitsFor(function() {
return $('.icon-btn').size() === 1;
}, 'load icon', 500);

runs(function() {
$button = $('.icon-btn');
});
});

afterEach(function() {
});

it('should be inserted into the dom', function() {
expect($button.size()).toBe(1);
});

it('has icon ok-circle', function() {
var flag = false;
runs(function() {
app.sandbox.emit('husky.button.instance.set-content', 'test', 'circle-ok');

_.delay(function() {
flag = true;
}, 500);
});

waitsFor(function() {
return flag;
}, 'load component', 500);

runs(function() {
expect($('.icon-btn').find('.loading-content').find('.icon-circle-ok').size()).toBe(1);
});
});

it('can be disabled', function() {
var flag = false;
runs(function() {
app.sandbox.emit('husky.button.instance.state', 'disable');

_.delay(function() {
flag = true;
}, 500);
});

waitsFor(function() {
return flag;
}, 'load component', 500);

runs(function() {
expect($('.icon-btn.disable').size()).toBe(1);
});
});
});
});

0 comments on commit 1de74a2

Please sign in to comment.