Pull in client side changes for quest routes

This commit is contained in:
Blade Barringer
2015-09-15 09:32:24 -05:00
parent 38e07246da
commit b32e521c56
9 changed files with 620 additions and 292 deletions

View File

@@ -157,6 +157,72 @@ describe('Inventory Controller', function() {
});
});
describe('#buyQuest', function() {
var quests, questObject;
beforeEach(inject(function(Quests) {
quests = Quests;
questObject = { key: 'whale' };
sandbox.stub(quests, 'buyQuest').returns({ then: function(res) { res(questObject); } });
}));
it('calls Quests.buyQuest', function() {
scope.buyQuest('foo');
expect(quests.buyQuest).to.be.calledOnce;
expect(quests.buyQuest).to.be.calledWith('foo');
});
it('sets selectedQuest to resolved quest object', function() {
scope.buyQuest('whale');
expect(rootScope.selectedQuest).to.eql(questObject);
});
it('opens buyQuest modal', function() {
sandbox.spy(rootScope, 'openModal');
scope.buyQuest('whale');
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('buyQuest', {controller: 'InventoryCtrl'});
});
});
describe('#showQuest', function() {
var quests, questObject;
beforeEach(inject(function(Quests) {
quests = Quests;
questObject = { key: 'whale' };
sandbox.stub(quests, 'showQuest').returns({ then: function(res) { res(questObject); } });
}));
it('calls Quests.showQuest', function() {
scope.showQuest('foo');
expect(quests.showQuest).to.be.calledOnce;
expect(quests.showQuest).to.be.calledWith('foo');
});
it('sets selectedQuest to resolved quest object', function() {
scope.showQuest('whale');
expect(rootScope.selectedQuest).to.eql(questObject);
});
it('opens showQuest modal', function() {
sandbox.spy(rootScope, 'openModal');
scope.showQuest('whale');
expect(rootScope.openModal).to.be.calledOnce;
expect(rootScope.openModal).to.be.calledWith('showQuest', {controller: 'InventoryCtrl'});
});
});
describe('#hasAllTimeTravelerItems', function() {
it('returns false if there are items left in the time traveler store', function() {
expect(scope.hasAllTimeTravelerItems()).to.eql(false);

View File

@@ -1,7 +1,7 @@
'use strict';
describe("Party Controller", function() {
var scope, ctrl, user, User, groups, rootScope, $controller;
var scope, ctrl, user, User, questsService, groups, rootScope, $controller;
beforeEach(function() {
user = specHelper.newUser(),
@@ -15,7 +15,7 @@ describe("Party Controller", function() {
$provide.value('User', User);
});
inject(function(_$rootScope_, _$controller_, Groups){
inject(function(_$rootScope_, _$controller_, Groups, Quests){
rootScope = _$rootScope_;
@@ -24,6 +24,7 @@ describe("Party Controller", function() {
$controller = _$controller_;
groups = Groups;
questsService = Quests;
// Load RootCtrl to ensure shared behaviors are loaded
$controller('RootCtrl', {$scope: scope, User: User});
@@ -33,129 +34,180 @@ describe("Party Controller", function() {
});
describe('questAccept', function() {
it('calls Groups.questAccept', function() {
var party = {};
var groupSpy = sandbox.stub(groups, "questAccept", function(){return true;});
scope.questAccept(party);
groupSpy.should.have.been.calledOnce;
beforeEach(function() {
scope.group = {
quest: { members: { 'user-id': true } }
};
sandbox.stub(questsService, 'sendAction').returns({
then: sandbox.stub().yields({members: {another: true}})
});
});
it('calls Quests.sendAction', function() {
scope.questAccept();
expect(questsService.sendAction).to.be.calledOnce;
expect(questsService.sendAction).to.be.calledWith('questAccept');
});
it('updates quest object with new participants list', function() {
scope.group.quest = {
members: { user: true, another: true }
};
scope.questAccept();
expect(scope.group.quest).to.eql({members: { another: true }});
});
});
describe('questReject', function() {
it('calls Groups.questReject', function() {
var party = {};
var groupSpy = sandbox.stub(groups, "questReject", function(){return true;});
scope.questReject(party);
groupSpy.should.have.been.calledOnce;
beforeEach(function() {
scope.group = {
quest: { members: { 'user-id': true } }
};
sandbox.stub(questsService, 'sendAction').returns({
then: sandbox.stub().yields({members: {another: true}})
});
});
it('calls Quests.sendAction', function() {
scope.questReject();
expect(questsService.sendAction).to.be.calledOnce;
expect(questsService.sendAction).to.be.calledWith('questReject');
});
it('updates quest object with new participants list', function() {
scope.group.quest = {
members: { user: true, another: true }
};
scope.questReject();
expect(scope.group.quest).to.eql({members: { another: true }});
});
});
describe('questCancel', function() {
var party, cancelSpy, windowSpy;
beforeEach(function() {
party = {};
cancelSpy = sandbox.stub(groups, "questCancel", function(){return true;});
sandbox.stub(questsService, 'sendAction').returns({
then: sandbox.stub().yields({members: {another: true}})
});
});
afterEach(function() {
windowSpy.restore();
cancelSpy.restore();
it('calls Quests.sendAction when alert box is confirmed', function() {
sandbox.stub(window, "confirm").returns(true);
scope.questCancel();
expect(window.confirm).to.be.calledOnce;
expect(window.confirm).to.be.calledWith(window.env.t('sureCancel'));
expect(questsService.sendAction).to.be.calledOnce;
expect(questsService.sendAction).to.be.calledWith('questCancel');
});
it('calls Groups.questCancel when alert box is confirmed', function() {
windowSpy = sandbox.stub(window, "confirm", function(){return true});
it('does not call Quests.sendAction when alert box is not confirmed', function() {
sandbox.stub(window, "confirm").returns(false);
scope.questCancel(party);
windowSpy.should.have.been.calledOnce;
windowSpy.should.have.been.calledWith(window.env.t('sureCancel'));
cancelSpy.should.have.been.calledOnce;
});
scope.questCancel();
it('does not call Groups.questCancel when alert box is not confirmed', function() {
windowSpy = sandbox.stub(window, "confirm", function(){return false});
scope.questCancel(party);
windowSpy.should.have.been.calledOnce;
cancelSpy.should.not.have.been.calledOnce;
expect(window.confirm).to.be.calledOnce;
expect(questsService.sendAction).to.not.be.called;
});
});
describe('questAbort', function() {
var party, abortSpy, windowSpy;
beforeEach(function() {
party = {};
abortSpy = sandbox.stub(groups, "questAbort", function(){return true;});
sandbox.stub(questsService, 'sendAction').returns({
then: sandbox.stub().yields({members: {another: true}})
});
});
afterEach(function() {
windowSpy.restore();
abortSpy.restore();
it('calls Quests.sendAction when two alert boxes are confirmed', function() {
sandbox.stub(window, "confirm", function(){return true});
scope.questAbort();
expect(window.confirm).to.be.calledTwice;
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
expect(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort'));
expect(questsService.sendAction).to.be.calledOnce;
expect(questsService.sendAction).to.be.calledWith('questAbort');
});
it('calls Groups.questAbort when two alert boxes are confirmed', function() {
windowSpy = sandbox.stub(window, "confirm", function(){return true});
it('does not call Quests.sendAction when first alert box is not confirmed', function() {
sandbox.stub(window, "confirm", function(){return false});
scope.questAbort(party);
windowSpy.should.have.been.calledTwice;
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
windowSpy.should.have.been.calledWith(window.env.t('doubleSureAbort'));
abortSpy.should.have.been.calledOnce;
scope.questAbort();
expect(window.confirm).to.be.calledOnce;
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
expect(window.confirm).to.not.be.calledWith(window.env.t('doubleSureAbort'));
expect(questsService.sendAction).to.not.be.called;
});
it('does not call Groups.questAbort when first alert box is not confirmed', function() {
windowSpy = sandbox.stub(window, "confirm", function(){return false});
scope.questAbort(party);
windowSpy.should.have.been.calledOnce;
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
windowSpy.should.not.have.been.calledWith(window.env.t('doubleSureAbort'));
abortSpy.should.not.have.been.calledOnce;
});
it('does not call Groups.questAbort when first alert box is confirmed but second one is not', function() {
it('does not call Quests.sendAction when first alert box is confirmed but second one is not', function() {
// Hack to confirm first window, but not second
// Should not be necessary when we upgrade sinon
var shouldReturn = false;
windowSpy = sandbox.stub(window, "confirm", function(){
sandbox.stub(window, 'confirm', function(){
shouldReturn = !shouldReturn;
return shouldReturn;
});
scope.questAbort(party);
windowSpy.should.have.been.calledTwice;
windowSpy.should.have.been.calledWith(window.env.t('sureAbort'));
windowSpy.should.have.been.calledWith(window.env.t('doubleSureAbort'));
abortSpy.should.not.have.been.calledOnce;
scope.questAbort();
expect(window.confirm).to.be.calledTwice;
expect(window.confirm).to.be.calledWith(window.env.t('sureAbort'));
expect(window.confirm).to.be.calledWith(window.env.t('doubleSureAbort'));
expect(questsService.sendAction).to.not.be.called;
});
});
describe('#questLeave', function() {
var party, leaveSpy, windowSpy;
beforeEach(function() {
party = {};
scope.group = {
quest: { members: { 'user-id': true } }
};
leaveSpy = sandbox.stub(groups, 'questLeave').returns({
then: sandbox.stub().yields()
sandbox.stub(questsService, 'sendAction').returns({
then: sandbox.stub().yields({members: {another: true}})
});
});
it('calls Groups.questLeave when alert box is confirmed', function() {
windowSpy = sandbox.stub(window, "confirm").returns(true);
it('calls Quests.sendAction when alert box is confirmed', function() {
sandbox.stub(window, "confirm").returns(true);
scope.questLeave(party);
windowSpy.should.have.been.calledOnce;
windowSpy.should.have.been.calledWith(window.env.t('sureLeave'));
leaveSpy.should.have.been.calledOnce;
scope.questLeave();
expect(window.confirm).to.be.calledOnce;
expect(window.confirm).to.be.calledWith(window.env.t('sureLeave'));
expect(questsService.sendAction).to.be.calledOnce;
expect(questsService.sendAction).to.be.calledWith('questLeave');
});
it('does not call Groups.questLeave when alert box is not confirmed', function() {
windowSpy = sandbox.stub(window, "confirm").returns(false);
it('does not call Quests.sendAction when alert box is not confirmed', function() {
sandbox.stub(window, "confirm").returns(false);
scope.questLeave(party);
windowSpy.should.have.been.calledOnce;
leaveSpy.should.not.have.been.calledOnce;
scope.questLeave();
expect(window.confirm).to.be.calledOnce;
questsService.sendAction.should.not.have.been.calledOnce;
});
it('updates quest object with new participants list', function() {
scope.group.quest = {
members: { user: true, another: true }
};
sandbox.stub(window, "confirm").returns(true);
scope.questLeave();
expect(scope.group.quest).to.eql({members: { another: true }});
});
});
@@ -241,4 +293,28 @@ describe("Party Controller", function() {
});
});
});
describe('#canEditQuest', function() {
var party;
beforeEach(function() {
party = specHelper.newGroup({
type: 'party',
leader: {},
quest: {}
});
});
it('returns false if user is not the quest leader', function() {
party.quest.leader = 'another-user';
expect(scope.canEditQuest(party)).to.eql(false);
});
it('returns true if user is quest leader', function() {
party.quest.leader = 'unique-user-id';
expect(scope.canEditQuest(party)).to.eql(true);
});
});
});