X-Git-Url: http://git.squeep.com/?p=squeep-indie-auther;a=blobdiff_plain;f=test%2Fsrc%2Ftemplate%2Ftemplate-helper.js;fp=test%2Fsrc%2Ftemplate%2Ftemplate-helper.js;h=7903dd88d86672eeb4918f2d3322e01e6bf3f035;hp=0000000000000000000000000000000000000000;hb=b0103b0d496262c438b40bc20304081dbfe41e73;hpb=8ed81748bce7cea7904cac7225b20a60cafdfc16 diff --git a/test/src/template/template-helper.js b/test/src/template/template-helper.js new file mode 100644 index 0000000..7903dd8 --- /dev/null +++ b/test/src/template/template-helper.js @@ -0,0 +1,95 @@ +/* eslint-env mocha */ +'use strict'; + +const assert = require('assert'); +const th = require('../../../src/template/template-helper'); + +describe('Template Helper', function () { + + describe('escapeCSS', function () { + it('allows valid', function () { + const str = 'valid-identifier'; + const result = th.escapeCSS(str); + assert.strictEqual(result, str); + }); + it('escapes invalid', function () { + const str = '(invalid*identifier)'; + const expected = '\\(invalid\\*identifier\\)'; + const result = th.escapeCSS(str); + assert.strictEqual(result, expected); + }); + }); // escapeCSS + + describe('scopeCompare', function () { + let a, b; + describe('empty app', function () { + it('sorts by name, first lower', function () { + a = ['scopeA', { application: '' }]; + b = ['scopeB', { application: '' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, -1); + }); + it('sorts by name, first higher', function () { + a = ['scopeA', { application: '' }]; + b = ['scopeB', { application: '' }]; + const result = th.scopeCompare(b, a); + assert.strictEqual(result, 1); + }); + it('sorts by name, equal', function () { + a = ['scopeA', { application: '' }]; + b = ['scopeA', { application: '' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, 0); + }); + }); + + describe('equal app', function () { + it('sorts by name, first lower', function () { + a = ['scopeA', { application: 'app' }]; + b = ['scopeB', { application: 'app' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, -1); + }); + it('sorts by name, first higher', function () { + a = ['scopeA', { application: 'app' }]; + b = ['scopeB', { application: 'app' }]; + const result = th.scopeCompare(b, a); + assert.strictEqual(result, 1); + }); + it('sorts by name, equal', function () { + a = ['scopeA', { application: 'app' }]; + b = ['scopeA', { application: 'app' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, 0); + }); + }); + + describe('different app', function () { + it('sorts by app, first lower', function () { + a = ['scopeA', { application: 'appA' }]; + b = ['scopeB', { application: 'appB' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, -1); + }); + it('sorts by app, first higher', function () { + a = ['scopeA', { application: 'appA' }]; + b = ['scopeB', { application: 'appB' }]; + const result = th.scopeCompare(b, a); + assert.strictEqual(result, 1); + }); + it('sorts by app, empty first', function () { + a = ['scopeA', { application: '' }]; + b = ['scopeB', { application: 'app' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, -1); + }); + it('sorts by app, empty last', function () { + a = ['scopeA', { application: 'app' }]; + b = ['scopeB', { application: '' }]; + const result = th.scopeCompare(a, b); + assert.strictEqual(result, 1); + }); + }); + }); // scopeCompare + +}); // Template Helper