mirror of
https://github.com/MichMich/MagicMirror.git
synced 2025-06-27 11:50:00 +00:00
Add unittest for calendar module
Add unittest for 'getLocalSpecification' function.
This commit is contained in:
parent
1eb10e3c22
commit
e0414e4eb9
@ -12,6 +12,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- Add `.vscode/` folder to `.gitignore` to keep custom Visual Studio Code config out of git.
|
- Add `.vscode/` folder to `.gitignore` to keep custom Visual Studio Code config out of git.
|
||||||
- Add unit test the capitalizeFirstLetter function of newfeed module.
|
- Add unit test the capitalizeFirstLetter function of newfeed module.
|
||||||
- Add new unit tests for function `shorten` in calendar module.
|
- Add new unit tests for function `shorten` in calendar module.
|
||||||
|
- Add new unit tests for function `getLocaleSpecification` in calendar module.
|
||||||
|
|
||||||
### Updated
|
### Updated
|
||||||
- Changed 'default.js' - listen on all attached interfaces by default.
|
- Changed 'default.js' - listen on all attached interfaces by default.
|
||||||
|
@ -67,30 +67,7 @@ Module.register("calendar", {
|
|||||||
Log.log("Starting module: " + this.name);
|
Log.log("Starting module: " + this.name);
|
||||||
|
|
||||||
// Set locale.
|
// Set locale.
|
||||||
moment.locale(config.language);
|
moment.updateLocale(config.language, this.getLocaleSpecification(config.timeFormat));
|
||||||
|
|
||||||
switch (config.timeFormat) {
|
|
||||||
case 12: {
|
|
||||||
moment.updateLocale(config.language, {
|
|
||||||
longDateFormat: {
|
|
||||||
LT: "h:mm A"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 24: {
|
|
||||||
moment.updateLocale(config.language, {
|
|
||||||
longDateFormat: {
|
|
||||||
LT: "HH:mm"
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// If config.timeFormat was not given (or has invalid format) default to locale default
|
|
||||||
default: {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (var c in this.config.calendars) {
|
for (var c in this.config.calendars) {
|
||||||
var calendar = this.config.calendars[c];
|
var calendar = this.config.calendars[c];
|
||||||
@ -306,6 +283,31 @@ Module.register("calendar", {
|
|||||||
return wrapper;
|
return wrapper;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This function accepts a number (either 12 or 24) and returns a moment.js LocaleSpecification with the
|
||||||
|
* corresponding timeformat to be used in the calendar display. If no number is given (or otherwise invalid input)
|
||||||
|
* it will a localeSpecification object with the system locale time format.
|
||||||
|
*
|
||||||
|
* @param {number} timeFormat Specifies either 12 or 24 hour time format
|
||||||
|
* @returns {moment.LocaleSpecification}
|
||||||
|
*/
|
||||||
|
getLocaleSpecification: function(timeFormat) {
|
||||||
|
switch (timeFormat) {
|
||||||
|
case 12: {
|
||||||
|
return { longDateFormat: {LT: "h:mm A"} };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 24: {
|
||||||
|
return { longDateFormat: {LT: "HH:mm"} };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default: {
|
||||||
|
return { longDateFormat: {LT: moment.localeData().longDateFormat("LT")} };
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
/* hasCalendarURL(url)
|
/* hasCalendarURL(url)
|
||||||
* Check if this config contains the calendar url.
|
* Check if this config contains the calendar url.
|
||||||
*
|
*
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
var fs = require("fs");
|
const expect = require("chai").expect;
|
||||||
var path = require("path");
|
|
||||||
var chai = require("chai");
|
|
||||||
var expect = chai.expect;
|
|
||||||
var vm = require("vm");
|
|
||||||
|
|
||||||
|
global.moment = require("moment");
|
||||||
|
|
||||||
describe("Functions into modules/default/calendar/calendar.js", function() {
|
describe("Functions into modules/default/calendar/calendar.js", function() {
|
||||||
|
|
||||||
@ -35,6 +32,62 @@ describe("Functions into modules/default/calendar/calendar.js", function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("getLocaleSpecification", function() {
|
||||||
|
it("Should return a valid moment.LocaleSpecification for a 12-hour format", function() {
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification(12)).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a valid moment.LocaleSpecification for a 24-hour format", function() {
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification(24)).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return the current system locale when called without timeFormat number", function() {
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: moment.localeData().longDateFormat("LT")} } );
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 12-hour longDateFormat when using the 'en' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("en");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 12-hour longDateFormat when using the 'au' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("au");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 12-hour longDateFormat when using the 'eg' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("eg");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "h:mm A"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 24-hour longDateFormat when using the 'nl' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("nl");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 24-hour longDateFormat when using the 'fr' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("fr");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Should return a 24-hour longDateFormat when using the 'uk' locale", function() {
|
||||||
|
var localeBackup = moment.locale();
|
||||||
|
moment.locale("uk");
|
||||||
|
expect(Module.definitions.calendar.getLocaleSpecification()).to.deep.equal({ longDateFormat: {LT: "HH:mm"} });
|
||||||
|
moment.locale(localeBackup);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("shorten", function() {
|
describe("shorten", function() {
|
||||||
strings = {
|
strings = {
|
||||||
" String with whitespace at the beginning that needs trimming" : { length: 16, return: "String with whit…" },
|
" String with whitespace at the beginning that needs trimming" : { length: 16, return: "String with whit…" },
|
||||||
|
Loading…
x
Reference in New Issue
Block a user