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