Skip to content

Commit

Permalink
Merge pull request #732 from aholachek/preferences
Browse files Browse the repository at this point in the history
querying link server on widget initialization instead of just listeni…
  • Loading branch information
aholachek committed Dec 30, 2015
2 parents 55eb029 + 16af396 commit 602282a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
3 changes: 3 additions & 0 deletions src/js/widgets/preferences/widget.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ define([
that.model.set("openURLConfig", config);
});

//and the user data (which contains user's open url selection)
this.model.set(this.getBeeHive().getObject("User").getUserData());

},

//translates what comes from toc widget (e.g. userPreferences__orcid) to view name
Expand Down
24 changes: 15 additions & 9 deletions test/mocha/js/widgets/preferences_widget.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ define([
};


it("should have a model that contains updated myads data and a collection of openurl endpoints", function(){

it("should initialize with correct user vals + should listen to user change events", function(){

var p = new PreferencesWidget();

Expand All @@ -49,8 +50,10 @@ define([

var fakeUser = {
getHardenedInstance : function(){return this},
getMyADSData : function() {
return fakeMyADS;
getUserData : function() {
return {
link_server : "minnesota_state.edu"
};
},
getOpenURLConfig : function(){
var d = $.Deferred();
Expand All @@ -59,7 +62,6 @@ define([

},
USER_INFO_CHANGE: User.prototype.USER_INFO_CHANGE,
getUserData : function() {return {}}
};

var fakeOrcid = {
Expand All @@ -72,8 +74,6 @@ define([

p.activate(minsub.beehive.getHardenedInstance());

minsub.publish(minsub.APP_STARTED);

expect(p.model.get("openURLConfig")).to.eql([
{
"name": "ohio wesleyan",
Expand All @@ -87,12 +87,18 @@ define([
"name": "wesleyan university",
"link": "wesleyan.edu"
}
]);
]);

expect(p.model.get("link_server")).to.eql("minnesota_state.edu");

//send new link server info in change event
minsub.publish(minsub.USER_ANNOUNCEMENT, User.prototype.USER_INFO_CHANGE, fakeMyADS);

expect(p.model.get("link_server")).to.eql("wesleyan.edu");

expect(JSON.stringify(p.model.toJSON())).to.eql('{"openURLConfig":[{"name":"ohio wesleyan","link":"ohio_wesleyan.edu"},{"name":"virginia wesleyan","link":"virginia_wesleyan.edu"},{"name":"wesleyan university","link":"wesleyan.edu"}],"link_server":"wesleyan.edu","anotherVal":"foo"}');


});

it("should show a view that allows user to set open url link server", function(){
Expand Down Expand Up @@ -349,8 +355,8 @@ define([

var fakeUser = {
getHardenedInstance : function(){return this},
getMyADSData : function() {
return fakeMyADS;
getUserData : function() {
return fakeMyADS
},
getOpenURLConfig : function() {
var d = $.Deferred();
Expand Down

0 comments on commit 602282a

Please sign in to comment.