4 const assert
= require('assert');
5 const th
= require('../../../src/template/template-helper');
6 const Config
= require('../../../config');
7 const config
= new Config('test');
9 describe('Template Helper', function () {
12 beforeEach(function () {
16 describe('dateOrNot', function () {
18 beforeEach(function () {
20 otherwise
= 'otherwise';
22 it('covers', function () {
23 const result
= th
.dateOrNot(date
, otherwise
);
24 assert
.strictEqual(result
, date
.toString());
26 it('covers no date', function () {
28 const result
= th
.dateOrNot(date
, otherwise
);
29 assert
.strictEqual(result
, otherwise
);
31 it('covers ms', function () {
32 const result
= th
.dateOrNot(date
.getTime(), otherwise
);
33 assert
.strictEqual(result
, date
.toString());
35 it('covers naught', function () {
36 const result
= th
.dateOrNot(0, otherwise
);
37 assert
.strictEqual(result
, otherwise
);
39 it('covers the infinite', function () {
40 const result
= th
.dateOrNot(-Infinity
, otherwise
);
41 assert
.strictEqual(result
, otherwise
);
45 describe('secondsToPeriod', function () {
46 it('covers seconds', function () {
47 const result
= th
.secondsToPeriod(45);
48 assert
.strictEqual(result
, '45 seconds');
50 it('covers minutes', function () {
51 const result
= th
.secondsToPeriod(105);
52 assert
.strictEqual(result
, '1 minute 45 seconds');
54 it('covers hours', function () {
55 const result
= th
.secondsToPeriod(3705);
56 assert
.strictEqual(result
, '1 hour 1 minute 45 seconds');
58 it('covers days', function () {
59 const result
= th
.secondsToPeriod(90105);
60 assert
.strictEqual(result
, '1 day 1 hour 1 minute 45 seconds');
62 it('covers months', function () {
63 const result
= th
.secondsToPeriod(5274105);
64 assert
.strictEqual(result
, '2 months 1 day 1 hour 1 minute 45 seconds');
66 }); // secondsToPeriod
68 describe('renderTopicRow', function () {
69 let topic
, subscribers
;
70 beforeEach(function () {
74 it('covers', function () {
75 const result
= th
.renderTopicRow(topic
, subscribers
);
78 it('covers empty', function () {
81 const result
= th
.renderTopicRow(topic
, subscribers
);
84 it('covers no link', function () {
85 subscribers
= [{}, {}];
86 const result
= th
.renderTopicRow(topic
, subscribers
, false);
89 it('covers validation', function () {
90 topic
.publisherValidationUrl
= 'https://example.com/';
91 const result
= th
.renderTopicRow(topic
, subscribers
, false);
96 describe('renderTopicRowHeader', function () {
97 it('covers', function () {
98 const result
= th
.renderTopicRowHeader();
101 }); // renderTopicRowHeader
103 describe('renderSubscriptionRow', function () {
105 beforeEach(function () {
108 it('covers', function () {
109 const result
= th
.renderSubscriptionRow(subscription
);
112 it('covers empty', function () {
113 const result
= th
.renderSubscriptionRow();
116 }); // renderSubscriptionRow
118 describe('renderSubscriptionRowHeader', function () {
119 it('covers', function () {
120 const result
= th
.renderSubscriptionRowHeader();
123 }); // renderSubscriptionRowHeader
125 describe('htmlHead', function () {
126 let pagePathLevel
, pageTitle
, headElements
;
127 beforeEach(function () {
131 it('covers', function () {
132 const result
= th
.htmlHead(pagePathLevel
, pageTitle
, headElements
);
135 it('covers elements', function () {
136 headElements
= [ '<div>foop</div>', '<div>poof</div>' ];
137 const result
= th
.htmlHead(pagePathLevel
, pageTitle
, headElements
);
142 describe('htmlTail', function () {
143 it('covers', function () {
144 const result
= th
.htmlTail();
149 describe('renderNavLink', function () {
151 beforeEach(function () {
153 href: 'https://example.com/',
157 it('covers no class', function () {
158 const result
= th
.renderNavLink(nav
);
161 it('covers class', function () {
162 nav
.class = 'foo bar';
163 const result
= th
.renderNavLink(nav
);
168 describe('htmlHeader', function () {
169 let pageTitle
, navLinks
;
170 beforeEach(function () {
174 it('covers no links', function () {
175 const result
= th
.htmlHeader(pageTitle
);
178 it('covers links', function () {
181 href: 'https://exmaple.com/',
185 const result
= th
.htmlHeader(pageTitle
, navLinks
);
190 describe('htmlFooter', function () {
191 it('covers', function () {
192 const result
= th
.htmlFooter(['foo', 'bar']);
195 it('covers default', function () {
196 const result
= th
.htmlFooter();
201 describe('htmlTemplate', function () {
202 let pagePathLevel
, pageTitle
, headElements
, navLinks
, main
;
203 beforeEach(function () {
211 it('covers', function () {
212 const result
= th
.htmlTemplate(ctx
, pagePathLevel
, pageTitle
, headElements
, navLinks
, main
);
215 it('covers defaults', function () {
216 const result
= th
.htmlTemplate(ctx
, pagePathLevel
, pageTitle
);
219 it('covers user', function () {
221 authenticatedProfile: 'user',
223 const result
= th
.htmlTemplate(ctx
, pagePathLevel
, pageTitle
);
226 it('covers user at root path', function () {
228 authenticatedIdentifier: 'user',
231 const result
= th
.htmlTemplate(ctx
, pagePathLevel
, pageTitle
);