a40293eb1354c21d4eb33f3a012c6b3714cb42c7
[squeep-indie-auther] / test / src / template / template-helper.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const th = require('../../../src/template/template-helper');
6
7 describe('Template Helper', function () {
8
9 describe('escapeCSS', function () {
10 it('allows valid', function () {
11 const str = 'valid-identifier';
12 const result = th.escapeCSS(str);
13 assert.strictEqual(result, str);
14 });
15 it('escapes invalid', function () {
16 const str = '(invalid*identifier)';
17 const expected = '\\(invalid\\*identifier\\)';
18 const result = th.escapeCSS(str);
19 assert.strictEqual(result, expected);
20 });
21 }); // escapeCSS
22
23 describe('scopeCompare', function () {
24 let a, b;
25 describe('empty app', function () {
26 it('sorts by name, first lower', function () {
27 a = ['scopeA', { application: '' }];
28 b = ['scopeB', { application: '' }];
29 const result = th.scopeCompare(a, b);
30 assert.strictEqual(result, -1);
31 });
32 it('sorts by name, first higher', function () {
33 a = ['scopeA', { application: '' }];
34 b = ['scopeB', { application: '' }];
35 const result = th.scopeCompare(b, a);
36 assert.strictEqual(result, 1);
37 });
38 it('sorts by name, equal', function () {
39 a = ['scopeA', { application: '' }];
40 b = ['scopeA', { application: '' }];
41 const result = th.scopeCompare(a, b);
42 assert.strictEqual(result, 0);
43 });
44 });
45
46 describe('equal app', function () {
47 it('sorts by name, first lower', function () {
48 a = ['scopeA', { application: 'app' }];
49 b = ['scopeB', { application: 'app' }];
50 const result = th.scopeCompare(a, b);
51 assert.strictEqual(result, -1);
52 });
53 it('sorts by name, first higher', function () {
54 a = ['scopeA', { application: 'app' }];
55 b = ['scopeB', { application: 'app' }];
56 const result = th.scopeCompare(b, a);
57 assert.strictEqual(result, 1);
58 });
59 it('sorts by name, equal', function () {
60 a = ['scopeA', { application: 'app' }];
61 b = ['scopeA', { application: 'app' }];
62 const result = th.scopeCompare(a, b);
63 assert.strictEqual(result, 0);
64 });
65 });
66
67 describe('different app', function () {
68 it('sorts by app, first lower', function () {
69 a = ['scopeA', { application: 'appA' }];
70 b = ['scopeB', { application: 'appB' }];
71 const result = th.scopeCompare(a, b);
72 assert.strictEqual(result, -1);
73 });
74 it('sorts by app, first higher', function () {
75 a = ['scopeA', { application: 'appA' }];
76 b = ['scopeB', { application: 'appB' }];
77 const result = th.scopeCompare(b, a);
78 assert.strictEqual(result, 1);
79 });
80 it('sorts by app, empty first', function () {
81 a = ['scopeA', { application: '' }];
82 b = ['scopeB', { application: 'app' }];
83 const result = th.scopeCompare(a, b);
84 assert.strictEqual(result, -1);
85 });
86 it('sorts by app, empty last', function () {
87 a = ['scopeA', { application: 'app' }];
88 b = ['scopeB', { application: '' }];
89 const result = th.scopeCompare(a, b);
90 assert.strictEqual(result, 1);
91 });
92 });
93 }); // scopeCompare
94
95 describe('navLinks', function () {
96 let pagePathLevel, ctx, options;
97 beforeEach(function () {
98 pagePathLevel = 1;
99 ctx = {};
100 options = {
101 navLinks: [],
102 };
103 });
104 it('populates navLinks', function () {
105 th.navLinks(pagePathLevel, ctx, options);
106 assert.strictEqual(options.navLinks.length, 2);
107 });
108 it('creates and populates navLinks', function () {
109 delete options.navLinks;
110 th.navLinks(pagePathLevel, ctx, options);
111 assert.strictEqual(options.navLinks.length, 2);
112 });
113 it('populates navLink when on admin', function () {
114 options.pageIdentifier = 'admin';
115 th.navLinks(pagePathLevel, ctx, options);
116 assert.strictEqual(options.navLinks.length, 1);
117 });
118 it('populates navLink when on ticketProffer', function () {
119 options.pageIdentifier = 'ticketProffer';
120 th.navLinks(pagePathLevel, ctx, options);
121 assert.strictEqual(options.navLinks.length, 1);
122 });
123 }); // navLinks
124
125 }); // Template Helper