2017-07-31 22:09:08 +02:00
|
|
|
const expect = require("chai").expect;
|
2017-03-26 00:49:00 -03:00
|
|
|
|
2017-07-31 22:09:08 +02:00
|
|
|
global.moment = require("moment");
|
2017-03-26 00:49:00 -03:00
|
|
|
|
|
|
|
describe("Functions into modules/default/calendar/calendar.js", function() {
|
|
|
|
|
|
|
|
// Fake for use by calendar.js
|
2019-06-04 10:19:25 +02:00
|
|
|
Module = {};
|
2017-03-26 00:49:00 -03:00
|
|
|
Module.definitions = {};
|
|
|
|
Module.register = function (name, moduleDefinition) {
|
|
|
|
Module.definitions[name] = moduleDefinition;
|
|
|
|
};
|
|
|
|
|
2017-07-25 09:32:32 -04:00
|
|
|
before(function() {
|
|
|
|
// load calendar.js
|
|
|
|
require("../../../modules/default/calendar/calendar.js");
|
|
|
|
});
|
2017-03-26 00:49:00 -03:00
|
|
|
|
|
|
|
describe("capFirst", function() {
|
|
|
|
words = {
|
2017-04-19 00:45:55 -03:00
|
|
|
"rodrigo": "Rodrigo",
|
|
|
|
"123m": "123m",
|
|
|
|
"magic mirror": "Magic mirror",
|
|
|
|
",a": ",a",
|
2017-03-26 00:49:00 -03:00
|
|
|
"ñandú": "Ñandú"
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(words).forEach(word => {
|
2017-07-29 16:02:53 +02:00
|
|
|
it(`for '${word}' should return '${words[word]}'`, function() {
|
2017-03-26 00:49:00 -03:00
|
|
|
expect(Module.definitions.calendar.capFirst(word)).to.equal(words[word]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2017-07-29 16:02:53 +02:00
|
|
|
|
2017-07-31 22:09:08 +02:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-07-29 16:02:53 +02:00
|
|
|
describe("shorten", function() {
|
|
|
|
strings = {
|
|
|
|
" String with whitespace at the beginning that needs trimming" : { length: 16, return: "String with whit…" },
|
|
|
|
"long string that needs shortening": { length: 16, return: "long string that…" },
|
|
|
|
"short string": { length: 16, return: "short string" },
|
|
|
|
"long string with no maxLength defined": { return: "long string with no maxLength defined" },
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(strings).forEach(string => {
|
|
|
|
it(`for '${string}' should return '${strings[string].return}'`, function() {
|
|
|
|
expect(Module.definitions.calendar.shorten(string, strings[string].length)).to.equal(strings[string].return);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should return an empty string if shorten is called with a non-string", function () {
|
|
|
|
expect(Module.definitions.calendar.shorten(100)).to.equal("");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should not shorten the string if shorten is called with a non-number maxLength", function () {
|
|
|
|
expect(Module.definitions.calendar.shorten("This is a test string", "This is not a number")).to.equal("This is a test string");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (with maxLength defined as 20)", function () {
|
|
|
|
expect(Module.definitions.calendar.shorten(
|
|
|
|
"This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true",
|
|
|
|
20,
|
|
|
|
true)).to.equal("This is a <br>wrapEvent test. Should wrap <br>the string instead of <br>shorten it if called with <br>wrapEvent = true");
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should wrap the string instead of shorten it if shorten is called with wrapEvents = true (without maxLength defined, default 25)", function () {
|
|
|
|
expect(Module.definitions.calendar.shorten(
|
|
|
|
"This is a wrapEvent test. Should wrap the string instead of shorten it if called with wrapEvent = true",
|
|
|
|
undefined,
|
|
|
|
true)).to.equal("This is a wrapEvent <br>test. Should wrap the string <br>instead of shorten it if called <br>with wrapEvent = true");
|
|
|
|
});
|
|
|
|
});
|
2017-03-26 00:49:00 -03:00
|
|
|
});
|
|
|
|
|