Skip to content

Commit

Permalink
Add tests and example
Browse files Browse the repository at this point in the history
  • Loading branch information
powmedia committed Jan 25, 2012
1 parent 55ed2d2 commit b181e1e
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 2 deletions.
47 changes: 47 additions & 0 deletions test/editors.js
Expand Up @@ -515,6 +515,53 @@ module('Radio');
})();


module('Checkboxes');

(function() {
var editor = editors.Checkboxes,
schema = {
options: ['Sterling', 'Lana', 'Cyril', 'Cheryl', 'Pam']
};

test('Default value', function() {
var field = new editor({
schema: schema
}).render();

var value = field.getValue();
equal(_.isEqual(value, []), true);
});

test('Custom value', function() {
var field = new editor({
value: ['Cyril'],
schema: schema
}).render();

var value = field.getValue();
var expected = ['Cyril'];
equal(_.isEqual(expected, value), true);
});

test('Throws errors if no options', function () {
raises(function () {
var field = new editor({schema: {}});
}, /^Missing required/, 'ERROR: Accepted a new Radio editor with no options.');
});

// Value from model doesn't work here as the value must be an array.

test('Correct type', function() {
var field = new editor({
schema: schema
}).render();
equal($(field.el).get(0).tagName, 'UL');
notEqual($(field.el).find('input[type=checkbox]').length, 0);
});

})();




module('Object');
Expand Down
6 changes: 4 additions & 2 deletions test/index.html
Expand Up @@ -50,7 +50,9 @@ <h2 id="qunit-userAgent"></h2>
date: { type: 'Date' },
datetime: { type: 'DateTime' },
list: { type: 'List' },
radio: { type: 'Radio', options: ['Opt 1', 'Opt 2'] }
radio: { type: 'Radio', options: ['Opt 1', 'Opt 2'] },
checkboxes: { type: 'Checkboxes', options: ['Sterling', 'Lana', 'Cyril', 'Cheryl', 'Pam']
}
}
});

Expand All @@ -63,7 +65,7 @@ <h2 id="qunit-userAgent"></h2>
var form = new Backbone.Form({
model: model,
fieldsets: [
['email', 'tel', 'number', 'checkbox', 'radio'],
['email', 'tel', 'number', 'checkbox', 'radio', 'checkboxes'],
{ legend: 'jQuery UI editors', fields: ['date', 'datetime', 'list'] }
]
}).render();
Expand Down

0 comments on commit b181e1e

Please sign in to comment.