Skip to content

Commit

Permalink
PATLAB-7 update helper, config and templating tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bb-drummer committed Mar 20, 2018
1 parent d7ce4d8 commit 77e039c
Show file tree
Hide file tree
Showing 7 changed files with 230 additions and 10 deletions.
14 changes: 14 additions & 0 deletions test/fixtures.staticpages/helper-code-default/expected/index.html
@@ -0,0 +1,14 @@
<html>
<body>
<div class="code-example"><pre><code class="html"><span class="hljs-tag">&lt;<span class="hljs-name">section</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"galaxy"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">div</span> <span class="hljs-attr">class</span>=<span class="hljs-string">"planet"</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">h1</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"earth"</span>&gt;</span>
some markup...
<span class="hljs-tag">&lt;/<span class="hljs-name">h1</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">div</span>&gt;</span>
<span class="hljs-tag">&lt;<span class="hljs-name">span</span> <span class="hljs-attr">id</span>=<span class="hljs-string">"sun"</span>&gt;</span>
more markup...
<span class="hljs-tag">&lt;/<span class="hljs-name">span</span>&gt;</span>
<span class="hljs-tag">&lt;/<span class="hljs-name">section</span>&gt;</span>
</code></pre></div> </body>
</html>
@@ -0,0 +1,4 @@
{
"patterns": {},
"categories": []
}
@@ -0,0 +1,5 @@
<html>
<body>
{{> body}}
</body>
</html>
12 changes: 12 additions & 0 deletions test/fixtures.staticpages/helper-code-default/pages/index.html
@@ -0,0 +1,12 @@
{{#code}}
<section class="galaxy">
<div class="planet">
<h1 id="earth">
some markup...
</h1>
</div>
<span id="sun">
more markup...
</span>
</section>
{{/code}}
13 changes: 13 additions & 0 deletions test/test.01.init-config.js
Expand Up @@ -227,5 +227,18 @@ describe('Patternlibrary instanciation and configuration:', function() {

});

describe('Patternlibrary.reset()', function() {
it('should clear all pattern-, category- and user data', function () {
var p = new Patternlibrary.Patternlibrary();
p.data.someKey = 'some value';
p.reset();
expect(p.data).not.to.have.a.key('someKey');
expect(p.data.patterns).to.be.a('object');
expect(p.data.categories).to.be.a('object');
expect(Object.keys(p.data.patterns).length).to.equal(0);
expect(Object.keys(p.data.categories).length).to.equal(0);
});
});


});
17 changes: 17 additions & 0 deletions test/test.10.basic-templating.js
Expand Up @@ -10,6 +10,23 @@ const CLEAN_UP = !true;
describe('Patternlibrary basic templating:', function() {

describe('Patternlibrary.layout', function() {

it('retrieves the default GUI layout if none is set (yet)', function(){
var p = new Patternlibrary.Patternlibrary();
var layout = p.layout;

expect(p.layout).to.be.a('function');
expect(layout).to.be.a('function');

p.handlebars.registerPartial('docs-htmlhead', '<head>');
p.handlebars.registerPartial('body', '<body>');
p.handlebars.registerPartial('docs-htmlclose', '<close>');
var rendered = layout({});
expect(rendered).to.contain('<head>');
expect(rendered).to.contain('<body>');
expect(rendered).to.contain('<close>');

});

it('assings a handlebars default layout "{{> body}}" from an empty template name string', function() {
var p = new Patternlibrary.Patternlibrary();
Expand Down
175 changes: 165 additions & 10 deletions test/test.90.handlebars.js
Expand Up @@ -41,7 +41,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {

describe('Structural', () => {

describe('{{#repeat}}{{/repeat}}', () => {
describe('{{#repeat}}...{{/repeat}}', () => {
it('prints content multiple times', function (done) {

patternlibraryOptions = {
Expand All @@ -67,7 +67,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});
});

describe('{{#ifEqual}}{{/ifEqual}}', () => {
describe('{{#ifEqual}}...{{/ifEqual}}', () => {
it('compares two values', function (done) {

patternlibraryOptions = {
Expand All @@ -93,7 +93,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});
});

describe('{{#ifpage}}{{/ifpage}}', () => {
describe('{{#ifpage}}...{{/ifpage}}', () => {
it('checks the current page', function (done) {

patternlibraryOptions = {
Expand All @@ -120,7 +120,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});
});

describe('{{#unlesspage}}{{/unlesspage}}', () => {
describe('{{#unlesspage}}...{{/unlesspage}}', () => {
it('checks the current page (negation of ifpage)', function (done) {

patternlibraryOptions = {
Expand All @@ -146,13 +146,71 @@ describe('Patternlibrary built-in Handlebars helpers', () => {

});
});

describe('{{#ifCond}}...{{else}}...{{/ifCond}}', () => {

it('{{#ifCond mode="eq" value... comp...}} checks if "value" "equals" "comp"', function () {
compare('{{#ifCond mode="eq" value="a" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="eq" value="a" comp="b"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="eq" value="b" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="eq" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="eq" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="eq" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
});

it('{{#ifCond mode="neq" value... comp...}} checks if "value" "not equals" "comp"', function () {
compare('{{#ifCond mode="neq" value="a" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="neq" value="a" comp="b"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="neq" value="b" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="neq" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="neq" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="neq" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
});

it('{{#ifCond mode="lt" value... comp...}} checks if "value" "is lower to" "comp"', function () {
compare('{{#ifCond mode="lt" value="a" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="lt" value="a" comp="b"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="lt" value="b" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="lt" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="lt" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="lt" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
});

it('{{#ifCond mode="lte" value... comp...}} checks if "value" "is lower or equal to" "comp"', function () {
compare('{{#ifCond mode="lte" value="a" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="lte" value="a" comp="b"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="lte" value="b" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="lte" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="lte" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="lte" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
});

it('{{#ifCond mode="gt" value... comp...}} checks if "value" "is greater to" "comp"', function () {
compare('{{#ifCond mode="gt" value="a" comp="a"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="gt" value="a" comp="b"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="gt" value="b" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="gt" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="gt" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="gt" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
});

it('{{#ifCond mode="gte" value... comp...}} checks if "value" "is greater or equal to" "comp"', function () {
compare('{{#ifCond mode="gte" value="a" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="gte" value="a" comp="b"}}true{{/ifCond}}', '');
compare('{{#ifCond mode="gte" value="b" comp="a"}}true{{/ifCond}}', 'true');
compare('{{#ifCond mode="gte" value="a" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
compare('{{#ifCond mode="gte" value="a" comp="b"}}true{{else}}false{{/ifCond}}', 'false');
compare('{{#ifCond mode="gte" value="b" comp="a"}}true{{else}}false{{/ifCond}}', 'true');
});

});

});

describe('Formatting', () => {

describe('{{#code}}{{/code}}', () => {
it('renders code blocks', function (done) {
describe('{{#code}}...{{/code}}', () => {
it('renders code blocks (given style "css") ', function (done) {

patternlibraryOptions = {
verbose : false,
Expand All @@ -175,9 +233,33 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
}, 250);

});

it('renders code blocks (default style "html")', function (done) {

patternlibraryOptions = {
verbose : false,
dest : FIXTURES + 'helper-code-default/build',
root : FIXTURES + 'helper-code-default/pages/',
layouts : FIXTURES + 'helper-code-default/layouts/',
partials: FIXTURES + 'helper-code-default/partials/',
nogui : true,
testing : true
};
rimraf.sync(FIXTURES + 'helper-code-default/build'); mkdirp(FIXTURES + 'helper-code-default/build');
var p = new Patternlibrary.Patternlibrary(patternlibraryOptions);

p.run();

setTimeout( function () {
equal(FIXTURES + 'helper-code-default/expected/index.html', FIXTURES + 'helper-code-default/build/index.html');
if (CLEAN_UP) rimraf.sync(FIXTURES + 'helper-code-default/build');
done();
}, 250);

});
});

describe('{{#markdown}}{{/markdown}}', () => {
describe('{{#markdown}}...{{/markdown}}', () => {
it('converts Markdown to HTML (block-helper)', function (done) {

patternlibraryOptions = {
Expand Down Expand Up @@ -209,7 +291,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});
});

describe('{{#heading}}{{/heading}}', () => {
describe('{{#heading}}...{{/heading}}', () => {
it('creates a heading of a specific level', () => {
var expected = '<h1 id="title" class="docs-heading">Title<a class="docs-heading-icon" href="#title"></a></h1>';

Expand All @@ -233,21 +315,50 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
it('capitalizes the first letter of a string', () => {
compare('{{toUpper "kittens"}}', 'Kittens');
});
it('retruns empty string when missing parameter', () => {
compare('{{toUpper }}', '');
});
});

describe('{{toLower}}', () => {
it('converts a string to lowercase', () => {
compare('{{toLower "SHOUT"}}', 'shout')
});
it('retruns empty string when missing parameter', () => {
compare('{{toLower }}', '');
});
});

describe('{{raw}}{{/raw}}', () => {
describe('{{raw}}...{{/raw}}', () => {
it('ignores $handlebars', () => {
compare('{{{{raw}}}}{{ignore}}{{{{/raw}}}}', '{{ignore}}');
});
});

describe('{{#filter}}{{/filter}}', () => {
describe('{{formatJson}}', () => {
it('ignores $handlebars', () => {
var data = {
myObj : {
"myKey" : "some value"
}
}
compare('{{formatJson myObj}}', '{&quot;myKey&quot;:&quot;some value&quot;}', data);
});
});

describe('{{texthelper}}', () => {
it('outputs predefined static text pattern', () => {
compare('{{texthelper "lastname"}}', 'Mustermann')
});
it('outputs parameter value when text pattern is unknown', () => {
compare('{{texthelper "some pattern"}}', 'some pattern')
});
it('outputs default medium length lorem-ipsum text when parameter is missing', () => {
compare('{{texthelper }}', 'Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.');
});
});

describe('{{#filter}}...{{/filter}}', () => {
it('filters private SassDoc and JSDoc objects', () => {
var data = {
item: { access: 'private' }
Expand Down Expand Up @@ -353,6 +464,22 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
compare('{{formatJsOptionValue undef}}', '');
});
});

describe('{{formatJsOptionTypes}}', () => {
it('formats JsDoc "type" definitions to read "x or y or z"', () => {
var data = {
types : {
names: ['abc', 'def', 'ghi']
}
};

compare(`{{formatJsOptionTypes types}}`, 'abc or def or ghi', data);
});

it('returns an empty string if no type names are present', () => {
compare('{{formatJsOptionTypes undef}}', '');
});
});

describe('{{formatJsEventName}}', () => {
it('formats a JSDoc event to look like "YourApp"-namespaced events', () => {
Expand All @@ -376,6 +503,7 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
});

describe('Links', () => {

describe('{{editLink}}', () => {
it('generates a GitHub edit link point to a repository, branch, and file', () => {
compare('{{editLink "foundation-sites" "master" "docs/pages/index.html"}}', 'https://github.com/zurb/foundation-sites/edit/master/docs/pages/index.md');
Expand All @@ -392,6 +520,33 @@ describe('Patternlibrary built-in Handlebars helpers', () => {
expect(output, 'includes super loud title that you should replace').to.contain('ISSUE%20NAME%20HERE');
});
});

describe('{{categorylink}}', () => {
it('generates a relative url assembled from a current categories\' root path and category name', () => {
var data = {
categoriesroot : '../pl/categories'
}

compare('{{categorylink "basic"}}', '../pl/categories/basic', data);
});
});

describe('{{patternlink}}', () => {
it('generates a relative url assembled from a current patterns\' root path and pattern\'s type/name identifier', () => {
var data = {
patternsroot : '../pl/'
}

compare('{{patternlink "atom/link"}}', '../pl/atoms/link', data);
compare('{{patternlink "molecule/panel"}}', '../pl/molecules/panel', data);
compare('{{patternlink "organism/teaser"}}', '../pl/organisms/teaser', data);
compare('{{patternlink "component/dropdown"}}', '../pl/components/dropdown', data);
compare('{{patternlink "template/servicepages"}}', '../pl/templates/servicepages', data);
compare('{{patternlink "page/contactpage"}}', '../pl/pages/contactpage', data);

});
});

});

describe('Sass', () => {
Expand Down

0 comments on commit 77e039c

Please sign in to comment.