mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
Pull in client side changes for quest routes
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user