Skip to content

Commit

Permalink
☔ Add tests to increase coverage (#115)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbody authored Jul 21, 2017
1 parent 1d971b3 commit ddfcb49
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
14 changes: 4 additions & 10 deletions js/helper-functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,10 @@ String.prototype.setFormat = function(styleEnumValue) {
var type = StyleEnum.toString(styleEnumValue);
var style = defaultStyles[type] ?
defaultStyles[type] : defaultStyles.standard;
var color = style.color ? style.color : defaultStyles.standard.color;
var color = style.color && isValidColor(style.color) ? style.color : defaultStyles.standard.color;
var bold = style.bold ? style.bold : defaultStyles.standard.bold;
var italic = style.italic ? style.italic : defaultStyles.standard.italic;
var backgroundColor = style.backgroundColor ?
var backgroundColor = style.backgroundColor && isValidColor(style.backgroundColor) ?
style.backgroundColor : defaultStyles.standard.backgroundColor;

if (bold) {
Expand All @@ -122,25 +122,19 @@ String.prototype.setFormat = function(styleEnumValue) {
result += "i";
}

if (color && isValidColor(color)) {
if (color) {
result += CONSTANTS.SEMI_COLON;
result += color;
} else {
// Set to null, if the color is not valid
color = null;
}

if (backgroundColor && isValidColor(backgroundColor)) {
if (backgroundColor) {
if (bold || italic || color) {
result += CONSTANTS.SEMI_COLON;
}
result += backgroundColor;
} else {
result += bold ? CONSTANTS.EMPTY : CONSTANTS.SEMI_COLON;
result += italic ? CONSTANTS.EMPTY : CONSTANTS.SEMI_COLON;
result += color ? CONSTANTS.EMPTY : CONSTANTS.SEMI_COLON;

result += defaultStyles.standard.backgroundColor;
}

return wrappedFormatting(result, this);
Expand Down
16 changes: 16 additions & 0 deletions spec/helping-functions-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ describe("Set format", function() {
beforeEach(function() {
this.exampleText = "Hello World";
});

afterEach(function() {
defaultStyles['name']['color'] = "green";
});

it("Title format", function() {
expect(this.exampleText.setFormat(StyleEnum.TITLE)).toBe("[[b;red;#000]Hello World]");
Expand Down Expand Up @@ -232,6 +236,18 @@ describe("Set format", function() {
it("Accepts empty style and text", function() {
expect("".setFormat("")).toBe("");
});

it('Accepts invalid styles', function() {
defaultStyles['title']['color'] = "cat";
expect(this.exampleText.setFormat(StyleEnum.TITLE)).toBe("[[b;white;#000]Hello World]");
expect(this.exampleText.setTitle()).toBe("[[b;white;#000]Hello World]");
});

it('Accepts empty default styles', function() {
defaultStyles['name']['color'] = null;
expect(this.exampleText.setFormat(StyleEnum.NAME)).toBe("[[b;white;#000]Hello World]");
expect(this.exampleText.setName()).toBe("[[b;white;#000]Hello World]");
});
});

describe("Date formatting", function() {
Expand Down

0 comments on commit ddfcb49

Please sign in to comment.