From 4fc04fea24889d3550cfb01f508466ff56c5ad40 Mon Sep 17 00:00:00 2001 From: Blade Barringer Date: Sat, 20 Jun 2015 21:10:18 -0500 Subject: [PATCH] Adjustments to PR #5298 * Put watch on $scope * Check for quest.completed !== true or false * Add test for quest invite modal watch --- test/spec/controllers/notificationCtrlSpec.js | 64 +++++++++++++++++++ .../public/js/controllers/notificationCtrl.js | 2 +- 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 test/spec/controllers/notificationCtrlSpec.js diff --git a/test/spec/controllers/notificationCtrlSpec.js b/test/spec/controllers/notificationCtrlSpec.js new file mode 100644 index 0000000000..9d53e7946a --- /dev/null +++ b/test/spec/controllers/notificationCtrlSpec.js @@ -0,0 +1,64 @@ +'use strict'; + +describe('Notification Controller', function() { + var user, scope, rootScope, ctrl; + + beforeEach(function() { + user = specHelper.newUser(); + user._id = "unique-user-id"; + + module(function($provide) { + $provide.value('User', {user: user}); + $provide.value('Guide', {}); + }); + + inject(function(_$rootScope_, _$controller_) { + scope = _$rootScope_.$new(); + rootScope = _$rootScope_; + + // Load RootCtrl to ensure shared behaviors are loaded + _$controller_('RootCtrl', {$scope: scope, User: {user: user}}); + + ctrl = _$controller_('NotificationCtrl', {$scope: scope, User: {user: user}}); + }); + }); + + describe('Quest Invitation modal watch', function() { + beforeEach(function() { + sandbox.stub(rootScope, 'openModal'); + }); + + it('opens quest invitation modal', function() { + user.party.quest.RSVPNeeded = true; + delete user.party.quest.completed; + scope.$digest(); + + expect(rootScope.openModal).to.be.calledOnce; + expect(rootScope.openModal).to.be.calledWith('questInvitation', {controller:'PartyCtrl'}); + }); + + it('does not open quest invitation modal if RSVPNeeded is not true', function() { + user.party.quest.RSVPNeeded = false; + user.party.quest.completed = false; + scope.$digest(); + + expect(rootScope.openModal).to.not.be.called; + }); + + it('does not open quest invitation modal if quest completed is set to false', function() { + user.party.quest.RSVPNeeded = true; + user.party.quest.completed = false; + scope.$digest(); + + expect(rootScope.openModal).to.not.be.called; + }); + + it('does not open quest invitation modal if quest completed is set to true', function() { + user.party.quest.RSVPNeeded = true; + user.party.quest.completed = true; + scope.$digest(); + + expect(rootScope.openModal).to.not.be.called; + }); + }); +}); diff --git a/website/public/js/controllers/notificationCtrl.js b/website/public/js/controllers/notificationCtrl.js index 307ae676f3..1d1be29443 100644 --- a/website/public/js/controllers/notificationCtrl.js +++ b/website/public/js/controllers/notificationCtrl.js @@ -154,7 +154,7 @@ habitrpg.controller('NotificationCtrl', }); // Quest invitation modal - $rootScope.$watch('user.party.quest.RSVPNeeded && (user.party.quest.completed == "" || user.party.quest.completed == undefined)', function(after, before){ + $scope.$watch('user.party.quest.RSVPNeeded && (user.party.quest.completed !== false && user.party.quest.completed !== true)', function(after, before){ if (after != true) return; $rootScope.openModal('questInvitation', {controller:'PartyCtrl'}); });