IndieAuth login support, allows viewing of topics related to profile
[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 empty', function () {
79 topic = null;
80 subscribers = null;
81 const result = th.renderTopicRow(topic, subscribers);
82 assert(result);
83 });
84 it('covers no link', function () {
85 subscribers = [{}, {}];
86 const result = th.renderTopicRow(topic, subscribers, false);
87 assert(result);
88 });
89 it('covers validation', function () {
90 topic.publisherValidationUrl = 'https://example.com/';
91 const result = th.renderTopicRow(topic, subscribers, false);
92 assert(result);
93 });
94 }); // renderTopicRow
95
96 describe('renderTopicRowHeader', function () {
97 it('covers', function () {
98 const result = th.renderTopicRowHeader();
99 assert(result);
100 });
101 }); // renderTopicRowHeader
102
103 describe('renderSubscriptionRow', function () {
104 let subscription;
105 beforeEach(function () {
106 subscription = {};
107 });
108 it('covers', function () {
109 const result = th.renderSubscriptionRow(subscription);
110 assert(result);
111 });
112 it('covers empty', function () {
113 const result = th.renderSubscriptionRow();
114 assert(result);
115 });
116 }); // renderSubscriptionRow
117
118 describe('renderSubscriptionRowHeader', function () {
119 it('covers', function () {
120 const result = th.renderSubscriptionRowHeader();
121 assert(result);
122 });
123 }); // renderSubscriptionRowHeader
124
125 describe('htmlHead', function () {
126 let pagePathLevel, pageTitle, headElements;
127 beforeEach(function () {
128 pagePathLevel = 2;
129 pageTitle = 'title';
130 });
131 it('covers', function () {
132 const result = th.htmlHead(pagePathLevel, pageTitle, headElements);
133 assert(result);
134 });
135 it('covers elements', function () {
136 headElements = [ '<div>foop</div>', '<div>poof</div>' ];
137 const result = th.htmlHead(pagePathLevel, pageTitle, headElements);
138 assert(result);
139 });
140 }); // htmlHead
141
142 describe('htmlTail', function () {
143 it('covers', function () {
144 const result = th.htmlTail();
145 assert(result);
146 });
147 }); // htmlTail
148
149 describe('renderNavLink', function () {
150 let nav;
151 beforeEach(function () {
152 nav = {
153 href: 'https://example.com/',
154 text: 'example',
155 };
156 });
157 it('covers no class', function () {
158 const result = th.renderNavLink(nav);
159 assert(result);
160 });
161 it('covers class', function () {
162 nav.class = 'foo bar';
163 const result = th.renderNavLink(nav);
164 assert(result);
165 });
166 }); // renderNavLink
167
168 describe('htmlHeader', function () {
169 let pageTitle, navLinks;
170 beforeEach(function () {
171 pageTitle = 'title';
172 navLinks = [];
173 });
174 it('covers no links', function () {
175 const result = th.htmlHeader(pageTitle);
176 assert(result);
177 });
178 it('covers links', function () {
179 navLinks = [
180 {
181 href: 'https://exmaple.com/',
182 text: 'example',
183 },
184 ];
185 const result = th.htmlHeader(pageTitle, navLinks);
186 assert(result);
187 });
188 }); // htmlHeader
189
190 describe('htmlFooter', function () {
191 it('covers', function () {
192 const result = th.htmlFooter(['foo', 'bar']);
193 assert(result);
194 });
195 it('covers default', function () {
196 const result = th.htmlFooter();
197 assert(result);
198 });
199 }); // htmlFooter
200
201 describe('htmlTemplate', function () {
202 let pagePathLevel, pageTitle, headElements, navLinks, main;
203 beforeEach(function () {
204 ctx = {};
205 pagePathLevel = 1;
206 pageTitle = 'title';
207 headElements = [];
208 navLinks = [];
209 main = [];
210 });
211 it('covers', function () {
212 const result = th.htmlTemplate(ctx, pagePathLevel, pageTitle, headElements, navLinks, main);
213 assert(result);
214 });
215 it('covers defaults', function () {
216 const result = th.htmlTemplate(ctx, pagePathLevel, pageTitle);
217 assert(result);
218 });
219 it('covers user', function () {
220 ctx.session = {
221 authenticatedProfile: 'user',
222 };
223 const result = th.htmlTemplate(ctx, pagePathLevel, pageTitle);
224 assert(result);
225 });
226 it('covers user at root path', function () {
227 ctx.session = {
228 authenticatedIdentifier: 'user',
229 };
230 pagePathLevel = 0;
231 const result = th.htmlTemplate(ctx, pagePathLevel, pageTitle);
232 assert(result);
233 });
234 }); // htmlTemplate
235
236 });