From 24ef3aa0123ede27172ae5031324a62946299b04 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Thu, 9 Apr 2015 21:57:06 -0500 Subject: [PATCH 1/2] Made uuid in hall of heroes populate the input box --- test/spec/hallCtrlSpec.js | 28 +++++++++++++++++++++++ website/public/js/controllers/hallCtrl.js | 4 ++++ website/views/options/social/hall.jade | 2 +- 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/spec/hallCtrlSpec.js diff --git a/test/spec/hallCtrlSpec.js b/test/spec/hallCtrlSpec.js new file mode 100644 index 0000000000..b795024887 --- /dev/null +++ b/test/spec/hallCtrlSpec.js @@ -0,0 +1,28 @@ +'use strict'; + +describe.only('Hall of Heroes Controller', function() { + var scope, ctrl, user, $rootScope; + + beforeEach(function() { + module(function($provide) { + $provide.value('User', {}); + }); + + inject(function($rootScope, $controller){ + user = specHelper.newUser(); + user._id = "unique-user-id" + + scope = $rootScope.$new(); + + // Load RootCtrl to ensure shared behaviors are loaded + $controller('RootCtrl', {$scope: scope, User: {user: user}}); + + ctrl = $controller('HallHeroesCtrl', {$scope: scope, User: {user: user}}); + }); + }); + + it('populates contributor input with selected hero id', function(){ + scope.populateContributorInput(user._id); + expect(scope._heroID).to.eql(user._id); + }); +}); diff --git a/website/public/js/controllers/hallCtrl.js b/website/public/js/controllers/hallCtrl.js index 6956bfedd5..97aaeec1e6 100644 --- a/website/public/js/controllers/hallCtrl.js +++ b/website/public/js/controllers/hallCtrl.js @@ -17,6 +17,10 @@ habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notifica }) } $scope.heroes = Hero.query(); + + $scope.populateContributorInput = function(id) { + $scope._heroID = id; + }; }]); habitrpg.controller("HallPatronsCtrl", ['$scope', '$rootScope', 'User', 'Notification', 'ApiUrl', '$resource', diff --git a/website/views/options/social/hall.jade b/website/views/options/social/hall.jade index bf07ea0eea..cb7489a8f7 100644 --- a/website/views/options/social/hall.jade +++ b/website/views/options/social/hall.jade @@ -84,7 +84,7 @@ script(type='text/ng-template', id='partials/options.social.hall.heroes.html') span(ng-class='userAdminGlyphiconStyle(hero)') span(ng-if='!hero.contributor.admin') a.label.label-default(ng-class='userLevelStyle(hero)', ng-click='clickMember(hero._id, true)') {{hero.profile.name}} - td(ng-if='user.contributor.admin') {{hero._id}} + td(ng-if='user.contributor.admin', ng-click='populateContributorInput(hero._id)').btn-link {{hero._id}} td {{hero.contributor.level}} td {{hero.contributor.text}} td From 8642366f15ba0fee251a5e4016453305d5018292 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Fri, 10 Apr 2015 23:51:34 -0500 Subject: [PATCH 2/2] scroll to top and load hero; add tests for new behavior. --- test/spec/hallCtrlSpec.js | 8 ++++++++ website/public/js/controllers/hallCtrl.js | 2 ++ 2 files changed, 10 insertions(+) diff --git a/test/spec/hallCtrlSpec.js b/test/spec/hallCtrlSpec.js index b795024887..dce34c838a 100644 --- a/test/spec/hallCtrlSpec.js +++ b/test/spec/hallCtrlSpec.js @@ -22,7 +22,15 @@ describe.only('Hall of Heroes Controller', function() { }); it('populates contributor input with selected hero id', function(){ + var loadHero = sinon.spy(scope, "loadHero"); + var scrollTo = sinon.spy(window, "scrollTo"); + scope.populateContributorInput(user._id); expect(scope._heroID).to.eql(user._id); + expect(loadHero.callCount).to.eql(1); + expect(scrollTo.callCount).to.eql(1); + + scope.loadHero.restore(); + window.scrollTo.restore(); }); }); diff --git a/website/public/js/controllers/hallCtrl.js b/website/public/js/controllers/hallCtrl.js index 97aaeec1e6..fe385a316c 100644 --- a/website/public/js/controllers/hallCtrl.js +++ b/website/public/js/controllers/hallCtrl.js @@ -20,6 +20,8 @@ habitrpg.controller("HallHeroesCtrl", ['$scope', '$rootScope', 'User', 'Notifica $scope.populateContributorInput = function(id) { $scope._heroID = id; + window.scrollTo(0,200); + $scope.loadHero(id); }; }]);