Skip to content

Commit

Permalink
Merge e2ee305 into f54e7be
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnath committed Sep 26, 2016
2 parents f54e7be + e2ee305 commit 6098f3e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 26 deletions.
3 changes: 0 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ module.exports = {
value: 'yellow',
},
],
settings: {
empty: false,
},
},
},
html: '<ul>{% for option in checkbox.options %}<li><input type="{{checkbox.type}}" name="{{checkbox.name}}" id="{{checkbox.id}}--{{loop.index}}" value="{{option.value}}" {% if checkbox.value %}{% if option.value in checkbox.value %}checked{% endif %}{% endif %}><label for="{{checkbox.id}}--{{loop.index}}">{{option.label}}</label></li>{% endfor %}</ul>',
Expand Down
6 changes: 1 addition & 5 deletions lib/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
* @module checkboxValidation
*/

module.exports = function checkboxValidation(input, settings) {
if (input.target.value === '' && !settings.target.empty) {
return `${input.target.name} cannot be left blank!`;
}

module.exports = function checkboxValidation() {
return true;
};
30 changes: 12 additions & 18 deletions tests/validation.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,31 @@
import test from 'ava';
import validation from '../lib/validation';

const input = {
const empty = {
target: {
name: 'checkbox',
value: 'foo bar baz',
},
all: {
checkbox: 'foo bar baz',
value: '',
},
};

const settings = {
const input = {
target: {
empty: false,
name: 'checkbox',
value: 'foo bar baz',
},
all: {
checkbox: {
empty: false,
},
checkbox: 'foo bar baz',
},
};

const settings = {};


// Valid input
test('valid input', t => {
t.true(validation(input, settings), 'Valid input returns true');
test('empty input', t => {
t.true(validation(empty, settings), 'empty input returns true');
});

// Invalid input
test('validate correct input', t => {
const ip = input;
ip.target.value = '';

t.is(validation(ip, settings), 'checkbox cannot be left blank!', 'Return string if not valid');
test('valid input', t => {
t.true(validation(input, settings), 'Any input returns true');
});

0 comments on commit 6098f3e

Please sign in to comment.