Skip to content

Commit

Permalink
Added event tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
brianreavis committed Jul 29, 2013
1 parent 245cebb commit a47a6e5
Show file tree
Hide file tree
Showing 2 changed files with 209 additions and 0 deletions.
208 changes: 208 additions & 0 deletions tests/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
(function() {

describe('Events', function() {

describe('change', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('change', function() {
done();
});
test.selectize.setValue('b');
});
it('should contain current value', function(done) {
test.selectize.on('change', function(value) {
expect(value).to.be.equal('c');
done();
});
test.selectize.setValue('c');
});
});

describe('item_add', function() {
beforeEach(function() {
test = setup_test('<select><option value="a"></option><option value="b"></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('item_add', function() {
done();
});
test.selectize.addItem('b');
});
it('should contain item\'s value', function(done) {
test.selectize.on('item_add', function(value, $item) {
expect(value).to.be.equal('b');
done();
});
test.selectize.addItem('b');
});
});

describe('item_remove', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b"></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('item_remove', function() {
done();
});
test.selectize.removeItem('a');
});
it('should contain item\'s value', function(done) {
test.selectize.on('item_remove', function(value) {
expect(value).to.be.equal('a');
done();
});
test.selectize.removeItem('a');
});
});

describe('clear', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('clear', function() {
done();
});
test.selectize.clear();
});
});

describe('option_add', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('option_add', function() {
done();
});
test.selectize.addOption('e', {value: 'e'});
});
it('should contain option value', function(done) {
test.selectize.on('option_add', function(value, data) {
expect(value).to.be.equal('e');
done();
});
test.selectize.addOption('e', {value: 'e'});
});
it('should contain option data', function(done) {
var option = {value: 'e'};
test.selectize.on('option_add', function(value, data) {
expect(data).to.be.equal(data);
done();
});
test.selectize.addOption(option.value, option);
});
});

describe('option_remove', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('option_remove', function() {
done();
});
test.selectize.removeOption('a');
});
it('should contain option value', function(done) {
test.selectize.on('option_remove', function(value) {
expect(value).to.be.equal('a');
done();
});
test.selectize.removeOption('a');
});
});

describe('option_clear', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('option_clear', function() {
done();
});
test.selectize.clearOptions();
});
});

describe('dropdown_open', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('dropdown_open', function() {
done();
});
test.selectize.open();
});
});

describe('dropdown_close', function() {
beforeEach(function() {
test = setup_test('<select><option value="a" selected></option><option value="b" selected></option><option value="c"></option></select>', {});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('dropdown_close', function() {
done();
});
test.selectize.open();
test.selectize.close();
});
});

describe('type', function() {
beforeEach(function() {
test = setup_test('<select></select>', {create: true});
});
afterEach(function() {
test.teardown();
});
it('should be triggered', function(done) {
test.selectize.on('type', function() {
done();
});
Syn.click(test.selectize.$control).type('a', test.selectize.$control_input);
});
it('should contain current value', function(done) {
test.selectize.on('type', function(value) {
expect(value).to.be.equal('a');
done();
});
Syn.click(test.selectize.$control).type('a', test.selectize.$control_input);
});
});

});

})();
1 change: 1 addition & 0 deletions tests/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<!-- begin tests -->
<script src="setup.js"></script>
<script src="api.js"></script>
<script src="events.js"></script>
<script src="interaction.js"></script>
<script src="xss.js"></script>
<!-- end tests -->
Expand Down

0 comments on commit a47a6e5

Please sign in to comment.