X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Fsrc%2Ftemplate%2Ftemplate-helper.js;h=6dc85a351868bfa2093649643d61abdbe507eaea;hb=e23bda592175ae5ed772f366069ccfd2f60e1f70;hp=4ddf36060cb85592d6a3f5816d0ad0356f84ea3e;hpb=9696c012e6b9a6c58904baa397ca0ebf78112316;p=websub-hub diff --git a/test/src/template/template-helper.js b/test/src/template/template-helper.js index 4ddf360..6dc85a3 100644 --- a/test/src/template/template-helper.js +++ b/test/src/template/template-helper.js @@ -1,69 +1,10 @@ /* eslint-env mocha */ 'use strict'; -const assert = require('assert'); +const assert = require('node:assert'); const th = require('../../../src/template/template-helper'); -const Config = require('../../../config'); -const config = new Config('test'); describe('Template Helper', function () { - let ctx; - - beforeEach(function () { - ctx = {}; - }); - - describe('dateOrNot', function () { - let date, otherwise; - beforeEach(function () { - date = new Date(); - otherwise = 'otherwise'; - }); - it('covers', function () { - const result = th.dateOrNot(date, otherwise); - assert.strictEqual(result, date.toString()); - }); - it('covers no date', function () { - date = undefined; - const result = th.dateOrNot(date, otherwise); - assert.strictEqual(result, otherwise); - }); - it('covers ms', function () { - const result = th.dateOrNot(date.getTime(), otherwise); - assert.strictEqual(result, date.toString()); - }); - it('covers naught', function () { - const result = th.dateOrNot(0, otherwise); - assert.strictEqual(result, otherwise); - }); - it('covers the infinite', function () { - const result = th.dateOrNot(-Infinity, otherwise); - assert.strictEqual(result, otherwise); - }); - }); // dateOrNot - - describe('secondsToPeriod', function () { - it('covers seconds', function () { - const result = th.secondsToPeriod(45); - assert.strictEqual(result, '45 seconds'); - }); - it('covers minutes', function () { - const result = th.secondsToPeriod(105); - assert.strictEqual(result, '1 minute 45 seconds'); - }); - it('covers hours', function () { - const result = th.secondsToPeriod(3705); - assert.strictEqual(result, '1 hour 1 minute 45 seconds'); - }); - it('covers days', function () { - const result = th.secondsToPeriod(90105); - assert.strictEqual(result, '1 day 1 hour 1 minute 45 seconds'); - }); - it('covers months', function () { - const result = th.secondsToPeriod(5274105); - assert.strictEqual(result, '2 months 1 day 1 hour 1 minute 45 seconds'); - }); - }); // secondsToPeriod describe('renderTopicRow', function () { let topic, subscribers; @@ -75,6 +16,12 @@ describe('Template Helper', function () { const result = th.renderTopicRow(topic, subscribers); assert(result); }); + it('covers empty', function () { + topic = null; + subscribers = null; + const result = th.renderTopicRow(topic, subscribers); + assert(result); + }); it('covers no link', function () { subscribers = [{}, {}]; const result = th.renderTopicRow(topic, subscribers, false); @@ -103,6 +50,10 @@ describe('Template Helper', function () { const result = th.renderSubscriptionRow(subscription); assert(result); }); + it('covers empty', function () { + const result = th.renderSubscriptionRow(); + assert(result); + }); }); // renderSubscriptionRow describe('renderSubscriptionRowHeader', function () { @@ -112,95 +63,19 @@ describe('Template Helper', function () { }); }); // renderSubscriptionRowHeader - describe('htmlHead', function () { - let pagePathLevel, pageTitle, headElements; - beforeEach(function () { - pagePathLevel = 2; - pageTitle = 'title'; + describe('xmlEscape', function () { + it('ignores numbers', function () { + const result = th.xmlEscape(3); + assert.strictEqual(result, 3); }); - it('covers', function () { - const result = th.htmlHead(pagePathLevel, pageTitle, headElements); - assert(result); + it('ignores objects', function () { + const result = th.xmlEscape({}); + assert.strictEqual(result, undefined); }); - it('covers elements', function () { - headElements = [ '