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 no link', function () {
79 subscribers
= [{}, {}];
80 const result
= th
.renderTopicRow(topic
, subscribers
, false);
83 it('covers validation', function () {
84 topic
.publisherValidationUrl
= 'https://example.com/';
85 const result
= th
.renderTopicRow(topic
, subscribers
, false);
90 describe('renderTopicRowHeader', function () {
91 it('covers', function () {
92 const result
= th
.renderTopicRowHeader();
95 }); // renderTopicRowHeader
97 describe('renderSubscriptionRow', function () {
99 beforeEach(function () {
102 it('covers', function () {
103 const result
= th
.renderSubscriptionRow(subscription
);
106 }); // renderSubscriptionRow
108 describe('renderSubscriptionRowHeader', function () {
109 it('covers', function () {
110 const result
= th
.renderSubscriptionRowHeader();
113 }); // renderSubscriptionRowHeader
115 describe('htmlHead', function () {
116 let pagePathLevel
, pageTitle
, headElements
;
117 beforeEach(function () {
121 it('covers', function () {
122 const result
= th
.htmlHead(pagePathLevel
, pageTitle
, headElements
);
125 it('covers elements', function () {
126 headElements
= [ '<div>foop</div>', '<div>poof</div>' ];
127 const result
= th
.htmlHead(pagePathLevel
, pageTitle
, headElements
);
132 describe('htmlTail', function () {
133 it('covers', function () {
134 const result
= th
.htmlTail();
139 describe('renderNavLink', function () {
141 beforeEach(function () {
143 href: 'https://example.com/',
147 it('covers no class', function () {
148 const result
= th
.renderNavLink(nav
);
151 it('covers class', function () {
152 nav
.class = 'foo bar';
153 const result
= th
.renderNavLink(nav
);
158 describe('htmlHeader', function () {
159 let pageTitle
, navLinks
;
160 beforeEach(function () {
164 it('covers no links', function () {
165 const result
= th
.htmlHeader(pageTitle
);
168 it('covers links', function () {
171 href: 'https://exmaple.com/',
175 const result
= th
.htmlHeader(pageTitle
, navLinks
);
180 describe('htmlFooter', function () {
181 it('covers', function () {
182 const result
= th
.htmlFooter();
187 describe('htmlTemplate', function () {
188 let pagePathLevel
, pageTitle
, headElements
, navLinks
, main
;
189 beforeEach(function () {
196 it('covers', function () {
197 const result
= th
.htmlTemplate(pagePathLevel
, pageTitle
, headElements
, navLinks
, main
);
200 it('covers defaults', function () {
201 const result
= th
.htmlTemplate(pagePathLevel
, pageTitle
);