add indention helper
[squeep-html-template-helper] / test / lib / template-helper.js
index 29878cd4e29e638ba1c9bdde5d500a1fad87dd11..ab5533faca6695fa1328b94089b0b11f3a878501 100644 (file)
@@ -50,6 +50,39 @@ describe('Template Helper', function () {
     });
   }); // dateOrNot
 
+  describe('dateFormat', function () {
+    it('renders otherwise', function () {
+      const expected = 'otherwise';
+      const result = th.dateFormat(undefined, undefined, undefined, expected);
+      assert.strictEqual(result, expected);
+    });
+    it('handles invalid date', function () {
+      const expected = 'otherwise';
+      const result = th.dateFormat(new Date('bad date'), undefined, undefined, expected);
+      assert.strictEqual(result, expected);
+    });
+    it('renders Infinity', function () {
+      const expected = 'end of time';
+      const result = th.dateFormat(Infinity, expected);
+      assert.strictEqual(result, expected);
+    });
+    it('renders -Infinity', function () {
+      const expected = 'beginning of time';
+      const result = th.dateFormat(-Infinity, undefined, expected);
+      assert.strictEqual(result, expected);
+    });
+    it('renders a Date', function () {
+      const expected = 'Mar 27, 2022, 3:28:05 PM PDT';
+      const result = th.dateFormat(new Date('2022-03-27T22:28:05.049Z'));
+      assert.strictEqual(result, expected);
+    });
+    it('renders a timestamp', function () {
+      const expected = 'Mar 27, 2022, 3:28:05 PM PDT';
+      const result = th.dateFormat(1648420085049);
+      assert.strictEqual(result, expected);
+    });
+  }); // dateFormat
+
   describe('secondsToPeriod', function () {
     it('covers seconds', function () {
       const result = th.secondsToPeriod(45);
@@ -138,6 +171,13 @@ describe('Template Helper', function () {
     });
   }); // LI
 
+  describe('indented', function () {
+    it('covers', function () {
+      const result = th.indented(2, ['foo', 'bar']);
+      result.forEach((r) => assert(r.startsWith('\t\t')));
+    });
+  }); // indented
+
   describe('htmlBody', function () {
     it('covers no main', function () {
       const result = th.htmlBody(pagePathLevel, ctx, options);