Add a simple (first) test for localetime Handlebars helper

This commit is contained in:
Jérémie Astori 2016-10-18 23:30:46 -04:00
parent 04f23704b8
commit 1ff011dfaf
3 changed files with 29 additions and 2 deletions

View File

@ -12,14 +12,14 @@
}, },
"homepage": "https://thelounge.github.io/", "homepage": "https://thelounge.github.io/",
"scripts": { "scripts": {
"coverage": "istanbul cover node_modules/mocha/bin/_mocha -r test/fixtures/env.js test/**/*.js", "coverage": "istanbul cover node_modules/mocha/bin/_mocha",
"start": "node index", "start": "node index",
"build": "npm-run-all build:*", "build": "npm-run-all build:*",
"build:font-awesome": "node scripts/build-fontawesome.js", "build:font-awesome": "node scripts/build-fontawesome.js",
"build:libs": "uglifyjs client/js/libs/*.js client/js/libs/jquery/*.js client/js/libs/handlebars/*.js -o client/js/libs.min.js --source-map client/js/libs.min.js.map --source-map-url libs.min.js.map -p relative", "build:libs": "uglifyjs client/js/libs/*.js client/js/libs/jquery/*.js client/js/libs/handlebars/*.js -o client/js/libs.min.js --source-map client/js/libs.min.js.map --source-map-url libs.min.js.map -p relative",
"build:handlebars": "handlebars client/views/ -e tpl -f client/js/lounge.templates.js", "build:handlebars": "handlebars client/views/ -e tpl -f client/js/lounge.templates.js",
"test": "npm-run-all -c test:mocha lint", "test": "npm-run-all -c test:mocha lint",
"test:mocha": "mocha -r test/fixtures/env.js test/**/*.js", "test:mocha": "mocha",
"lint": "npm-run-all -c lint:js lint:css", "lint": "npm-run-all -c lint:js lint:css",
"lint:js": "npm-run-all -c lint:js:es5 lint:js:es6", "lint:js": "npm-run-all -c lint:js:es5 lint:js:es6",
"lint:js:es5": "eslint --parser-options=\"ecmaVersion:5\" client/", "lint:js:es5": "eslint --parser-options=\"ecmaVersion:5\" client/",

View File

@ -0,0 +1,25 @@
"use strict";
const Handlebars = global.Handlebars = require("handlebars");
const expect = require("chai").expect;
require("../../../../../client/js/libs/handlebars/localetime");
describe("localetime Handlebars helper", () => {
it("should render a human-readable date", () => {
const template = Handlebars.compile("{{localetime time}}");
// 12PM in UTC time
const date = new Date("2014-05-22T12:00:00");
// Offset between UTC and local timezone
const offset = date.getTimezoneOffset() * 60 * 1000;
// Pretend local timezone is UTC by moving the clock of that offset
const time = date.getTime() + offset;
expect(template({time: time})).to.equal("5/22/2014, 12:00:00 PM");
});
});

2
test/mocha.opts Normal file
View File

@ -0,0 +1,2 @@
--require test/fixtures/env
--recursive