diff --git a/lib/jasmine-core/boot.js b/lib/jasmine-core/boot.js index f623e6a0..8da6900b 100644 --- a/lib/jasmine-core/boot.js +++ b/lib/jasmine-core/boot.js @@ -84,7 +84,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ var htmlReporter = new jasmine.HtmlReporter({ env: env, - onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, + onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); }, + addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); }, getContainer: function() { return document.body; }, createElement: function() { return document.createElement.apply(document, arguments); }, createTextNode: function() { return document.createTextNode.apply(document, arguments); }, diff --git a/lib/jasmine-core/boot/boot.js b/lib/jasmine-core/boot/boot.js index 164f068b..e8ddd551 100644 --- a/lib/jasmine-core/boot/boot.js +++ b/lib/jasmine-core/boot/boot.js @@ -62,7 +62,8 @@ */ var htmlReporter = new jasmine.HtmlReporter({ env: env, - onRaiseExceptionsClick: function() { queryString.setParam("catch", !env.catchingExceptions()); }, + onRaiseExceptionsClick: function() { queryString.navigateWithNewParam("catch", !env.catchingExceptions()); }, + addToExistingQueryString: function(key, value) { return queryString.fullStringWithNewParam(key, value); }, getContainer: function() { return document.body; }, createElement: function() { return document.createElement.apply(document, arguments); }, createTextNode: function() { return document.createTextNode.apply(document, arguments); }, diff --git a/lib/jasmine-core/jasmine-html.js b/lib/jasmine-core/jasmine-html.js index 898108b7..e4f63edc 100644 --- a/lib/jasmine-core/jasmine-html.js +++ b/lib/jasmine-core/jasmine-html.js @@ -40,6 +40,7 @@ jasmineRequire.HtmlReporter = function(j$) { createElement = options.createElement, createTextNode = options.createTextNode, onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, + addToExistingQueryString = options.addToExistingQueryString || defaultQueryString, timer = options.timer || noopTimer, results = [], specsExecuted = 0, @@ -267,7 +268,7 @@ jasmineRequire.HtmlReporter = function(j$) { function clearPrior() { // return the reporter var oldReporter = find(''); - + if(oldReporter) { getContainer().removeChild(oldReporter); } @@ -306,7 +307,11 @@ jasmineRequire.HtmlReporter = function(j$) { } function specHref(result) { - return '?spec=' + encodeURIComponent(result.fullName); + return addToExistingQueryString('spec', encodeURIComponent(result.fullName)); + } + + function defaultQueryString(key, value) { + return '?' + key + '=' + value; } function setMenuModeTo(mode) { @@ -358,10 +363,14 @@ jasmineRequire.ResultsNode = function() { jasmineRequire.QueryString = function() { function QueryString(options) { - this.setParam = function(key, value) { + this.navigateWithNewParam = function(key, value) { + options.getWindowLocation().search = this.fullStringWithNewParam(key, value); + }; + + this.fullStringWithNewParam = function(key, value) { var paramMap = queryStringToParamMap(); paramMap[key] = value; - options.getWindowLocation().search = toQueryString(paramMap); + return toQueryString(paramMap); }; this.getParam = function(key) { diff --git a/spec/html/HtmlReporterSpec.js b/spec/html/HtmlReporterSpec.js index b4f9756e..09a52161 100644 --- a/spec/html/HtmlReporterSpec.js +++ b/spec/html/HtmlReporterSpec.js @@ -278,7 +278,8 @@ describe("New HtmlReporter", function() { env: env, getContainer: getContainer, createElement: function() { return document.createElement.apply(document, arguments); }, - createTextNode: function() { return document.createTextNode.apply(document, arguments); } + createTextNode: function() { return document.createTextNode.apply(document, arguments); }, + addToExistingQueryString: function(key, value) { return "?foo=bar&" + key + "=" + value; } }); reporter.initialize(); @@ -350,7 +351,7 @@ describe("New HtmlReporter", function() { var suiteDetail = outerSuite.childNodes[0]; var suiteLink = suiteDetail.childNodes[0]; expect(suiteLink.innerHTML).toEqual("A Suite"); - expect(suiteLink.getAttribute('href')).toEqual("?spec=A%20Suite"); + expect(suiteLink.getAttribute('href')).toEqual("?foo=bar&spec=A%20Suite"); var specs = outerSuite.childNodes[1]; var spec = specs.childNodes[0]; @@ -359,7 +360,7 @@ describe("New HtmlReporter", function() { var specLink = spec.childNodes[0]; expect(specLink.innerHTML).toEqual("with a spec"); - expect(specLink.getAttribute("href")).toEqual("?spec=A%20Suite%20with%20a%20spec"); + expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=A%20Suite%20with%20a%20spec"); // expect(specLink.getAttribute("title")).toEqual("A Suite with a spec"); }); @@ -567,7 +568,8 @@ describe("New HtmlReporter", function() { env: env, getContainer: getContainer, createElement: function() { return document.createElement.apply(document, arguments); }, - createTextNode: function() { return document.createTextNode.apply(document, arguments); } + createTextNode: function() { return document.createTextNode.apply(document, arguments); }, + addToExistingQueryString: function(key, value) { return "?foo=bar&" + key + "=" + value; } }); reporter.initialize(); @@ -614,7 +616,7 @@ describe("New HtmlReporter", function() { var specLink = specDiv.childNodes[0]; expect(specLink.getAttribute("title")).toEqual("a suite with a failing spec"); - expect(specLink.getAttribute("href")).toEqual("?spec=a%20suite%20with%20a%20failing%20spec"); + expect(specLink.getAttribute("href")).toEqual("?foo=bar&spec=a%20suite%20with%20a%20failing%20spec"); var message = failure.childNodes[1].childNodes[0]; expect(message.getAttribute("class")).toEqual("result-message"); diff --git a/spec/html/QueryStringSpec.js b/spec/html/QueryStringSpec.js index d4cd691a..f68261f3 100644 --- a/spec/html/QueryStringSpec.js +++ b/spec/html/QueryStringSpec.js @@ -1,6 +1,6 @@ describe("QueryString", function() { - describe("#setParam", function() { + describe("#navigateWithNewParam", function() { it("sets the query string to include the given key/value pair", function() { var windowLocation = { search: "" @@ -9,7 +9,7 @@ describe("QueryString", function() { getWindowLocation: function() { return windowLocation } }); - queryString.setParam("foo", "bar baz"); + queryString.navigateWithNewParam("foo", "bar baz"); expect(windowLocation.search).toMatch(/foo=bar%20baz/); }); @@ -22,13 +22,29 @@ describe("QueryString", function() { getWindowLocation: function() { return windowLocation } }); - queryString.setParam("baz", "quux"); + queryString.navigateWithNewParam("baz", "quux"); expect(windowLocation.search).toMatch(/foo=bar/); expect(windowLocation.search).toMatch(/baz=quux/); }); }); + describe('#fullStringWithNewParam', function() { + it("gets the query string including the given key/value pair", function() { + var windowLocation = { + search: "?foo=bar" + }, + queryString = new j$.QueryString({ + getWindowLocation: function() { return windowLocation } + }); + + var result = queryString.fullStringWithNewParam("baz", "quux"); + + expect(result).toMatch(/foo=bar/); + expect(result).toMatch(/baz=quux/); + }); + }); + describe("#getParam", function() { it("returns the value of the requested key", function() { diff --git a/src/html/HtmlReporter.js b/src/html/HtmlReporter.js index 990cdbe0..c96b8583 100644 --- a/src/html/HtmlReporter.js +++ b/src/html/HtmlReporter.js @@ -11,6 +11,7 @@ jasmineRequire.HtmlReporter = function(j$) { createElement = options.createElement, createTextNode = options.createTextNode, onRaiseExceptionsClick = options.onRaiseExceptionsClick || function() {}, + addToExistingQueryString = options.addToExistingQueryString || defaultQueryString, timer = options.timer || noopTimer, results = [], specsExecuted = 0, @@ -238,7 +239,7 @@ jasmineRequire.HtmlReporter = function(j$) { function clearPrior() { // return the reporter var oldReporter = find(''); - + if(oldReporter) { getContainer().removeChild(oldReporter); } @@ -277,7 +278,11 @@ jasmineRequire.HtmlReporter = function(j$) { } function specHref(result) { - return '?spec=' + encodeURIComponent(result.fullName); + return addToExistingQueryString('spec', encodeURIComponent(result.fullName)); + } + + function defaultQueryString(key, value) { + return '?' + key + '=' + value; } function setMenuModeTo(mode) { diff --git a/src/html/QueryString.js b/src/html/QueryString.js index 13d6855c..a72d92d8 100644 --- a/src/html/QueryString.js +++ b/src/html/QueryString.js @@ -1,10 +1,14 @@ jasmineRequire.QueryString = function() { function QueryString(options) { - this.setParam = function(key, value) { + this.navigateWithNewParam = function(key, value) { + options.getWindowLocation().search = this.fullStringWithNewParam(key, value); + }; + + this.fullStringWithNewParam = function(key, value) { var paramMap = queryStringToParamMap(); paramMap[key] = value; - options.getWindowLocation().search = toQueryString(paramMap); + return toQueryString(paramMap); }; this.getParam = function(key) {