X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=test%2Flib%2Ftemplate-helper.js;h=968a85f75c2f9e9651252099fefbc5eb96dc026d;hb=12a56b9b35eeb6181ce1d4b4fa2a0536984374d8;hp=ab5533faca6695fa1328b94089b0b11f3a878501;hpb=6f6bea9c4444979f564f7e2242dbd3504895a22e;p=squeep-html-template-helper diff --git a/test/lib/template-helper.js b/test/lib/template-helper.js index ab5533f..968a85f 100644 --- a/test/lib/template-helper.js +++ b/test/lib/template-helper.js @@ -3,14 +3,10 @@ const assert = require('assert'); const th = require('../../lib/template-helper'); -const lint = require('html-minifier-lint').lint; // eslint-disable-line node/no-unpublished-require const stubLogger = require('../stub-logger'); +const LintHtml = require('../lint-html'); -function lintHtml(html) { - const result = lint(html); - stubLogger.debug('validHtml', '', { result, html }); - assert(!result); -} +const lintHtml = new LintHtml(stubLogger); describe('Template Helper', function () { let ctx, options, pagePathLevel; @@ -18,9 +14,21 @@ describe('Template Helper', function () { beforeEach(function () { pagePathLevel = 2; ctx = {}; - options = {}; + options = { + pageTitle: 'Test Page', + }; }); + describe('initContext', function () { + it('covers', function () { + th.initContext(ctx); + assert(ctx.errors); + assert(ctx.notifications); + assert(Array.isArray(ctx.errors)); + assert(Array.isArray(ctx.notifications)); + }); + }); // initContext + describe('dateOrNot', function () { let date, otherwise; beforeEach(function () { @@ -83,6 +91,26 @@ describe('Template Helper', function () { }); }); // dateFormat + describe('timeElement', function () { + it('renders a date', function () { + const when = new Date('2022-09-11T21:17:56.872Z'); + const expected = ''; + const result = th.timeElement(when); + assert.strictEqual(result, expected); + }); + it('covers title', function () { + const when = new Date('2022-09-11T21:17:56.872Z'); + const expected = ''; + const result = th.timeElement(when, { title: 'a date' }); + assert.strictEqual(result, expected); + }); + it('covers other', function () { + const expected = ''; + const result = th.timeElement(1648420085049); + assert.strictEqual(result, expected); + }); + }); // timeElement + describe('secondsToPeriod', function () { it('covers seconds', function () { const result = th.secondsToPeriod(45); @@ -236,43 +264,43 @@ describe('Template Helper', function () { beforeEach(function () { main = []; }); - it('covers', function () { + it('covers', async function () { const result = th.htmlPage(pagePathLevel, ctx, options, main); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); - it('covers defaults', function () { + it('covers defaults', async function () { const result = th.htmlPage(pagePathLevel, ctx, options, main); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); - it('covers user', function () { + it('covers user', async function () { ctx.session = { authenticatedProfile: 'https://user.example.com/', }; const result = th.htmlPage(pagePathLevel, ctx, options, main); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); - it('covers user at root path', function () { + it('covers user at root path', async function () { ctx.session = { authenticatedIdentifier: 'user', }; pagePathLevel = 0; const result = th.htmlPage(pagePathLevel, ctx, options, main); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); - it('covers logout redirect', function () { + it('covers logout redirect', async function () { ctx.session = { authenticatedIdentifier: 'user', }; ctx.url = 'https://app.example.com/this_page'; const result = th.htmlPage(pagePathLevel, ctx, options, main); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); - it('covers existing navLinks', function () { + it('covers existing navLinks', async function () { ctx.session = { authenticatedIdentifier: 'user', }; @@ -281,7 +309,7 @@ describe('Template Helper', function () { href: 'link', }]; const result = th.htmlPage(pagePathLevel, ctx, options); - lintHtml(result); + await lintHtml.lint(result); assert(result); }); }); // htmlPage