mirror of
https://github.com/thelounge/thelounge
synced 2024-11-10 06:34:21 +00:00
Add a simple (first) test for localetime Handlebars helper
This commit is contained in:
parent
04f23704b8
commit
1ff011dfaf
3 changed files with 29 additions and 2 deletions
|
@ -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/",
|
||||
|
|
25
test/client/js/libs/handlebars/localetimeTest.js
Normal file
25
test/client/js/libs/handlebars/localetimeTest.js
Normal 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
2
test/mocha.opts
Normal file
|
@ -0,0 +1,2 @@
|
|||
--require test/fixtures/env
|
||||
--recursive
|
Loading…
Reference in a new issue