4 const assert
= require('assert');
5 const th
= require('../../../src/template/template-helper');
7 describe('Template Helper', function () {
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
);
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
);
23 describe('scopeCompare', function () {
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
95 describe('navLinks', function () {
96 let pagePathLevel
, ctx
, options
;
97 beforeEach(function () {
104 it('populates navLinks', function () {
105 th
.navLinks(pagePathLevel
, ctx
, options
);
106 assert
.strictEqual(options
.navLinks
.length
, 2);
108 it('creates and populates navLinks', function () {
109 delete options
.navLinks
;
110 th
.navLinks(pagePathLevel
, ctx
, options
);
111 assert
.strictEqual(options
.navLinks
.length
, 2);
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);
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);
125 }); // Template Helper