Coverage
100% line coverage
100% statement coverage
100% block coverage
90 SLOC
lib/AlertController.js
100% line coverage
100% statement coverage
100% block coverage
17 SLOC
| Line | Hits | Statements | Source | Action |
|---|---|---|---|---|
| 1 | not covered /* globals jQuery, alert */ | |||
| 2 | 1 | 100% | "use strict"; | |
| 3 | not covered | |||
| 4 | not covered /** | |||
| 5 | not covered * Controller to handle showing and hiding of server alert messages | |||
| 6 | not covered */ | |||
| 7 | 1 | 100% | var AlertController = function () {}; | |
| 8 | not covered | |||
| 9 | 1 | 100% | AlertController.prototype = { /** * show the message * @param {String} html message * @return {AlertController} instance of this class for chaining */ show: function (html) { | |
| 10 | not covered /** | |||
| 11 | not covered * show the message | |||
| 12 | not covered * @param {String} html message | |||
| 13 | not covered * @return {AlertController} instance of this class for chaining | |||
| 14 | not covered */ | |||
| 15 | not covered show: function (html) { | |||
| 16 | 1 | 100% | var me = this; | |
| 17 | 1 | 100% | me.message.html(html); | |
| 18 | 1 | 100% | me.container.addClass("showing"); | |
| 19 | 1 | 100% | return me; | |
| 20 | not covered }, | |||
| 21 | not covered | |||
| 22 | not covered /** | |||
| 23 | not covered * hide the message | |||
| 24 | not covered * @return {AlertController} instance of this class for chaining | |||
| 25 | not covered */ | |||
| 26 | not covered hide: function () { | |||
| 27 | 1 | 100% | var me = this; | |
| 28 | 1 | 100% | me.container.removeClass("showing"); | |
| 29 | 1 | 100% | return me; | |
| 30 | not covered }, | |||
| 31 | not covered | |||
| 32 | not covered /** | |||
| 33 | not covered * entry point into the controller, binds event listeners | |||
| 34 | not covered * @return {AlertController} instance of this class for chaining | |||
| 35 | not covered */ | |||
| 36 | not covered bindListeners: function () { | |||
| 37 | 2 | 100% | var me = this; | |
| 38 | 2 | 100% | me.container = $('.alertContainer'); | |
| 39 | 2 | 100% | me.message = me.container.find('.message:first'); | |
| 40 | not covered | |||
| 41 | 2 | 100% | $("#ok").on("click", me.hide.bind(me)); | |
| 42 | not covered } | |||
| 43 | not covered }; | |||
| 44 | not covered | |||
| 45 | not covered // to pull into node namespace if included | |||
| 46 | 1 | 100% | if (typeof module !== "undefined" && module.exports !== undefined) { | |
| 47 | 1 | 100% | module.exports = AlertController; | |
| 48 | not covered } |
lib/WutController.js
100% line coverage
100% statement coverage
100% block coverage
73 SLOC
| Line | Hits | Statements | Source | Action |
|---|---|---|---|---|
| 1 | not covered /* globals jQuery, chrome, message, AlertController */ | |||
| 2 | 1 | 100% | "use strict"; | |
| 3 | not covered /** | |||
| 4 | not covered * Controller to handle the majority of the binding of events and actions for the user, | |||
| 5 | not covered * from clicking on various things to handling the copy to clipboard event and so forth. | |||
| 6 | not covered * @param {String} message the instance of AlertController class that this class needs | |||
| 7 | not covered */ | |||
| 8 | 1 | 100% | var WutController = function (message) { | |
| 9 | 1 | 100% | var me = this; | |
| 10 | 1 | 100% | me.message = message; | |
| 11 | not covered }; | |||
| 12 | not covered | |||
| 13 | 1 | 100% | WutController.prototype = { /** * method to 0 pad a number between 0-9 (for the purpose of date/time) * @param {Number} n the number to pad * @return {Number} the padded number */ pad: function(n){ | |
| 14 | not covered /** | |||
| 15 | not covered * method to 0 pad a number between 0-9 (for the purpose of date/time) | |||
| 16 | not covered * @param {Number} n the number to pad | |||
| 17 | not covered * @return {Number} the padded number | |||
| 18 | not covered */ | |||
| 19 | not covered pad: function(n){ | |||
| 20 | 12 | 100% | return n < 10 ? '0' + n : n; | |
| 21 | not covered }, | |||
| 22 | not covered | |||
| 23 | not covered /** | |||
| 24 | not covered * focuses on the select input and selects it | |||
| 25 | not covered * @return {Collection} collection containing just the link item | |||
| 26 | not covered */ | |||
| 27 | not covered selectAll: function(){ | |||
| 28 | 1 | 100% | var $link = $("#link"); | |
| 29 | 1 | 100% | $link.focus(); | |
| 30 | 1 | 100% | $link.select(); | |
| 31 | 1 | 100% | return $link; | |
| 32 | not covered }, | |||
| 33 | not covered | |||
| 34 | not covered /** | |||
| 35 | not covered * execute the copy to clipboard operation | |||
| 36 | not covered * @return {Collection} collection containing just the link item | |||
| 37 | not covered */ | |||
| 38 | not covered executeCopy: function(){ | |||
| 39 | 1 | 100% | var me = this, | |
| 40 | 1 | 100% | input = document.createElement('textarea'), | |
| 41 | 1 | 100% | $link = $("#link"); | |
| 42 | 1 | 100% | document.body.appendChild(input); | |
| 43 | 1 | 100% | input.value = $link.html(); | |
| 44 | 1 | 100% | input.focus(); | |
| 45 | 1 | 100% | input.select(); | |
| 46 | 1 | 100% | document.execCommand('Copy'); | |
| 47 | 1 | 100% | input.remove(); | |
| 48 | 1 | 100% | $(".linkHolder").addClass("copied"); | |
| 49 | 1 | 100% | setTimeout(function() { | |
| 50 | 1 | 100% | $(".linkHolder").removeClass("copied"); | |
| 51 | not covered },2000); | |||
| 52 | 1 | 100% | return $link; | |
| 53 | not covered }, | |||
| 54 | not covered | |||
| 55 | not covered /** | |||
| 56 | not covered * perform the ajax request to generate the link and delegate response callbacks | |||
| 57 | not covered * @return {Deferred} the deferred object generated by $.ajax | |||
| 58 | not covered */ | |||
| 59 | not covered generateLink : function() { | |||
| 60 | 4 | 100% | var me = this, | |
| 61 | 4 | 100% | url = $("#urlField").val() || $("#urlField").attr("placeholder"), | |
| 62 | 4 | 100% | activateDate = $("#activationDateField").val(), | |
| 63 | 4 | 100% | deactivateDate = $("#deactivationDateField").val(), | |
| 64 | 4 | 100% | button = $("#generateLink"); | |
| 65 | not covered | |||
| 66 | 4 | 100% | if (button.hasClass("disabled")) { | |
| 67 | 1 | 100% | return false; | |
| 68 | not covered } | |||
| 69 | not covered | |||
| 70 | 3 | 100% | button.addClass("disabled").html("Generating..."); | |
| 71 | not covered | |||
| 72 | 3 | 100% | return $.ajax({ url:"http://wut.link/", type:"POST", dataType: "json", data:{ url:url, activateDate: activateDate, deactivateDate: deactivateDate }, | |
| 73 | not covered url:"http://wut.link/", | |||
| 74 | not covered type:"POST", | |||
| 75 | not covered dataType: "json", | |||
| 76 | not covered data:{ | |||
| 77 | not covered url:url, | |||
| 78 | not covered activateDate: activateDate, | |||
| 79 | not covered deactivateDate: deactivateDate | |||
| 80 | not covered }, | |||
| 81 | 3 | 100% | success: me.handleResponse.bind(me) | |
| 82 | not covered }); | |||
| 83 | not covered | |||
| 84 | not covered }, | |||
| 85 | not covered | |||
| 86 | not covered /** | |||
| 87 | not covered * handle the actual ajax response (route to success or error callback) | |||
| 88 | not covered * @param {Object} response Response object | |||
| 89 | not covered * @return {Object} response Response object for potential chaining | |||
| 90 | not covered */ | |||
| 91 | not covered handleResponse: function(response) { | |||
| 92 | 2 | 100% | var me = this; | |
| 93 | not covered if (response.errors) { | |||
| 94 | 1 | 100% | me.onGenerateLinkError(response.errors); | |
| 95 | not covered } else { | |||
| 96 | 1 | 100% | me.onGenerateLinkSuccess(response); | |
| 97 | not covered } | |||
| 98 | not covered | |||
| 99 | 2 | 100% | me.resetGenerateLinkButton(); | |
| 100 | 2 | 100% | return response; | |
| 101 | not covered }, | |||
| 102 | not covered | |||
| 103 | not covered /** | |||
| 104 | not covered * generate error message returned trying to make link | |||
| 105 | not covered * @param {Object} errors object containing the errors | |||
| 106 | not covered * @return {Array} array of error Strings | |||
| 107 | not covered */ | |||
| 108 | not covered onGenerateLinkError: function (errors) { | |||
| 109 | 1 | 100% | var me = this, text = [], error; | |
| 110 | not covered text = [], | |||
| 111 | not covered error; | |||
| 112 | not covered | |||
| 113 | 1 | 100% | if (typeof errors === "object") { | |
| 114 | not covered for (error in errors) { | |||
| 115 | 2 | 100% | if (errors.hasOwnProperty(error)) { | |
| 116 | 2 | 100% | text = text.concat(errors[error]); | |
| 117 | not covered } | |||
| 118 | not covered } | |||
| 119 | not covered } | |||
| 120 | not covered | |||
| 121 | 1 | 100% | if (text.length && me.message !== undefined) { | |
| 122 | 1 | 100% | text.unshift("A link wasn't created because:<br>"); | |
| 123 | 1 | 100% | me.message.show(text.join('<br>')); | |
| 124 | not covered } | |||
| 125 | not covered | |||
| 126 | 1 | 100% | return text; | |
| 127 | not covered }, | |||
| 128 | not covered | |||
| 129 | not covered /** | |||
| 130 | not covered * clear out the form after a successful link generation, and if copyAsap | |||
| 131 | not covered * is checked, also copy that link to the clipboard | |||
| 132 | not covered * @param {Object} response json response from server | |||
| 133 | not covered * @return {Object} json response from server | |||
| 134 | not covered */ | |||
| 135 | not covered onGenerateLinkSuccess: function (response) { | |||
| 136 | 3 | 100% | var me = this, button = $("#generateLink"); | |
| 137 | not covered button = $("#generateLink"); | |||
| 138 | 3 | 100% | $("#link").html(response.proxyUrl); | |
| 139 | 3 | 100% | $(".linkHolder").addClass("loaded"); | |
| 140 | 3 | 100% | button.removeClass("disabled").html("Create Link"); | |
| 141 | 3 | 100% | if ($('#copyAsap').is(':checked')) { | |
| 142 | 1 | 100% | me.executeCopy(); | |
| 143 | not covered } | |||
| 144 | not covered | |||
| 145 | 3 | 100% | return me; | |
| 146 | not covered }, | |||
| 147 | not covered | |||
| 148 | not covered /** | |||
| 149 | not covered * on chrome tab query, set the urlField's placeholder to the url | |||
| 150 | not covered * @param {Collection} tabs collection of chrome tabs | |||
| 151 | not covered * @return {Collection} collection of chrome tabs | |||
| 152 | not covered */ | |||
| 153 | not covered onTabQuery: function(tabs) { | |||
| 154 | 1 | 100% | $("#urlField").attr("placeholder",tabs[0].url); | |
| 155 | 1 | 100% | return tabs; | |
| 156 | not covered }, | |||
| 157 | not covered | |||
| 158 | not covered /** | |||
| 159 | not covered * entry point into the controller, binds event listeners and then | |||
| 160 | not covered * binds the event listeners on the child AlertController class. | |||
| 161 | not covered * @return {WutController} the instance for chaining | |||
| 162 | not covered */ | |||
| 163 | not covered bindListeners: function() { | |||
| 164 | 1 | 100% | var me = this; | |
| 165 | not covered // set placeholder to current url (will use this if not provided by user) | |||
| 166 | 1 | 100% | chrome.tabs.query({'active': true,'currentWindow':true}, me.onTabQuery); | |
| 167 | not covered | |||
| 168 | 1 | 100% | $("#generateLink").on("click", me.generateLink.bind(me)); | |
| 169 | 1 | 100% | $("#link").on("click",this.selectAll); | |
| 170 | 1 | 100% | $("#copyButton").on("click",this.executeCopy); | |
| 171 | 1 | 100% | me.message.bindListeners(); | |
| 172 | not covered | |||
| 173 | 1 | 100% | return me; | |
| 174 | not covered }, | |||
| 175 | not covered | |||
| 176 | not covered /** | |||
| 177 | not covered * after an ajax attempt, clear the generate link styles and text | |||
| 178 | not covered * @return {Collection} collection of jQuery objects containing the button | |||
| 179 | not covered */ | |||
| 180 | not covered resetGenerateLinkButton: function () { | |||
| 181 | 3 | 100% | $("#generateLink").removeClass("disabled"); | |
| 182 | 3 | 100% | $("#generateLink").html("Create Link"); | |
| 183 | 3 | 100% | return $("#generateLink"); | |
| 184 | not covered } | |||
| 185 | not covered }; | |||
| 186 | not covered | |||
| 187 | not covered // to pull into node namespace if included | |||
| 188 | 1 | 100% | if (typeof module !== "undefined" && module.exports !== undefined) { | |
| 189 | 1 | 100% | module.exports = WutController; | |
| 190 | not covered } |