From 800a96feb106d41fd250fcf58911bc7932fa78d6 Mon Sep 17 00:00:00 2001 From: Florin Alexandrescu Date: Wed, 4 Feb 2015 21:42:37 -0700 Subject: [PATCH 1/3] Support multiple parameters with the same name --- extension/js/popup.js | 12 ++++++++---- extension/js/queryStringParser.js | 7 ++++--- test/queryStringParser-Tests.js | 22 +++++++++++++--------- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/extension/js/popup.js b/extension/js/popup.js index f383b15..b06e53b 100644 --- a/extension/js/popup.js +++ b/extension/js/popup.js @@ -10,16 +10,20 @@ window.processTabUrl = function(tabUrl) { var values = parser.getValues(query); var itemsFound = false; - if(values!==null){ + if(values.length){ var table = document.getElementById("query-values"); - for(var name in values){ + + + for(var i = 0, len = values.length; i< len; i++){ itemsFound = true; var row = document.createElement("tr"); var colName = document.createElement("td"); var colValue = document.createElement("td"); - colName.innerHTML = name; - colValue.innerHTML = values[name] || " "; + for(var key in values[i]){ + colName.innerHTML = key; + colValue.innerHTML = values[i][key] || " "; + } row.appendChild(colName); row.appendChild(colValue); diff --git a/extension/js/queryStringParser.js b/extension/js/queryStringParser.js index 590df22..0487dc0 100644 --- a/extension/js/queryStringParser.js +++ b/extension/js/queryStringParser.js @@ -4,12 +4,13 @@ function QueryStringParser(){ this.getValues = function(url){ var query = this.getQueryFromUrl(url); - var values = {}; + var values = []; var match; while (!!(match = this.regExQuerySearch.exec(query))){ - values[this.decode(match[1])] = this.decode(match[2]); + var kv = {}; + kv[this.decode(match[1])] = this.decode(match[2]); + values.push(kv); } - return values; }; diff --git a/test/queryStringParser-Tests.js b/test/queryStringParser-Tests.js index 6383eec..4dc58e9 100644 --- a/test/queryStringParser-Tests.js +++ b/test/queryStringParser-Tests.js @@ -11,39 +11,43 @@ describe("queryStringParser", function() { describe("getValues()", function(){ it("should parse one value", function() { - evaluateItem("http://github.com/?me=you", {me: "you"}); + evaluateItem("http://github.com/?me=you", [{me: "you"}]); }); it("should parse 2 values", function() { - evaluateItem("http://github.com/?me=you&yomama=andyourcousintoo", {me: "you", yomama: 'andyourcousintoo'}); + evaluateItem("http://github.com/?me=you&yomama=andyourcousintoo", [{me: "you"}, {yomama: 'andyourcousintoo'}]); }); it("should parse multi values", function() { - evaluateItem("http://github.com/?me=you&yomama=andyour,cousintoo", {me: "you", yomama: 'andyour,cousintoo'}); + evaluateItem("http://github.com/?me=you&yomama=andyour,cousintoo", [{me: "you"},{yomama: 'andyour,cousintoo'}]); }); it("should parse with a + in the values", function() { - evaluateItem("http://github.com/?me=you&yomama=andyour+cousintoo", {me: "you", yomama: 'andyour cousintoo'}); + evaluateItem("http://github.com/?me=you&yomama=andyour+cousintoo", [{me: "you"}, {yomama: 'andyour cousintoo'}]); }); it("should parse with an encoded value", function() { - evaluateItem("http://github.com/?me=you%20too&yomama=andyour%20%26%20cousintoo", {me: "you too", yomama: 'andyour & cousintoo'}); + evaluateItem("http://github.com/?me=you%20too&yomama=andyour%20%26%20cousintoo", [{me: "you too"}, {yomama: 'andyour & cousintoo'}]); }); + it("should parse multiple keys with the same name", function() { + evaluateItem("http://github.com/?me=tarzan&you=mary&you=jane", [{me: "tarzan"}, {you: "mary"}, {you: "jane"}]); + }); + it("should return empty object when there is no query", function() { - evaluateItem("http://github.com", {}); + evaluateItem("http://github.com", []); }); it("should return empty object when there is no query", function() { - evaluateItem("http://github.com/", {}); + evaluateItem("http://github.com/", []); }); it("should return empty object when there is no query", function() { - evaluateItem("http://github.com/?", {}); + evaluateItem("http://github.com/?", []); }); it("should return a key but no value", function() { - evaluateItem("http://github.com/?me=", {me: ''}); + evaluateItem("http://github.com/?me=", [{me: ''}]); }); function evaluateItem(item, expected){ From ad7e57ba17a7a73bbb2371e073b1701a8d4d610e Mon Sep 17 00:00:00 2001 From: Florin Alexandrescu Date: Wed, 4 Feb 2015 21:43:37 -0700 Subject: [PATCH 2/3] Update karma config --- Gruntfile.js | 2 +- config/karma.conf.js | 106 +++++++++++++++++++++++-------------------- package.json | 2 + 3 files changed, 60 insertions(+), 50 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index afef18d..4525174 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -20,7 +20,7 @@ module.exports = function(grunt) { }, clean: { all: [ - 'build/temp/', + 'build/temp/' ] }, compress: { diff --git a/config/karma.conf.js b/config/karma.conf.js index 8039190..478d870 100644 --- a/config/karma.conf.js +++ b/config/karma.conf.js @@ -1,50 +1,58 @@ +module.exports = function(config) { + config.set({ -// base path, that will be used to resolve files and exclude -basePath = '../'; - -// list of files / patterns to load in the browser -files = [ - JASMINE, - JASMINE_ADAPTER, - 'extension/js/queryStringParser.js', - 'test/**/*.js' -]; - -// list of files to exclude -exclude = [ -]; - -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari -// - PhantomJS -browsers = [ - 'PhantomJS' -]; - -// test results reporter to use -// possible values: dots || progress -reporter = ['progress', 'growl']; - -// web server port -port = 9018; - -// cli runner port -runnerPort = 9100; - -// enable / disable colors in the output (reporters and logs) -colors = true; - -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; - -// enable / disable watching file and executing tests whenever any file changes -autoWatch = true; - -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; \ No newline at end of file + // base path, that will be used to resolve files and exclude + basePath: '../', + + // list of files / patterns to load in the browser + files: [ + 'extension/js/queryStringParser.js', + 'test/**/*.js' + ], + + // list of files to exclude + exclude: [ + ], + + frameworks: ['jasmine'], + + // Start these browsers, currently available: + // - Chrome + // - ChromeCanary + // - Firefox + // - Opera + // - Safari + // - PhantomJS + browsers: ['PhantomJS'], + + // test results reporter to use + // possible values: dots || progress + reporters: ['spec', 'progress', 'growl'], + + // web server port + port: 9018, + + // cli runner port + runnerPort: 9100, + + // enable / disable colors in the output (reporters and logs) + colors: true, + + // level of logging + // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG + //logLevel = config.LOG_INFO; + + // enable / disable watching file and executing tests whenever any file changes + autoWatch: true, + + // Continuous Integration mode + // if true, it capture browsers, run tests and exit + singleRun: false, + + plugins: [ + 'karma-phantomjs-launcher', + 'karma-jasmine' + ] + + }); +}; diff --git a/package.json b/package.json index cebefd8..c177a28 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,8 @@ "grunt-contrib-concat": "latest", "grunt-contrib-compress": "latest", "grunt-karma": "latest", + "karma-jasmine": "latest", + "karma-phantomjs-launcher" : "latest", "grunt-file-creator": "latest", "jasmine-node": "latest", "chai": "latest", From 70ffa5346e5c60be2200317534b34525ff87670d Mon Sep 17 00:00:00 2001 From: Florin Alexandrescu Date: Wed, 4 Feb 2015 21:53:57 -0700 Subject: [PATCH 3/3] Update readme with testing info. --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9371c53..83fdc89 100644 --- a/README.md +++ b/README.md @@ -37,9 +37,14 @@ From the Extensions Manager follow these steps: * Navigate to the repo directory and select the "extension" directory * Should be ~/Code/query-string-values-extension/extension +## Testing +Run tests with + + grunt karma + ## Using the extension -I haven't created a cool looking icon for this yet, but next to the navigation bar, you should see this icon ![Alt Query String Values] (https://raw.github.com/acolchado/query-string-values-extension/master/extension/img/icon-16.png), click it and you will see all of the query stirng values. +I haven't created a cool looking icon for this yet, but next to the navigation bar, you should see this icon ![Alt Query String Values] (https://raw.github.com/acolchado/query-string-values-extension/master/extension/img/icon-16.png), click it and you will see all of the query string values. ## Contributing