Skip to content

Commit 2ace3ee

Browse files
committed
Tests for imported javascript #49
1 parent 33c9390 commit 2ace3ee

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

karma.conf.js

+3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ module.exports = function (config) {
3232
"grails-app/assets/vendor/expr-eval/1.2.1/bundle.js",
3333
'grails-app/assets/vendor/jquery.validationEngine/jquery.validationEngine.js',
3434
'grails-app/assets/vendor/jquery.validationEngine/jquery.validationEngine-en.js',
35+
'grails-app/assets/vendor/momentjs/2.24.0/moment.min.js',
36+
'grails-app/assets/vendor/momentjs/2.24.0/locales/en-au.js',
37+
'grails-app/assets/vendor/momentjs/moment-timezone-with-data.min.js',
3538
'grails-app/assets/javascripts/forms.js',
3639
'grails-app/assets/javascripts/*.js',
3740
'test/js/util/*.js',

test/js/spec/KnockoutDatesSpec.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
describe("knockout dates spec", function () {
2+
it("the simpleDate extender can work with ISO dates but display dates in a human readable format", function() {
3+
var simpleDate = ko.observable().extend({simpleDate:false});
4+
var date = Date.fromISO("2019-05-30T14:00:00Z");
5+
simpleDate(date);
6+
7+
expect(simpleDate.formattedDate()).toBe("31-05-2019"); // AEST
8+
});
9+
});

test/js/spec/UtilsSpec.js

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
describe("Utils Spec", function () {
2+
it("can format file sizes in a human readable form", function() {
3+
expect(formatBytes(10)).toBe("0.01 KB");
4+
expect(formatBytes(1000000000)).toBe("1.00 GB");
5+
expect(formatBytes(1000000)).toBe("1.00 MB");
6+
});
7+
8+
it("can format a date to the financial year in which it falls", function() {
9+
10+
expect(isoDateToFinancialYear("2017-12-31T13:00:00Z")).toBe("2017/2018");
11+
expect(isoDateToFinancialYear("2017-05-30T14:00:00Z")).toBe("2016/2017");
12+
expect(isoDateToFinancialYear("2017-07-01T14:00:00Z")).toBe("2017/2018");
13+
14+
});
15+
16+
it("will treat a date at midnight of July 1 as the previous financial year", function() {
17+
expect(isoDateToFinancialYear("2017-06-30T14:00:00Z")).toBe("2016/2017");
18+
});
19+
20+
it("can parse a date from an iso string", function() {
21+
var date = Date.fromISO("2019-02-01T03:23:55Z");
22+
expect(date.getUTCDate()).toBe(1);
23+
expect(date.getUTCMonth()).toBe(1);
24+
expect(date.getUTCFullYear()).toBe(2019);
25+
expect(date.getUTCMinutes()).toBe(23);
26+
expect(date.getUTCHours()).toBe(3);
27+
});
28+
29+
it("can tell if a date is valid", function() {
30+
expect(isValidDate("3")).toBeFalsy();
31+
expect(isValidDate(new Date())).toBeTruthy();
32+
});
33+
34+
it("can format a UTC date into a simple date string", function() {
35+
expect(convertToSimpleDate("2019-01-31T13:00:00Z")).toBe("01-02-2019");
36+
});
37+
38+
it("can format a date in ISO 8601 format", function() {
39+
expect(convertToIsoDate("2019-01-31T13:00:00Z")).toBe("2019-01-31T13:00:00Z");
40+
expect(convertToIsoDate("31-01-2019")).toBe("2019-01-30T13:00:00Z"); // Potentially problematic due to time zones in travis...
41+
})
42+
});

0 commit comments

Comments
 (0)