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
+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'});
});
});
});