Add new unit tests

Add new unit tests for 'shorten' function in calendar module
This commit is contained in:
Bas van Wetten
2017-07-29 16:02:53 +02:00
parent bf24ee369f
commit 35e3b889c3
3 changed files with 56 additions and 16 deletions

View File

@@ -27,10 +27,47 @@ describe("Functions into modules/default/calendar/calendar.js", function() {
};
Object.keys(words).forEach(word => {
it(`for ${word} should return ${words[word]}`, function() {
it(`for '${word}' should return '${words[word]}'`, function() {
expect(Module.definitions.calendar.capFirst(word)).to.equal(words[word]);
});
});
});
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");
});
});
});