Skip to content

Commit

Permalink
🆕 adding in more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nick Tilden committed Sep 27, 2016
1 parent 931b593 commit 13a0dc5
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/form/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const addRequired = (html, input, index) => {

if (input.required === 'save' || inp.required === 'save' || input.required === 'publish' || inp.required === 'publish') {
let level = '';
const required = input.required && inp.required;
const required = inp.required || input.required;
if (inp.required !== undefined) {
level += `required--${inp.required}`;
}
Expand Down
62 changes: 62 additions & 0 deletions tests/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,65 @@ test('Add Required Checkbox - Pass', t => {
const result = html.required(param.html, param.input, param.index);
t.false(includes(result, expected));
});

test('Add Required and Repeatable - Pass', t => {
const param = {
html: '"<div class="form--repeatable"><label for="91f79620-ba21-4a4a-a4c7-02f456129b0f">Add Your Text <mark class="mark-publish">required to publish</mark></label><input type="text" id="91f79620-ba21-4a4a-a4c7-02f456129b0f" name="name--text" placeholder="Text goes here" /></div>"',
input: {
description: 'I am the Bar Content Type Config text description',
html: '<div class=\'form--repeatable\'><label for=\'{{text.id}}\'>{{text.label}} <mark class=\'mark-{{text.required}}\'>required to {{text.required}}</mark></label><input type=\'{{text.type}}\' id=\'{{text.id}}\' name=\'{{text.name}}\' placeholder=\'{{text.placeholder}}\' /></div>',
id: 'text-required',
inputs: {
text: {
id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--1',
label: 'Add Your Text',
name: 'name--text',
placeholder: 'Text goes here',
type: 'text',
},
},
name: 'Add Your Text',
required: 'publish',
repeatable: 'true',
type: 'text',
},
index: undefined,
};
const expected = 'aria-required="true" required';
const result = html.required(param.html, param.input, param.index);
t.false(includes(result, expected));
});

test('Add Object Required - Pass', t => {
const param = {
html: '"<fieldset id="community-links" class="form--fieldset required--publish"><legend class="form--legend">Object</legend><p class="form--description">I am the Foo Object text description</p><div class="form--field"><label for="91f79620-ba21-4a4a-a4c7-02f456129b0f--1" class="required--publish">Add Your Text <mark class="mark-publish">required to publish</mark></label><input type="text" id="91f79620-ba21-4a4a-a4c7-02f456129b0f--1" name="name--text" placeholder="Text goes here"></div><div class="form--field"><label for="91f79620-ba21-4a4a-a4c7-02f456129b0f--2">Add Your URL <mark class="mark-publish">required to publish</mark></label><input type="url" id="91f79620-ba21-4a4a-a4c7-02f456129b0f--2" name="name--url" placeholder="http://"></div></fieldset>"',
input: {
name: 'Object',
description: 'I am the Foo Object text description',
html: '<fieldset id=\'community-links\' class=\'form--fieldset required--{{text.required}}\'><legend class=\'form--legend\'>{{input.name}}</legend><p class=\'form--description\'>{{input.description}}</p><div class=\'form--field\'><label for=\'{{text.id}}\' class=\'required--{{text.required}}\'>{{text.label}} <mark class=\'mark-{{text.required}}\'>required to {{text.required}}</mark></label><input type=\'{{text.type}}\' id=\'{{text.id}}\' name=\'{{text.name}}\' placeholder=\'{{text.placeholder1}}\'></div><div class=\'form--field\'><label for=\'{{url.id}}\'>{{url.label}} <mark class=\'mark-{{url.required}}\'>required to {{url.required}}</mark></label><input type=\'{{url.type}}\' id=\'{{url.id}}\' name=\'{{url.name}}\' placeholder=\'{{url.placeholder}}\'></div></fieldset>',
id: 'object-required',
inputs: {
text: {
id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--1',
label: 'Add Your Text',
name: 'name--text',
placeholder: 'Text goes here',
type: 'text',
required: 'publish',
},
url: {
id: '91f79620-ba21-4a4a-a4c7-02f456129b0f--2',
label: 'Add Your URL',
name: 'name--url',
placeholder: 'http://',
type: 'url',
required: 'publish',
},
},
},
index: undefined,
};
const expected = 'aria-required="true" required';
const result = html.required(param.html, param.input, param.index);
t.false(includes(result, expected));
});

0 comments on commit 13a0dc5

Please sign in to comment.