From 8c392e92a001daad517e0d7d281ae82a8cf1f559 Mon Sep 17 00:00:00 2001 From: mpl Date: Wed, 3 Jun 2015 16:52:27 +0200 Subject: [PATCH] ui/navigator: allow tests, fix navigate return, add tests 1) cam.object dep was needed for any of the tests to run 2) fixed the return logic of navigate() to match its doc. Should be of no consequence though, as afaik this return value is not used anywhere. 3) added tests for 2) Change-Id: I5c236ab95482b50437f0047d63e42603f754438d --- server/camlistored/ui/navigator.js | 5 +++-- server/camlistored/ui/navigator_test.js | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/server/camlistored/ui/navigator.js b/server/camlistored/ui/navigator.js index 19bb3adb1..84ea7823d 100644 --- a/server/camlistored/ui/navigator.js +++ b/server/camlistored/ui/navigator.js @@ -16,6 +16,7 @@ limitations under the License. goog.provide('cam.Navigator'); +goog.require('cam.object'); goog.require('goog.Uri'); // Navigator intercepts various types of browser navgiations and gives its client an opportunity to decide whether the navigation should be handled with JavaScript or not. @@ -75,10 +76,10 @@ cam.Navigator.prototype.onDidNavigate = function() {}; // @return boolean Whether the navigation was handled locally. cam.Navigator.prototype.navigate = function(url) { if (this.dispatchImpl_(url, true)) { - return false; + return true; } this.location_.href = url.toString(); - return true; + return false; }; // Handles navigations initiated via clicking a hyperlink. diff --git a/server/camlistored/ui/navigator_test.js b/server/camlistored/ui/navigator_test.js index 4da1c8c64..e8f35750c 100644 --- a/server/camlistored/ui/navigator_test.js +++ b/server/camlistored/ui/navigator_test.js @@ -70,26 +70,29 @@ describe('cam.Navigator', function() { it('#navigate - no handler', function() { // We should do network navigation. navigator.onWillNavigate = function(){}; - navigator.navigate(url); + var handledLocally = navigator.navigate(url); assert.equal(mockLocation.href, url.toString()); assert.equal(mockHistory.states.length, 1); + assert.equal(handledLocally, false); }); it('#navigate - handler returns false', function() { // Both handlers should get called, we should do network navigation. - navigator.navigate(url); + var handledLocally = navigator.navigate(url); assert.equal(handler.lastURL, url); assert.equal(mockLocation.href, url.toString()); assert.equal(mockHistory.states.length, 1); + assert.equal(handledLocally, false); }); it('#navigate - handler returns true', function() { // Both handlers should get called, we should do pushState() navigation. handler.returnsTrue = true; - navigator.navigate(url); + var handledLocally = navigator.navigate(url); assert.equal(handler.lastURL, url); assert.equal(mockLocation.href, ''); assert.deepEqual(mockHistory.states, [{state:{}, url:''}, {state:{}, url:url.toString()}]); + assert.equal(handledLocally, true); }); it('#handleClick_ - handled', function() {