diff --git a/common-patterns.txt b/common-patterns.txt new file mode 100644 index 000000000..fcd850455 --- /dev/null +++ b/common-patterns.txt @@ -0,0 +1,10 @@ + +//widget can publish an alert + +var pubsub = that.getBeeHive().getPubSub(); + pubsub.publish(pubsub.ALERT, new ApiFeedback({ + code: ApiFeedback.CODES.ALERT, + msg: "Logged in to ADS", + type: "success", + modal : true + })); \ No newline at end of file diff --git a/src/discovery.config.js b/src/discovery.config.js index f6f81fa36..257d484af 100644 --- a/src/discovery.config.js +++ b/src/discovery.config.js @@ -41,19 +41,19 @@ require.config({ QueryMediator: 'js/components/query_mediator', Diagnostics: 'js/bugutils/diagnostics', AlertsController: 'js/wraps/alerts_mediator', - Orcid: 'js/modules/orcid/module' + Orcid: 'js/modules/orcid/module', }, services: { Api: 'js/services/api', PubSub: 'js/services/pubsub', Navigator: 'js/apps/discovery/navigator', - PersistentStorage: 'js/services/storage' + PersistentStorage: 'js/services/storage', + HistoryManager: 'js/components/history_manager', }, objects: { User: 'js/components/user', Session: 'js/components/session', DynamicConfig: 'discovery.vars', - HistoryManager: 'js/components/history_manager', MasterPageManager: 'js/page_managers/master', AppStorage: 'js/components/app_storage', RecaptchaManager : 'js/components/recaptcha_manager', diff --git a/src/js/apps/discovery/main.js b/src/js/apps/discovery/main.js index 04a28e493..9e9709635 100644 --- a/src/js/apps/discovery/main.js +++ b/src/js/apps/discovery/main.js @@ -22,7 +22,8 @@ define(['config', 'module'], function(config, module) { 'js/mixins/api_access', 'es5-shim' ], - function(Router, + function( + Router, Application, DiscoveryBootstrap, ApiAccess diff --git a/src/js/apps/discovery/navigator.js b/src/js/apps/discovery/navigator.js index fe12cad77..374e73bb6 100644 --- a/src/js/apps/discovery/navigator.js +++ b/src/js/apps/discovery/navigator.js @@ -410,10 +410,11 @@ define([ } }); - this.set('results-page', function() { + this.set('results-page', function(widget, args) { app.getObject('MasterPageManager').show('SearchPage', searchPageAlwaysVisible); + //allowing widgets to override appstorage query (so far only used for orcid redirect) var q = app.getObject('AppStorage').getCurrentQuery(); var route = '#search/' + queryUpdater.clean(q).url(); diff --git a/src/js/apps/discovery/router.js b/src/js/apps/discovery/router.js index e9d8ac79b..ea45ec9ef 100644 --- a/src/js/apps/discovery/router.js +++ b/src/js/apps/discovery/router.js @@ -29,7 +29,6 @@ define([ initialize : function(options){ options = options || {}; - this.history = options.history; this.queryUpdater = new ApiQueryUpdater('Router'); }, @@ -91,7 +90,6 @@ define([ paperForm : function(){ this.routerNavigate('PaperSearchForm'); - }, search: function (query, widgetName) { diff --git a/src/js/components/app_storage.js b/src/js/components/app_storage.js index a131d7f75..5b0896052 100644 --- a/src/js/components/app_storage.js +++ b/src/js/components/app_storage.js @@ -20,11 +20,17 @@ define([ var AppStorage = Backbone.Model.extend({ activate: function(beehive) { + var that = this; this.setBeeHive(beehive); _.bindAll(this, "onPaperSelection", "onBulkPaperSelection"); var pubsub = this.getPubSub(); pubsub.subscribe(pubsub.PAPER_SELECTION, this.onPaperSelection); pubsub.subscribe(pubsub.BULK_PAPER_SELECTION, this.onBulkPaperSelection); + //see if we can load an api query from app storage + if (this.getBeeHive().getService("PersistentStorage")){ + var stashedQuery = this.getBeeHive().getService("PersistentStorage").get("currentQuery"); + this.setCurrentQuery(new ApiQuery(stashedQuery)); + } }, initialize: function() { @@ -49,6 +55,9 @@ define([ throw new Error('You must save ApiQuery instance'); } this.set('currentQuery', apiQuery); + //save to storage + if (this.getBeeHive().getService("PersistentStorage")) + this.getBeeHive().getService("PersistentStorage").set("currentQuery", apiQuery.toJSON()); }, setCurrentNumFound : function(numFound){ @@ -163,11 +172,12 @@ define([ //this is used when authentication requires an interruption in user flow //stashedPage val should be the name of a navigate command + //should by called with 1 param: an array of args used for pubsub.navigate command - setStashedNav : function(){ + setStashedNav : function(pageInstructions){ var storage = this.getBeeHive().getService('PersistentStorage'); if (storage){ - storage.set("stashedNavArgs", [].slice.apply(arguments)); + storage.set("stashedNavArgs", pageInstructions); } else { console.warn("no persistent storage service available"); @@ -179,6 +189,11 @@ define([ if (storage){ var args = storage.get("stashedNavArgs"); if (!args) return false; + //it's a results page, so initiate a start search + if (args[0] == "results-page" && this.getCurrentQuery()){ + //this feels hackish, but only easy way to run the stored query + this.getPubSub().publish(this.getPubSub().START_SEARCH, this.getCurrentQuery()); + } this.getPubSub().publish.apply(this.getPubSub(), [this.getPubSub().NAVIGATE].concat(args)); storage.remove("stashedNavArgs"); return true; diff --git a/src/js/components/history_manager.js b/src/js/components/history_manager.js index 43bf86026..5ffa67b61 100644 --- a/src/js/components/history_manager.js +++ b/src/js/components/history_manager.js @@ -1,92 +1,52 @@ -define(["underscore"], function (_) { - var HistoryManager = function () { - this.history = [] - } +define([ + 'js/components/generic_module', + 'js/mixins/dependon', + 'js/mixins/hardened', + 'js/components/pubsub_key' + ], + function( + GenericModule, + Dependon, + Hardened, + PubSubKey + ) { - _.extend(HistoryManager.prototype, { + var History = GenericModule.extend({ + initialize: function () { + this._history = []; + }, - /* - * This will return the prior PAGE--so the history entry before the current - * one. If you are on the abstract page and were on the results page before that, - * that is what will be returned. Even if you have been on several routes within - * the abstract page, these will be ignored and you will be given the - * actual page name. - * - * */ - getPriorPage : function () { + activate: function (beehive) { - if (this.history.length <=1){ - return undefined - } - var currentPage, p, priorPage; + this.setBeeHive(beehive); + var pubsub = this.getPubSub(); + pubsub.subscribe(pubsub.NAVIGATE, _.bind(this.recordNav, this)); - currentPage = _.last(this.history).page; - //first, simplify the dict to include only pages, not subpages - p = 1; - while (p < this.history.length){ + }, - priorPage = this.history[(this.history.length -1) -p].page + recordNav: function () { + this._history.push([].slice.apply(arguments)); + }, - if (priorPage !== currentPage){ - return priorPage - } - p+=1 - - } - //nothing was found that differs from currentPage - return undefined - }, - getPriorPageVal : function () { - - if (this.history.length <=1){ - return undefined - } + getCurrentNav : function(){ + return this._history[this._history.length-1]; + }, - var currentPage, p, prior, priorPage; + getPreviousNav: function(){ + return this._history[this._history.length-2]; + }, - currentPage = _.last(this.history).page; - //first, simplify the dict to include only pages, not subpages - p = 1; - - while (p < this.history.length){ - prior= this.history[(this.history.length -1) -p] - priorPage = prior.page - - if (priorPage !== currentPage){ - return prior.data + hardenedInterface: { + getPreviousNav : "", + getCurrentNav : "", } - p+=1 - } - return undefined - }, - - /* - * Unlike get prior page, this will give you whatever the prior - * route was, even if it was within the current page. - * */ - - getPriorRoute : function(){ - - var subPage = this.history[this.history.length -1].subPage; - var page = this.history[this.history.length -1].page; - - return {page: page, subPage : subPage} - }, - - getPriorRouteVal : function(){ - - return this.history[this.history.length -1].data - - }, + }); - addEntry : function (item) { - this.history.push(item) - } - }) + _.extend(History.prototype, Dependon.BeeHive, Hardened); - return HistoryManager + return History; -}) +}); diff --git a/src/js/components/session.js b/src/js/components/session.js index db4228a52..eaddb31cc 100644 --- a/src/js/components/session.js +++ b/src/js/components/session.js @@ -44,7 +44,6 @@ define([ var options = options || {}; //right now, this will only be used if someone forgot their password this.model = new SessionModel(); - this.test = options.test ? true : undefined; _.bindAll(this, [ @@ -68,6 +67,9 @@ define([ login: function (data) { + var d = $.Deferred(), + that = this; + this.sendRequestWithNewCSRF(function(csrfToken){ var request = new ApiRequest({ target : ApiTargets.USER, @@ -77,16 +79,24 @@ define([ data: JSON.stringify(data), contentType : "application/json", headers : {'X-CSRFToken' : csrfToken }, - done : this.loginSuccess, - fail : this.loginFail, + done : function(){ + //allow widgets to listen for success or failure + d.resolve.apply(arguments); + //session response to success + that.loginSuccess.apply(arguments); + }, + fail : function(){ + d.reject.apply(arguments); + that.loginFail.apply(arguments); + }, beforeSend: function(jqXHR, settings) { jqXHR.session = this; } } }); return this.getBeeHive().getService("Api").request(request); - }); + return d.promise(); }, /* @@ -200,9 +210,6 @@ define([ //reset auth token by contacting Bootstrap, which will log user in var that = this; this.getApiAccess({reconnect: true}).done(function(){ - //user has just authenticated themselves using the form, so redirect them to their account - var pubsub = that.getPubSub(); - pubsub.publish(pubsub.NAVIGATE, "UserPreferences"); }); }, diff --git a/src/js/components/user.js b/src/js/components/user.js index 409be8e92..c91a85a53 100644 --- a/src/js/components/user.js +++ b/src/js/components/user.js @@ -283,8 +283,12 @@ define([ redirectIfNecessary : function(){ var pubsub = this.getPubSub(); + + //redirect user to wherever they were before authentication page if (this.getBeeHive().getObject("MasterPageManager").currentChild === "AuthenticationPage" && this.isLoggedIn()){ - pubsub.publish(pubsub.NAVIGATE, "index-page"); + //so that navigator can redirect to the proper page + var previousNav = this.getBeeHive().getService("HistoryManager").getPreviousNav(); + pubsub.publish.apply(pubsub, [pubsub.NAVIGATE].concat(previousNav)); } else if (this.getBeeHive().getObject("MasterPageManager").currentChild === "SettingsPage" && !this.isLoggedIn()){ pubsub.publish(pubsub.NAVIGATE, "authentication-page"); @@ -311,11 +315,8 @@ define([ //this function is called immediately after the logout is confirmed completeLogOut : function(){ this.userModel.clear(); - //navigate to the index page - this.getPubSub().publish(this.getPubSub().NAVIGATE, "index-page"); }, - // publicly accessible deleteAccount : function(){ diff --git a/src/js/modules/orcid/orcid_api.js b/src/js/modules/orcid/orcid_api.js index 94da97206..1a05f91f0 100644 --- a/src/js/modules/orcid/orcid_api.js +++ b/src/js/modules/orcid/orcid_api.js @@ -152,6 +152,11 @@ define([ + "&redirect_uri=" + encodeURIComponent(this.config.redirectUrlBase + (targetRoute || '/#/user/orcid')) }); + //make sure to redirect to the proper page after sign in + this.getPubSub().publish(this.getPubSub().ORCID_ANNOUNCEMENT, "login"); + var currentPage = this.getBeeHive().getService("HistoryManager").getCurrentNav(); + this.getBeeHive().getObject("AppStorage").setStashedNav(currentPage); + }, /* @@ -215,6 +220,7 @@ define([ */ signOut: function () { this.saveAccessData(null); + this.getPubSub().publish(this.getPubSub().ORCID_ANNOUNCEMENT, "logout"); }, hasExchangeCode: function (searchString) { diff --git a/src/js/widgets/authentication/widget.js b/src/js/widgets/authentication/widget.js index 119e1cc84..fbdfbaecf 100644 --- a/src/js/widgets/authentication/widget.js +++ b/src/js/widgets/authentication/widget.js @@ -1,6 +1,7 @@ define([ 'marionette', 'js/widgets/base/base_widget', + 'js/components/api_feedback', 'js/mixins/form_view_functions', 'js/widgets/success/view', 'js/components/api_targets', @@ -16,6 +17,7 @@ define([ ], function (Marionette, BaseWidget, + ApiFeedback, FormFunctions, SuccessView, ApiTargets, @@ -461,7 +463,8 @@ define([ triggerCorrectSubmit : function(model) { - var data = model.toJSON(); + var data = model.toJSON(), + that = this; if (model.target == "REGISTER"){ @@ -471,7 +474,21 @@ define([ } else if (model.target == "USER"){ - this.getBeeHive().getObject("Session").login(model.toJSON()); + + //only show success message if login initiated from auth widget + //(if you showed it every time user logged in, you'd show it + //redundantly on start up of bumblebee) + this.getBeeHive().getObject("Session").login(model.toJSON()).done(function(){ + //this currently doesnt work with the way the alerts widget hides itself + //after navigate + //var pubsub = that.getPubSub(); + //pubsub.publish(pubsub.ALERT, new ApiFeedback({ + // code: ApiFeedback.CODES.ALERT, + // msg: "Logged in to ADS", + // type: "success", + //})); + }); + } else if (model.target == "RESET_PASSWORD" && model.method === "POST"){ diff --git a/src/js/widgets/navbar/widget.js b/src/js/widgets/navbar/widget.js index f8c149877..d271d5a26 100644 --- a/src/js/widgets/navbar/widget.js +++ b/src/js/widgets/navbar/widget.js @@ -56,17 +56,18 @@ define([ this.trigger("navigate-to-orcid-link") }, "click .orcid-logout": function (e) { - this.trigger("logout-only-orcid"); e.preventDefault(); + this.trigger("logout-only-orcid"); }, - "click .logout": function () { - this.trigger("logout") + "click .logout": function (e) { + e.preventDefault(); + this.trigger("logout"); }, "click .login": function () { - this.trigger("navigate-login") + this.trigger("navigate-login"); }, "click .register": function () { - this.trigger("navigate-register") + this.trigger("navigate-register"); }, "click button.search-author-name": function (e) { this.trigger('search-author'); @@ -242,7 +243,7 @@ define([ _navigate: function (page, opts) { var pubsub = this.getPubSub(); - pubsub.publish(pubsub.NAVIGATE, page, opts) + pubsub.publish(pubsub.NAVIGATE, page, opts); }, //to set the correct initial values for signed in statuses diff --git a/src/js/widgets/preferences/views/openurl.js b/src/js/widgets/preferences/views/openurl.js index 3502dae67..60ca6005d 100644 --- a/src/js/widgets/preferences/views/openurl.js +++ b/src/js/widgets/preferences/views/openurl.js @@ -31,12 +31,13 @@ define([ var current = _.findWhere(data.openURLConfig, {link : data.link_server}); data.openURLName = current ? current.name : ""; + return data; - return data }, modelEvents : { - "change" : "render" + "change:link_server" : "render", + "change:openURLConfig" : "render" }, events : { diff --git a/src/js/widgets/preferences/widget.js b/src/js/widgets/preferences/widget.js index 100328393..55dfc0c5d 100644 --- a/src/js/widgets/preferences/widget.js +++ b/src/js/widgets/preferences/widget.js @@ -19,7 +19,7 @@ define([ defaults : function(){ return { openURLConfig : undefined, - OrcidLoggedIn : undefined + orcidLoggedIn : undefined } } @@ -76,6 +76,7 @@ define([ _.bindAll(this); var pubsub = beehive.getService('PubSub'); pubsub.subscribe(pubsub.USER_ANNOUNCEMENT, this.handleUserAnnouncement); + pubsub.subscribe(pubsub.ORCID_ANNOUNCEMENT, this.handleOrcidAnnouncement); //as soon as preferences widget is activated, get the open url config this.getBeeHive().getObject("User").getOpenURLConfig().done(function (config) { @@ -145,7 +146,6 @@ define([ } else if (event === "orcid-authenticate"){ - this.getBeeHive().getObject("AppStorage").setStashedNav("UserPreferences", {subView: "orcid"}); this.getBeeHive().getService("OrcidApi").signIn(); } @@ -181,6 +181,17 @@ define([ if (event == user.USER_INFO_CHANGE) { this.model.set(data); } + }, + + handleOrcidAnnouncement: function (event) { + //update the user model if it changes + if (event === "login") { + this.model.set("orcidLoggedIn", false); + + } + else if (event === "logout"){ + this.model.set("orcidLoggedIn", false); + } } }); diff --git a/src/styles/sass/ads-sass/bootstrap-variables.scss b/src/styles/sass/ads-sass/bootstrap-variables.scss index 04d01c3cf..ef3d691eb 100644 --- a/src/styles/sass/ads-sass/bootstrap-variables.scss +++ b/src/styles/sass/ads-sass/bootstrap-variables.scss @@ -288,7 +288,8 @@ $screen-phone: $screen-xs-min !default; // Small screen / tablet //** Deprecated `$screen-sm` as of v3.0.1 -$screen-sm: 768px !default; +// alex: i added +20 px +$screen-sm: 788px !default; $screen-sm-min: $screen-sm !default; //** Deprecated `$screen-tablet` as of v3.0.1 $screen-tablet: $screen-sm-min !default; diff --git a/test/mocha/js/components/app_storage.spec.js b/test/mocha/js/components/app_storage.spec.js index 1ba9ee528..c7904f5d9 100644 --- a/test/mocha/js/components/app_storage.spec.js +++ b/test/mocha/js/components/app_storage.spec.js @@ -17,6 +17,15 @@ define([ it("query related funcs", function () { var s = new AppStorage(); + var minsub = new MinimalPubsub(); + var fakePersistentStorage = { + //persistent storage returns jsonified api-query + get : sinon.spy(function(arg){if (arg == "currentQuery"){return {q : "planet"}}}), + set : sinon.spy(function(){}), + getHardenedInstance : function(){return this} + }; + minsub.beehive.addService("PersistentStorage", fakePersistentStorage); + s.activate(minsub.beehive); expect(s.getCurrentQuery).to.be.defined; s.setCurrentQuery(new ApiQuery({q: 'foo'})); @@ -91,34 +100,50 @@ define([ it("can stash previous page for redirection purposes", function(){ + var s = new AppStorage(); var minsub = new MinimalPubsub(); var fakeStorage = { - set : sinon.spy(), - get : sinon.spy(function(){ - return { - stashedNavArgs : ["UserPreferences", "orcid"] + //persistent storage returns jsonified api-query + get : sinon.spy(function(arg){ + if (arg == "currentQuery"){ + return {q : "planet"} + } + else if (arg === "stashedNavArgs"){ + return { + stashedNavArgs : ["UserPreferences", "orcid"] + } } }), - remove : sinon.spy() - } - - + set : sinon.spy(function(){}), + remove : sinon.spy(function(){}), + getHardenedInstance : function(){return this} + }; minsub.beehive.addService("PersistentStorage", fakeStorage); - s.activate(minsub.beehive); s.setStashedNav("UserPreferences", "orcid"); - expect(fakeStorage.set.callCount).to.eql(1); + expect(fakeStorage.set.callCount).to.eql(2); + expect(fakeStorage.set.args[0]).to.eql([ + "currentQuery", + { + "q": [ + "planet" + ] + } + ]); + + expect(fakeStorage.set.args[1]).to.eql(["stashedNavArgs", "UserPreferences"]); s.getPubSub().publish = sinon.spy(); + expect(fakeStorage.get.callCount).to.eql(1); + s.executeStashedNav("UserPreferences", "orcid"); - expect(fakeStorage.set.callCount).to.eql(1); - expect(fakeStorage.get.callCount).to.eql(1); + expect(fakeStorage.get.callCount).to.eql(2); expect(s.getPubSub().publish.callCount).to.eql(1); @@ -132,6 +157,8 @@ define([ } ]); + expect(fakeStorage.remove.calledWith("stashedNavArgs")).to.be.true; + diff --git a/test/mocha/js/components/history_manager.spec.js b/test/mocha/js/components/history_manager.spec.js index 17169bafd..0238568d0 100644 --- a/test/mocha/js/components/history_manager.spec.js +++ b/test/mocha/js/components/history_manager.spec.js @@ -1,37 +1,37 @@ -define(['js/components/history_manager'], function(HistoryManager){ +define([ + "js/bugutils/minimal_pubsub", + 'js/components/history_manager' +], + function( + Minsub, + HistoryManager + ){ describe("History Manager (Component)", function(){ - var manager; + it("should record navigation signals and allow the previous and penultimate nav events to be queried", function(){ - beforeEach(function(){ + var manager = new HistoryManager(); - manager = new HistoryManager(); + var minsub = new (Minsub.extend({ + request: function(apiRequest) { + return {some: 'foo'} + } + }))({verbose: false}); - }) + manager.activate(minsub.beehive.getHardenedInstance()); - it("should return the prior page (rather than prior route) using its getPriorPage function", function(){ + minsub.publish(minsub.NAVIGATE, "index-page"); - manager.addEntry({page: "landingPage", data: "fakeQuery", subPage: undefined}); - manager.addEntry({page: "resultsPage", data: "fakeQuery", subPage: undefined}); - manager.addEntry({page: "abstractPage", data: "fakeBibcode", subPage: "subPage2"}); - manager.addEntry({page: "abstractPage", data: "fakeBibcode", subPage: "subPage1"}); + minsub.publish(minsub.NAVIGATE, "results-page"); - expect(manager.getPriorPage()).to.eql("resultsPage"); + expect(JSON.stringify(manager.getCurrentNav())).to.eql('["results-page",{}]'); + expect(JSON.stringify(manager.getPreviousNav())).to.eql('["index-page",{}]'); - }) - it("should return the prior page's data value using its getPriorPageVal function", function(){ - - manager.addEntry({page: "landingPage", data: "fakeQuery", subPage: undefined}); - manager.addEntry({page: "resultsPage", data: "fakeQuery", subPage: undefined}); - manager.addEntry({page: "abstractPage", data: "fakeBibcode", subPage: "subPage2"}); - manager.addEntry({page: "abstractPage", data: "fakeBibcode", subPage: "subPage1"}); - - expect(manager.getPriorPageVal()).to.eql("fakeQuery"); - }); + }) }) }); \ No newline at end of file diff --git a/test/mocha/js/components/session.spec.js b/test/mocha/js/components/session.spec.js index 9e64aa33c..08ab20a6c 100644 --- a/test/mocha/js/components/session.spec.js +++ b/test/mocha/js/components/session.spec.js @@ -60,8 +60,8 @@ define([ expect(requestStub.args[0][0].toJSON().target).to.eql("accounts/user"); expect(requestStub.args[0][0].toJSON().options.type).to.eql("POST"); expect(requestStub.args[0][0].toJSON().options.data).to.eql('{"username":"goo","password":"foo","g-recaptcha-response":"boo"}'); - expect(requestStub.args[0][0].toJSON().options.done).to.eql(s.loginSuccess); - expect(requestStub.args[0][0].toJSON().options.fail).to.eql(s.loginFail); + + s.logout(); @@ -181,8 +181,6 @@ define([ expect(s.getApiAccess.callCount).to.eql(1); //called once getApiAccess is resolved - expect(s.getPubSub().publish.args[0]).to.eql(["[Router]-Navigate-With-Trigger", "UserPreferences"]); - s.logoutSuccess(); @@ -190,13 +188,13 @@ define([ expect(u.completeLogOut.callCount).to.eql(1); s.registerSuccess(); - expect(s.getPubSub().publish.args[1]).to.eql(["[PubSub]-User-Announcement", "register_success"]); + expect(s.getPubSub().publish.args[0]).to.eql(["[PubSub]-User-Announcement", "register_success"]); s.resetPassword1Success(); - expect(s.getPubSub().publish.args[2]).to.eql(["[PubSub]-User-Announcement", "reset_password_1_success"]); + expect(s.getPubSub().publish.args[1]).to.eql(["[PubSub]-User-Announcement", "reset_password_1_success"]); s.resetPassword2Success(); - expect(s.getPubSub().publish.args[3]).to.eql(["[PubSub]-User-Announcement", "reset_password_2_success"]); + expect(s.getPubSub().publish.args[2]).to.eql(["[PubSub]-User-Announcement", "reset_password_2_success"]); }); diff --git a/test/mocha/js/modules/orcid/orcid_api.spec.js b/test/mocha/js/modules/orcid/orcid_api.spec.js index bcb45198f..357946c0e 100644 --- a/test/mocha/js/modules/orcid/orcid_api.spec.js +++ b/test/mocha/js/modules/orcid/orcid_api.spec.js @@ -64,6 +64,26 @@ define([ orcidRedirectUrlBase: 'http://localhost:8000', orcidLoginEndpoint: 'https://api.orcid.org/oauth/authorize' }); + + var fakeHistoryManager = { + getCurrentNav : function(){ + return "index-page"; + }, + getHardenedInstance : function(){return this} + }; + + var fakeAppStorage = { + getHardenedInstance: function () { + return this + }, + setStashedNav : sinon.spy() + }; + + + beehive.addService("HistoryManager", fakeHistoryManager); + beehive.addObject("AppStorage", fakeAppStorage); + + var oModule = new OrcidModule(); oModule.activate(beehive); return beehive.getService('OrcidApi'); @@ -75,6 +95,7 @@ define([ minsub.subscribe(minsub.APP_EXIT, spy); oApi.signIn(); expect(spy.called).to.eql(true); + expect(minsub.beehive.getObject("AppStorage").setStashedNav.calledWith("index-page")).to.be.true; expect(spy.lastCall.args[0]).to.eql({ url: "https://api.orcid.org/oauth/authorize?scope=/orcid-profile/read-limited%20/orcid-works/create%20/orcid-works/update&response_type=code&access_type=offline&show_login=true&client_id=APP-P5ANJTQRRTMA6GXZ&redirect_uri=http%3A%2F%2Flocalhost%3A8000%2F%23%2Fuser%2Forcid", type: 'orcid' diff --git a/test/mocha/js/widgets/preferences_widget.spec.js b/test/mocha/js/widgets/preferences_widget.spec.js index 9b83133e3..36e7710f7 100644 --- a/test/mocha/js/widgets/preferences_widget.spec.js +++ b/test/mocha/js/widgets/preferences_widget.spec.js @@ -378,16 +378,6 @@ define([ $("button.orcid-authenticate").click(); expect(fakeOrcid.signIn.callCount).to.eql(1); - expect(fakeAppStorage.setStashedNav.args[0]).to.eql([ - "UserPreferences", - { - "subView": "orcid" - } - ]); - - - - });