This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Initial unit tests for a few helpers.
References #11 still a long way to go to actually test the framework.
- Loading branch information
1 parent
0ad0824
commit f2c2b8b
Showing
8 changed files
with
491 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
var vows = require("vows"), | ||
assert = require("assert"), | ||
nwt = require('./../libraries/nwt.js'); | ||
|
||
var formHelper = global.nwt.load().helper('Form'); | ||
|
||
// Make a context stub | ||
// TODO: Rip this out into a test utility | ||
global.context = function() { | ||
return {clientScripts : []}; | ||
}; | ||
|
||
vows.describe('FormHelper').addBatch({ | ||
'FormHelper::generate': { | ||
'with no elements': { | ||
topic: formHelper, | ||
|
||
'Proper markup': function (helper) { | ||
assert.equal(helper.generate().render(), '<form method="POST" action="#"></form>'); | ||
} | ||
}, | ||
'with elements': { | ||
topic: formHelper, | ||
|
||
'Proper markup': function (helper) { | ||
var markup = helper.generate( | ||
formHelper.field('Test.field', {type: 'text'}) | ||
); | ||
assert.equal(markup.render(), '<form method="POST" action="#"><div class="row text"><label for="TestField">Test.field</label><input type="text" value="" id="TestField" name="Test[field]"></div></form>'); | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
'FormHelper::field': { | ||
'Test generic form fields': { | ||
topic: formHelper, | ||
|
||
'Default text input': function (helper) { | ||
var markup = helper.field('Key.value'); | ||
assert.equal(markup.render(), '<div class="row text"><label for="KeyValue">Key.value</label><input type="text" value="" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'Text input': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'text'}); | ||
assert.equal(markup.render(), '<div class="row text"><label for="KeyValue">Key.value</label><input type="text" value="" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'Textarea': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'textarea'}); | ||
assert.equal(markup.render(), '<div class="row textarea"><label for="KeyValue">Key.value</label><textarea type="textarea" id="KeyValue" name="Key[value]"></textarea></div>'); | ||
}, | ||
|
||
'Select (no options)': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'select'}); | ||
assert.equal(markup.render(), '<div class="row select"><label for="KeyValue">Key.value</label><select type="select" id="KeyValue" name="Key[value]"></select></div>'); | ||
}, | ||
|
||
'Select (with options)': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'select', options: {0: '1', 1: '2'}}); | ||
assert.equal(markup.render(), '<div class="row select"><label for="KeyValue">Key.value</label><select type="select" id="KeyValue" name="Key[value]"><option value="0" selected>1</option><option value="1">2</option></select></div>'); | ||
}, | ||
|
||
'Multiselect': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'select', multiple: true}); | ||
assert.equal(markup.render(), '<div class="row select"><label for="KeyValue">Key.value</label><select type="select" multiple="true" id="KeyValue" name="Key[value]"></select></div>'); | ||
}, | ||
|
||
'Checkbox (unchecked)': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'checkbox'}); | ||
assert.equal(markup.render(), '<div class="row checkbox"><label for="KeyValue">Key.value</label><input type="checkbox" value="" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'Checkbox (checked)': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'checkbox', checked: true}); | ||
assert.equal(markup.render(), '<div class="row checkbox"><label for="KeyValue">Key.value</label><input type="checkbox" value="" checked="true" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'Radio': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'radio'}); | ||
assert.equal(markup.render(), '<div class="row radio"><label for="KeyValue">Key.value</label><input type="radio" value="" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'checkboxgroup': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'checkboxgroup', options: {0: '1', 1: '2'}}); | ||
assert.equal(markup.render(), '<div class="row checkboxgroup"><label for="KeyValue">Key.value</label><div class="grouped"><div class="row checkbox"><label for="KeyValue[0]">1</label><input type="checkbox" value="0" value="0" label="1" name="Key[value][0]" id="KeyValue[0]"></div><div class="row checkbox"><label for="KeyValue[1]">2</label><input type="checkbox" value="1" value="1" label="2" name="Key[value][1]" id="KeyValue[1]"></div></div></div>'); | ||
}, | ||
|
||
'radiogroup': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'radiogroup', options: {0: '1', 1: '2'}}); | ||
assert.equal(markup.render(), '<div class="row radiogroup"><label for="KeyValue">Key.value</label><div class="grouped"><div class="row radio"><label for="KeyValue[0]">1</label><input type="radio" value="0" value="0" label="1" name="Key[value]" id="KeyValue[0]"></div><div class="row radio"><label for="KeyValue[1]">2</label><input type="radio" value="1" value="1" label="2" name="Key[value]" id="KeyValue[1]"></div></div></div>'); | ||
}, | ||
|
||
'File': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'radio'}); | ||
assert.equal(markup.render(), '<div class="row radio"><label for="KeyValue">Key.value</label><input type="radio" value="" id="KeyValue" name="Key[value]"></div>'); | ||
}, | ||
|
||
'Submit': function (helper) { | ||
var markup = helper.submit('Submit'); | ||
assert.equal(markup + '', '<input type="submit" value="Submit">'); | ||
}, | ||
|
||
'Before | Between | After': function (helper) { | ||
var markup = helper.field('Key.value', {type: 'text'}) | ||
.before('Before') | ||
.between('Between') | ||
.after('After'); | ||
|
||
assert.equal(markup.render(), '<div class="row text">Before<label for="KeyValue">Key.value</label>Between<input type="text" value="" id="KeyValue" name="Key[value]">After</div>'); | ||
}, | ||
} | ||
} | ||
}).export(module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
var vows = require("vows"), | ||
assert = require("assert"), | ||
nwt = require('./../libraries/nwt.js'); | ||
|
||
var htmlHelper = global.nwt.load().helper('Html'); | ||
|
||
vows.describe('HtmlHelper').addBatch({ | ||
'HtmlHelper::link': { | ||
'With some content': { | ||
topic: htmlHelper.link('Content', '#'), | ||
|
||
'Proper markup': function (topic) { | ||
assert.equal(topic + '', '<a href="#">Content</a>'); | ||
} | ||
}, | ||
'with a class': { | ||
topic: htmlHelper.link('Content', '#', {class: 'awesome'}), | ||
|
||
'has a class of "awesome"': function (topic) { | ||
assert.equal(topic + '', '<a href="#" class="awesome">Content</a>'); | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
'HtmlHelper::image': { | ||
'With src': { | ||
topic: htmlHelper.image('/'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<img src="/">'); | ||
} | ||
}, | ||
'with width/height settings': { | ||
topic: htmlHelper.image('/', {height:20, width:20}), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<img src="/" height="20" width="20">'); | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
'HtmlHelper::list': { | ||
'with no items': { | ||
topic: htmlHelper.list(), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<ul></ul>'); | ||
} | ||
}, | ||
'with several items': { | ||
topic: htmlHelper.list('Item 1', 'Item 2'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<ul><li>Item 1</li><li>Item 2</li></ul>'); | ||
} | ||
} | ||
} | ||
}).addBatch({ | ||
'HtmlHelper Standard Elements': { | ||
'h1': { | ||
topic: htmlHelper.h1('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h1>Content</h1>'); | ||
} | ||
}, | ||
'h2': { | ||
topic: htmlHelper.h2('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h2>Content</h2>'); | ||
} | ||
}, | ||
'h3': { | ||
topic: htmlHelper.h3('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h3>Content</h3>'); | ||
} | ||
}, | ||
'h4': { | ||
topic: htmlHelper.h4('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h4>Content</h4>'); | ||
} | ||
}, | ||
'h5': { | ||
topic: htmlHelper.h5('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h5>Content</h5>'); | ||
} | ||
}, | ||
'h6': { | ||
topic: htmlHelper.h6('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<h6>Content</h6>'); | ||
} | ||
}, | ||
'p': { | ||
topic: htmlHelper.p('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<p>Content</p>'); | ||
} | ||
}, | ||
'blockquote': { | ||
topic: htmlHelper.blockquote('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<blockquote>Content</blockquote>'); | ||
} | ||
}, | ||
'code': { | ||
topic: htmlHelper.code('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<code>Content</code>'); | ||
} | ||
}, | ||
'em': { | ||
topic: htmlHelper.em('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<em>Content</em>'); | ||
} | ||
}, | ||
'div': { | ||
topic: htmlHelper.div('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<div>Content</div>'); | ||
} | ||
}, | ||
'pre': { | ||
topic: htmlHelper.pre('Content'), | ||
|
||
'proper markup': function (topic) { | ||
assert.equal(topic + '', '<pre>Content</pre>'); | ||
} | ||
} | ||
} | ||
}).export(module); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
var vows = require("vows"), | ||
assert = require("assert"), | ||
nwt = require('./../libraries/nwt.js'); | ||
|
||
var numberHelper = global.nwt.load().helper('Number'); | ||
|
||
vows.describe('numberHelper').addBatch({ | ||
'NumberHelper::format': { | ||
'with no elements': { | ||
topic: numberHelper, | ||
|
||
'Format whole': function (helper) { | ||
assert.equal(helper.format(100), 100); | ||
}, | ||
|
||
'Format thousands': function (helper) { | ||
assert.equal(helper.format(1000), '1,000'); | ||
}, | ||
|
||
'Format decimals': function (helper) { | ||
assert.equal(helper.format(100.123), '100.12'); | ||
}, | ||
|
||
'Format thousands and decimals': function (helper) { | ||
assert.equal(helper.format(1000.999), '1,000.99'); | ||
}, | ||
|
||
'Custom format': function (helper) { | ||
assert.equal(helper.format(123456.987, 1, "|", ">"), '123>456|9'); | ||
} | ||
} | ||
} | ||
}).export(module); |
Oops, something went wrong.