Skip to content

Commit

Permalink
🚑 Handle empty commands (#229)
Browse files Browse the repository at this point in the history
- Handle empty commands
- Unit test empty commands
- Prepare release 4.4.4
  • Loading branch information
bbody authored Dec 1, 2018
1 parent 42dd0c0 commit b367be6
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 32 deletions.
36 changes: 21 additions & 15 deletions dist/cmd-resume.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* v4.4.0 of CMD Resume by Brendon Body(https://github.com/bbody/CMD-Resume.git) */
/* v4.4.4 of CMD Resume by Brendon Body(https://github.com/bbody/CMD-Resume.git) */
;(function($){
"use strict";

Expand Down Expand Up @@ -88,6 +88,11 @@
}
};

// Check if an object has key and has length
var isDefinedNotEmpty = function(object, key) {
return key && typeof object[key] !== "undefined" && object[key].length;
};

// Calculate the formatting
var mergeFormatting = function(baseStyle, overRideStyle) {
if (overRideStyle.color && isValidColor(overRideStyle.color)) {
Expand Down Expand Up @@ -583,7 +588,7 @@
};

self.initName = function() {
if (self.data.basics.name) {
if (isDefinedNotEmpty(self.data.basics, "name")) {
self.commands.name = {
title: "Name",
description: "owner of the résumé",
Expand All @@ -594,7 +599,7 @@
};

self.initSummary = function() {
if (self.data.basics.summary) {
if (isDefinedNotEmpty(self.data.basics, "summary")) {
self.commands.about = {
title: "About",
description: "about me",
Expand All @@ -605,7 +610,7 @@
};

self.initPdfLink = function() {
if (self.data.basics.pdfLink) {
if (isDefinedNotEmpty(self.data.basics, "pdfLink")) {
self.commands.pdf = {
title: "Résumé PDF",
description: "pdf version of the résumé",
Expand All @@ -621,6 +626,7 @@
};

self.initLocation = function() {
// Is an object, so don't need to check length
if (self.data.basics.location) {
self.commands.location = {
title: "Location",
Expand Down Expand Up @@ -649,7 +655,7 @@
};

self.initLabel = function() {
if (self.data.basics.label) {
if (isDefinedNotEmpty(self.data.basics, "label")) {
self.commands.lookingfor = {
title: "Looking For",
description: "looking for what kind of position",
Expand All @@ -660,7 +666,7 @@
};

self.initProfiles = function() {
if (self.data.basics.profiles) {
if (isDefinedNotEmpty(self.data.basics, "profiles")) {
self.commands.socialmedia = {
title: "Social Media",
description: "social media profiles",
Expand All @@ -685,7 +691,7 @@
};

self.initSkills = function() {
if (self.data.skills) {
if (isDefinedNotEmpty(self.data, "skills")) {
self.commands.skills = {
title: "Skills",
description: "skills obtained",
Expand Down Expand Up @@ -750,7 +756,7 @@
};

self.initEducation = function() {
if (self.data.education) {
if (isDefinedNotEmpty(self.data, "education")) {
self.commands.education = {
title: "Education",
description: "education history",
Expand All @@ -772,7 +778,7 @@
};

self.initWork = function() {
if (self.data.work && self.data.work.length) {
if (isDefinedNotEmpty(self.data, "work")) {
self.commands.employment = {
title: "Employment",
description: "employment history",
Expand All @@ -794,7 +800,7 @@
};

self.initVolunteer = function() {
if (self.data.volunteer) {
if (isDefinedNotEmpty(self.data, "volunteer")) {
self.commands.volunteering = {
title: "Volunteering",
description: "volunteering history",
Expand All @@ -816,7 +822,7 @@
};

self.initAwards = function() {
if (self.data.awards) {
if (isDefinedNotEmpty(self.data, "awards")) {
self.commands.awards = {
title: "Awards",
description: "awards obtained",
Expand All @@ -838,7 +844,7 @@
};

self.initPublications = function() {
if (self.data.publications) {
if (isDefinedNotEmpty(self.data, "publications")) {
self.commands.publications = {
title: "Publications",
description: "publications produced",
Expand All @@ -860,7 +866,7 @@
};

self.initLanguages = function() {
if (self.data.languages) {
if (isDefinedNotEmpty(self.data, "languages")) {
self.commands.languages = {
title: "Languages",
description: "languages",
Expand All @@ -879,7 +885,7 @@
};

self.initInterests = function() {
if (self.data.interests) {
if (isDefinedNotEmpty(self.data, "interests")) {
self.commands.interests = {
title: "Interests",
description: "interests",
Expand All @@ -898,7 +904,7 @@
};

self.initReferences = function() {
if (self.data.references) {
if (isDefinedNotEmpty(self.data, "references")) {
self.commands.references = {
title: "References",
description: "references",
Expand Down
4 changes: 2 additions & 2 deletions dist/cmd-resume.min.js

Large diffs are not rendered by default.

29 changes: 15 additions & 14 deletions js/cmd-resume.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initName = function() {
if (self.data.basics.name) {
if (isDefinedNotEmpty(self.data.basics, "name")) {
self.commands.name = {
title: "Name",
description: "owner of the résumé",
Expand All @@ -153,7 +153,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initSummary = function() {
if (self.data.basics.summary) {
if (isDefinedNotEmpty(self.data.basics, "summary")) {
self.commands.about = {
title: "About",
description: "about me",
Expand All @@ -164,7 +164,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initPdfLink = function() {
if (self.data.basics.pdfLink) {
if (isDefinedNotEmpty(self.data.basics, "pdfLink")) {
self.commands.pdf = {
title: "Résumé PDF",
description: "pdf version of the résumé",
Expand All @@ -180,6 +180,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initLocation = function() {
// Is an object, so don't need to check length
if (self.data.basics.location) {
self.commands.location = {
title: "Location",
Expand Down Expand Up @@ -208,7 +209,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initLabel = function() {
if (self.data.basics.label) {
if (isDefinedNotEmpty(self.data.basics, "label")) {
self.commands.lookingfor = {
title: "Looking For",
description: "looking for what kind of position",
Expand All @@ -219,7 +220,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initProfiles = function() {
if (self.data.basics.profiles) {
if (isDefinedNotEmpty(self.data.basics, "profiles")) {
self.commands.socialmedia = {
title: "Social Media",
description: "social media profiles",
Expand All @@ -244,7 +245,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initSkills = function() {
if (self.data.skills) {
if (isDefinedNotEmpty(self.data, "skills")) {
self.commands.skills = {
title: "Skills",
description: "skills obtained",
Expand Down Expand Up @@ -309,7 +310,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initEducation = function() {
if (self.data.education) {
if (isDefinedNotEmpty(self.data, "education")) {
self.commands.education = {
title: "Education",
description: "education history",
Expand All @@ -331,7 +332,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initWork = function() {
if (self.data.work && self.data.work.length) {
if (isDefinedNotEmpty(self.data, "work")) {
self.commands.employment = {
title: "Employment",
description: "employment history",
Expand All @@ -353,7 +354,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initVolunteer = function() {
if (self.data.volunteer) {
if (isDefinedNotEmpty(self.data, "volunteer")) {
self.commands.volunteering = {
title: "Volunteering",
description: "volunteering history",
Expand All @@ -375,7 +376,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initAwards = function() {
if (self.data.awards) {
if (isDefinedNotEmpty(self.data, "awards")) {
self.commands.awards = {
title: "Awards",
description: "awards obtained",
Expand All @@ -397,7 +398,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initPublications = function() {
if (self.data.publications) {
if (isDefinedNotEmpty(self.data, "publications")) {
self.commands.publications = {
title: "Publications",
description: "publications produced",
Expand All @@ -419,7 +420,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initLanguages = function() {
if (self.data.languages) {
if (isDefinedNotEmpty(self.data, "languages")) {
self.commands.languages = {
title: "Languages",
description: "languages",
Expand All @@ -438,7 +439,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initInterests = function() {
if (self.data.interests) {
if (isDefinedNotEmpty(self.data, "interests")) {
self.commands.interests = {
title: "Interests",
description: "interests",
Expand All @@ -457,7 +458,7 @@ $.fn.CMDResume = function(primaryEndpoint, options) {
};

self.initReferences = function() {
if (self.data.references) {
if (isDefinedNotEmpty(self.data, "references")) {
self.commands.references = {
title: "References",
description: "references",
Expand Down
5 changes: 5 additions & 0 deletions js/helpers/misc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,8 @@ var isValidColor = function(color) {
return false;
}
};

// Check if an object has key and has length
var isDefinedNotEmpty = function(object, key) {
return key && typeof object[key] !== "undefined" && object[key].length;
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"jquery-plugin",
"ecosystem:jquery"
],
"version": "4.4.3",
"version": "4.4.4",
"author": {
"name": "Brendon Body",
"url": "https://github.com/bbody"
Expand Down
52 changes: 52 additions & 0 deletions spec/helpers/misc.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,56 @@ describe("misc", function() {
expect(isValidColor()).toBeFalsy();
});
});

describe("Color validator", function() {
it("Hex code (3 digits)", function() {
expect(isValidColor("#FFF")).toBeTruthy();
});

it("Hex code (6 digits)", function() {
expect(isValidColor("#C0FFEE")).toBeTruthy();
});

it("Color name", function() {
expect(isValidColor("white")).toBeTruthy();
});

it("Invalid color name", function() {
expect(isValidColor("test")).toBeFalsy();
});

it("Empty string", function() {
expect(isValidColor("")).toBeFalsy();
});

it("Empty string", function() {
expect(isValidColor(null)).toBeFalsy();
});

it("Empty string", function() {
expect(isValidColor()).toBeFalsy();
});
});

describe("Object has key defined and not empty", function() {
it("Handles no key", function() {
expect(isDefinedNotEmpty({}, "key")).toBeFalsy();
});

it("Has string with length", function() {
expect(isDefinedNotEmpty({"key": ""}, "key")).toBeFalsy();
});

it("Has string with length", function() {
expect(isDefinedNotEmpty({"key": "a"}, "key")).toBeTruthy();
});

it("Handles empty array", function() {
expect(isDefinedNotEmpty({"key": []}, "key")).toBeFalsy();
});

it("Handles array", function() {
expect(isDefinedNotEmpty({"key": ["value"]}, "key")).toBeTruthy();
});
});
});

0 comments on commit b367be6

Please sign in to comment.