Improvement #6912: New achievement modal service and more achievement tests (#6943)

* add tests for beastMaster, mountMaster, and triadBingo achievements

* add tests for challengeWon, streak, ultimateGear, rebirth, and contributor achievements

* add achievement service that has openModal function

* achievement test pass again

* fix indentation, rename openModal to more descriptive displayAchievement

* add unit tests for achievements service

* initialize user.preferences.suppressModals in specHelper.newUser

* update achievement tests to account for new notification service

* add new achievementServices file to manifest.json

* fix tests

* award wonChallenge achiev like other achievs

* differentiate between small and normal achiev modals

* refactor achievementService.displayAchievement() to take options param
This commit is contained in:
Kaitlin Hipkin
2016-09-09 08:58:44 -04:00
committed by Blade Barringer
parent 31a1a14bae
commit a3f83b9076
11 changed files with 267 additions and 48 deletions
+35 -2
View File
@@ -1,7 +1,7 @@
'use strict';
describe('Inventory Controller', function() {
var scope, ctrl, user, rootScope;
var scope, ctrl, user, rootScope, shared, achievement;
beforeEach(function() {
module(function($provide) {
@@ -15,7 +15,7 @@ describe('Inventory Controller', function() {
$provide.value('$window', mockWindow);
});
inject(function($rootScope, $controller, Shared, User, $location, $window) {
inject(function($rootScope, $controller, Shared, User, $location, $window, Achievement) {
user = specHelper.newUser({
balance: 4,
items: {
@@ -32,6 +32,8 @@ describe('Inventory Controller', function() {
});
Shared.wrap(user);
shared = Shared;
achievement = Achievement;
scope = $rootScope.$new();
rootScope = $rootScope;
@@ -118,6 +120,27 @@ describe('Inventory Controller', function() {
expect(rootScope.openModal).to.not.be.called;
});
it('shows beastMaster achievement modal if user has all 90 pets', function(){
sandbox.stub(achievement, 'displayAchievement');
sandbox.stub(shared.count, "beastMasterProgress").returns(90);
scope.chooseEgg('Cactus');
scope.choosePotion('Base');
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('beastMaster');
});
it('shows triadBingo achievement modal if user has all pets twice and all mounts', function(){
sandbox.stub(achievement, 'displayAchievement');
sandbox.stub(shared.count, "mountMasterProgress").returns(90);
sandbox.stub(shared.count, "dropPetsCurrentlyOwned").returns(90);
scope.chooseEgg('Cactus');
scope.choosePotion('Base');
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('triadBingo');
});
});
describe('Feeding and Raising Pets', function() {
@@ -194,6 +217,16 @@ describe('Inventory Controller', function() {
expect(rootScope.openModal).to.have.been.calledOnce;
expect(rootScope.openModal).to.have.been.calledWith('raisePet');
});
it('shows mountMaster achievement modal if user has all 90 mounts', function(){
sandbox.stub(achievement, 'displayAchievement');
sandbox.stub(shared.count, "mountMasterProgress").returns(90);
scope.chooseFood('Meat');
scope.choosePet('PandaCub','Base');
expect(achievement.displayAchievement).to.be.calledOnce;
expect(achievement.displayAchievement).to.be.calledWith('mountMaster');
});
});
it('sells an egg', function(){
+116 -14
View File
@@ -1,33 +1,49 @@
'use strict';
describe('Notification Controller', function() {
var user, scope, rootScope, ctrl;
var user, scope, rootScope, fakeBackend, achievement, ctrl;
beforeEach(function() {
user = specHelper.newUser();
user._id = "unique-user-id";
var userSync = sinon.stub().returns({
then: function then (f) { f(); }
});
let User = {
user,
readNotification: function noop () {},
sync: userSync
};
module(function($provide) {
$provide.value('User', {user: user});
$provide.value('User', User);
$provide.value('Guide', {});
});
inject(function(_$rootScope_, _$controller_) {
inject(function(_$rootScope_, $httpBackend, _$controller_, Achievement, Shared) {
scope = _$rootScope_.$new();
rootScope = _$rootScope_;
// Load RootCtrl to ensure shared behaviors are loaded
_$controller_('RootCtrl', {$scope: scope, User: {user: user}});
fakeBackend = $httpBackend;
fakeBackend.when('GET', 'partials/main.html').respond({});
ctrl = _$controller_('NotificationCtrl', {$scope: scope, User: {user: user}});
achievement = Achievement;
Shared.wrap(user);
// Load RootCtrl to ensure shared behaviors are loaded
_$controller_('RootCtrl', {$scope: scope, User});
ctrl = _$controller_('NotificationCtrl', {$scope: scope, User});
});
sandbox.stub(rootScope, 'openModal');
sandbox.stub(achievement, 'displayAchievement');
});
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;
@@ -55,10 +71,6 @@ describe('Notification Controller', function() {
});
describe('Quest Completion modal watch', function() {
beforeEach(function() {
sandbox.stub(rootScope, 'openModal');
});
it('opens quest completion modal', function() {
user.party.quest.completed = "hedgebeast";
scope.$digest();
@@ -84,4 +96,94 @@ describe('Notification Controller', function() {
expect(rootScope.openModal).to.not.be.called;
});
});
describe('User challenge won notification watch', function() {
it('opens challenge won modal when a challenge-won notification is recieved', function() {
rootScope.$digest();
rootScope.userNotifications.push({type: 'WON_CHALLENGE'});
rootScope.$digest();
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('wonChallenge');
});
it('does not open challenge won modal if no new challenge-won notification is recieved', function() {
rootScope.$digest();
rootScope.$digest();
expect(achievement.displayAchievement).to.not.be.calledWith('wonChallenge');
});
});
describe('User streak achievement notification watch', function() {
it('opens streak achievement modal when a streak-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.userNotifications.push({type: 'STREAK_ACHIEVEMENT'});
rootScope.$digest();
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('streak', {size: 'md'});
});
it('does not open streak achievement modal if no new streak-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.$digest();
expect(achievement.displayAchievement).to.not.be.calledWith('streak', {size: 'md'});
});
});
describe('User ultimate gear set achievement notification watch', function() {
it('opens ultimate gear set achievement modal when an ultimate-gear-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.userNotifications.push({type: 'ULTIMATE_GEAR_ACHIEVEMENT'});
rootScope.$digest();
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('ultimateGear', {size: 'md'});
});
it('does not open ultimate gear set achievement modal if no new ultimate-gear-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.$digest();
expect(achievement.displayAchievement).to.not.be.calledWith('ultimateGear', {size: 'md'});
});
});
describe('User rebirth achievement notification watch', function() {
it('opens rebirth achievement modal when a rebirth-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.userNotifications.push({type: 'REBIRTH_ACHIEVEMENT'});
rootScope.$digest();
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('rebirth');
});
it('does not open rebirth achievement modal if no new rebirth-achievement notification is recieved', function() {
rootScope.$digest();
rootScope.$digest();
expect(achievement.displayAchievement).to.not.be.calledWith('rebirth');
});
});
describe('User contributor achievement notification watch', function() {
it('opens contributor achievement modal when a new-contributor-level notification is recieved', function() {
rootScope.$digest();
rootScope.userNotifications.push({type: 'NEW_CONTRIBUTOR_LEVEL'});
rootScope.$digest();
expect(achievement.displayAchievement).to.be.called;
expect(achievement.displayAchievement).to.be.calledWith('contributor', {size: 'md'});
});
it('does not open contributor achievement modal if no new new-contributor-level notification is recieved', function() {
rootScope.$digest();
rootScope.$digest();
expect(achievement.displayAchievement).to.not.be.calledWith('contributor', {size: 'md'});
});
});
});
+13 -13
View File
@@ -1,8 +1,7 @@
'use strict';
describe("Party Controller", function() {
var scope, ctrl, user, User, questsService, groups, rootScope, $controller, deferred;
var party;
var scope, ctrl, user, User, questsService, groups, achievement, rootScope, $controller, deferred, party;
beforeEach(function() {
user = specHelper.newUser(),
@@ -23,7 +22,7 @@ describe("Party Controller", function() {
$provide.value('User', User);
});
inject(function(_$rootScope_, _$controller_, Groups, Quests, _$q_){
inject(function(_$rootScope_, _$controller_, Groups, Quests, _$q_, Achievement){
rootScope = _$rootScope_;
@@ -33,6 +32,7 @@ describe("Party Controller", function() {
groups = Groups;
questsService = Quests;
achievement = Achievement;
// Load RootCtrl to ensure shared behaviors are loaded
$controller('RootCtrl', {$scope: scope, User: User});
@@ -61,7 +61,7 @@ describe("Party Controller", function() {
};
beforeEach(function() {
sandbox.stub(rootScope, 'openModal');
sandbox.stub(achievement, 'displayAchievement');
});
context('party has 1 member', function() {
@@ -71,7 +71,7 @@ describe("Party Controller", function() {
initializeControllerWithStubbedState();
expect(User.set).to.not.be.called;
expect(rootScope.openModal).to.not.be.called;
expect(achievement.displayAchievement).to.not.be.called;
});
});
@@ -87,8 +87,8 @@ describe("Party Controller", function() {
expect(User.set).to.be.calledWith(
{ 'achievements.partyUp': true }
);
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('achievements/partyUp');
expect(achievement.displayAchievement).to.be.calledOnce;
expect(achievement.displayAchievement).to.be.calledWith('partyUp');
done();
}, 1000);
});
@@ -112,8 +112,8 @@ describe("Party Controller", function() {
expect(User.set).to.be.calledWith(
{ 'achievements.partyOn': true }
);
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
expect(achievement.displayAchievement).to.be.calledOnce;
expect(achievement.displayAchievement).to.be.calledWith('partyOn');
done();
}, 1000);
});
@@ -131,9 +131,9 @@ describe("Party Controller", function() {
expect(User.set).to.be.calledWith(
{ 'achievements.partyOn': true}
);
expect(rootScope.openModal).to.have.been.called;
expect(rootScope.openModal).to.be.calledWith('achievements/partyUp');
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
expect(achievement.displayAchievement).to.have.been.called;
expect(achievement.displayAchievement).to.be.calledWith('partyUp');
expect(achievement.displayAchievement).to.be.calledWith('partyOn');
done();
}, 1000);
});
@@ -147,7 +147,7 @@ describe("Party Controller", function() {
initializeControllerWithStubbedState();
expect(User.set).to.not.be.called;
expect(rootScope.openModal).to.not.be.called;
expect(achievement.displayAchievement).to.not.be.called;
});
});
});
@@ -0,0 +1,55 @@
'use strict';
describe('achievementServices', function() {
var achievementService, rootScope;
beforeEach(function() {
rootScope = { 'openModal': sandbox.stub() };
module(function($provide) {
$provide.value('$rootScope', rootScope);
});
inject(function(Achievement) {
achievementService = Achievement;
});
});
describe('#displayAchievement', function() {
it('passes given achievement name to openModal', function() {
achievementService.displayAchievement('beastMaster');
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('achievements/beastMaster');
});
it('calls openModal with UserCtrl and small modal size if no other size is given', function() {
achievementService.displayAchievement('test');
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith(
'achievements/test',
{ controller: 'UserCtrl', size: 'sm' }
);
});
it('calls openModal with UserCtrl and specified modal size if one is given', function() {
achievementService.displayAchievement('test', {size: 'md'});
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith(
'achievements/test',
{ controller: 'UserCtrl', size: 'md' }
);
});
it('calls openModal with UserCtrl and default \'sm\' size if invalid size is given', function() {
achievementService.displayAchievement('test', {size: 'INVALID_SIZE'});
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith(
'achievements/test',
{ controller: 'UserCtrl', size: 'sm' }
);
});
});
});
+1 -1
View File
@@ -39,7 +39,7 @@ var specHelper = {};
progress: {down: 0}
}
},
preferences: {},
preferences: { suppressModals: {} },
habits: [],
dailys: [],
todos: [],