4ddf36060cb85592d6a3f5816d0ad0356f84ea3e
[websub-hub] / test / src / template / template-helper.js
1 /* eslint-env mocha */
2 'use strict';
3
4 const assert = require('assert');
5 const th = require('../../../src/template/template-helper');
6 const Config = require('../../../config');
7 const config = new Config('test');
8
9 describe('Template Helper', function () {
10 let ctx;
11
12 beforeEach(function () {
13 ctx = {};
14 });
15
16 describe('dateOrNot', function () {
17 let date, otherwise;
18 beforeEach(function () {
19 date = new Date();
20 otherwise = 'otherwise';
21 });
22 it('covers', function () {
23 const result = th.dateOrNot(date, otherwise);
24 assert.strictEqual(result, date.toString());
25 });
26 it('covers no date', function () {
27 date = undefined;
28 const result = th.dateOrNot(date, otherwise);
29 assert.strictEqual(result, otherwise);
30 });
31 it('covers ms', function () {
32 const result = th.dateOrNot(date.getTime(), otherwise);
33 assert.strictEqual(result, date.toString());
34 });
35 it('covers naught', function () {
36 const result = th.dateOrNot(0, otherwise);
37 assert.strictEqual(result, otherwise);
38 });
39 it('covers the infinite', function () {
40 const result = th.dateOrNot(-Infinity, otherwise);
41 assert.strictEqual(result, otherwise);
42 });
43 }); // dateOrNot
44
45 describe('secondsToPeriod', function () {
46 it('covers seconds', function () {
47 const result = th.secondsToPeriod(45);
48 assert.strictEqual(result, '45 seconds');
49 });
50 it('covers minutes', function () {
51 const result = th.secondsToPeriod(105);
52 assert.strictEqual(result, '1 minute 45 seconds');
53 });
54 it('covers hours', function () {
55 const result = th.secondsToPeriod(3705);
56 assert.strictEqual(result, '1 hour 1 minute 45 seconds');
57 });
58 it('covers days', function () {
59 const result = th.secondsToPeriod(90105);
60 assert.strictEqual(result, '1 day 1 hour 1 minute 45 seconds');
61 });
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');
65 });
66 }); // secondsToPeriod
67
68 describe('renderTopicRow', function () {
69 let topic, subscribers;
70 beforeEach(function () {
71 topic = {};
72 subscribers = [];
73 });
74 it('covers', function () {
75 const result = th.renderTopicRow(topic, subscribers);
76 assert(result);
77 });
78 it('covers no link', function () {
79 subscribers = [{}, {}];
80 const result = th.renderTopicRow(topic, subscribers, false);
81 assert(result);
82 });
83 it('covers validation', function () {
84 topic.publisherValidationUrl = 'https://example.com/';
85 const result = th.renderTopicRow(topic, subscribers, false);
86 assert(result);
87 });
88 }); // renderTopicRow
89
90 describe('renderTopicRowHeader', function () {
91 it('covers', function () {
92 const result = th.renderTopicRowHeader();
93 assert(result);
94 });
95 }); // renderTopicRowHeader
96
97 describe('renderSubscriptionRow', function () {
98 let subscription;
99 beforeEach(function () {
100 subscription = {};
101 });
102 it('covers', function () {
103 const result = th.renderSubscriptionRow(subscription);
104 assert(result);
105 });
106 }); // renderSubscriptionRow
107
108 describe('renderSubscriptionRowHeader', function () {
109 it('covers', function () {
110 const result = th.renderSubscriptionRowHeader();
111 assert(result);
112 });
113 }); // renderSubscriptionRowHeader
114
115 describe('htmlHead', function () {
116 let pagePathLevel, pageTitle, headElements;
117 beforeEach(function () {
118 pagePathLevel = 2;
119 pageTitle = 'title';
120 });
121 it('covers', function () {
122 const result = th.htmlHead(pagePathLevel, pageTitle, headElements);
123 assert(result);
124 });
125 it('covers elements', function () {
126 headElements = [ '<div>foop</div>', '<div>poof</div>' ];
127 const result = th.htmlHead(pagePathLevel, pageTitle, headElements);
128 assert(result);
129 });
130 }); // htmlHead
131
132 describe('htmlTail', function () {
133 it('covers', function () {
134 const result = th.htmlTail();
135 assert(result);
136 });
137 }); // htmlTail
138
139 describe('renderNavLink', function () {
140 let nav;
141 beforeEach(function () {
142 nav = {
143 href: 'https://example.com/',
144 text: 'example',
145 };
146 });
147 it('covers no class', function () {
148 const result = th.renderNavLink(nav);
149 assert(result);
150 });
151 it('covers class', function () {
152 nav.class = 'foo bar';
153 const result = th.renderNavLink(nav);
154 assert(result);
155 });
156 }); // renderNavLink
157
158 describe('htmlHeader', function () {
159 let pageTitle, navLinks;
160 beforeEach(function () {
161 pageTitle = 'title';
162 navLinks = [];
163 });
164 it('covers no links', function () {
165 const result = th.htmlHeader(pageTitle);
166 assert(result);
167 });
168 it('covers links', function () {
169 navLinks = [
170 {
171 href: 'https://exmaple.com/',
172 text: 'example',
173 },
174 ];
175 const result = th.htmlHeader(pageTitle, navLinks);
176 assert(result);
177 });
178 }); // htmlHeader
179
180 describe('htmlFooter', function () {
181 it('covers', function () {
182 const result = th.htmlFooter();
183 assert(result);
184 });
185 }); // htmlFooter
186
187 describe('htmlTemplate', function () {
188 let pagePathLevel, pageTitle, headElements, navLinks, main;
189 beforeEach(function () {
190 pagePathLevel = 1;
191 pageTitle = 'title';
192 headElements = [];
193 navLinks = [];
194 main = [];
195 });
196 it('covers', function () {
197 const result = th.htmlTemplate(pagePathLevel, pageTitle, headElements, navLinks, main);
198 assert(result);
199 });
200 it('covers defaults', function () {
201 const result = th.htmlTemplate(pagePathLevel, pageTitle);
202 assert(result);
203 });
204 }); // htmlTemplate
205
206 });