ca61f34544f2053ee2a60bd20f64e177466e489f
3 const assert
= require('assert');
4 const th
= require('../../../src/template/template-helper');
6 describe('Template Helper', function () {
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
);
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
);
22 describe('scopeCompare', function () {
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);
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);
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);
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);
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);
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);
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);
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);
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);
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);
94 describe('navLinks', function () {
95 let pagePathLevel
, ctx
, options
;
96 beforeEach(function () {
103 it('populates navLinks', function () {
104 th
.navLinks(pagePathLevel
, ctx
, options
);
105 assert
.strictEqual(options
.navLinks
.length
, 2);
107 it('creates and populates navLinks', function () {
108 delete options
.navLinks
;
109 th
.navLinks(pagePathLevel
, ctx
, options
);
110 assert
.strictEqual(options
.navLinks
.length
, 2);
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);
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);
124 }); // Template Helper