-
Notifications
You must be signed in to change notification settings - Fork 4
/
template.test.js
40 lines (31 loc) · 1.24 KB
/
template.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
global.chrome = {
action: {
onClicked: {
addListener: function () {}
}
}
};
import {populateTemplate} from './template.js';
import {Settings, DateTime} from "./third_party/luxon.min.js";
// Set the time to be constant for testing.
// From: https://github.com/moment/luxon/issues/254#issuecomment-386495652
Settings.now = () => 1494837020000; // 2017-05-15 08:30:20 AM GMT.
Settings.defaultZone = 'gmt' // Otherwise dates depend on local machine timezone.
test('test short title', () => {
expect(populateTemplate("{{ short_title }} (book)", {short_title: "Hello"})).toBe("Hello (book)");
});
test('test date', () => {
expect(populateTemplate("{{ date }}", {short_title: "Hello"})).toBe("2017-05-15");
});
test('test time', () => {
expect(populateTemplate("{{ time }}", {short_title: "Hello"})).toBe("08:30");
});
test('test date formatting', () => {
expect(populateTemplate("{{ date:ffff }}", {})).toBe("Monday, 15 May 2017, 08:30 Coordinated Universal Time")
});
test('test isbn13', () => {
expect(populateTemplate("{{ isbn13 }}", {isbn13: "0123456789012"})).toBe("0123456789012");
});
test('test missing isbn13', () => {
expect(populateTemplate("{{ isbn13 }}", {isbn13: null})).toBe("");
});