From 1ff011dfaffffc52b7024da7dff85f28cb8233f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Tue, 18 Oct 2016 23:30:46 -0400 Subject: [PATCH] Add a simple (first) test for localetime Handlebars helper --- package.json | 4 +-- .../js/libs/handlebars/localetimeTest.js | 25 +++++++++++++++++++ test/mocha.opts | 2 ++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/client/js/libs/handlebars/localetimeTest.js create mode 100644 test/mocha.opts diff --git a/package.json b/package.json index bafd97dc..9b822647 100644 --- a/package.json +++ b/package.json @@ -12,14 +12,14 @@ }, "homepage": "https://thelounge.github.io/", "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", "build": "npm-run-all build:*", "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:handlebars": "handlebars client/views/ -e tpl -f client/js/lounge.templates.js", "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:js": "npm-run-all -c lint:js:es5 lint:js:es6", "lint:js:es5": "eslint --parser-options=\"ecmaVersion:5\" client/", diff --git a/test/client/js/libs/handlebars/localetimeTest.js b/test/client/js/libs/handlebars/localetimeTest.js new file mode 100644 index 00000000..66cbc648 --- /dev/null +++ b/test/client/js/libs/handlebars/localetimeTest.js @@ -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"); + }); + +}); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 00000000..09f51914 --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,2 @@ +--require test/fixtures/env +--recursive