mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
Add confirmation popover for Release pets/mounts
Add tests for releasing pets and mounts Refactor tests to use expect syntax from sinon-chai tests(karma): Refine settings controller tests refactor(client): Remove unecessary releaseX functions from $scope in settings ctrl
This commit is contained in:
committed by
Blade Barringer
parent
f6f82cafc4
commit
ea54ec607a
@@ -1,9 +1,13 @@
|
||||
'use strict';
|
||||
|
||||
describe('Settings Controller', function() {
|
||||
describe('Settings Controller', function () {
|
||||
var rootScope, scope, user, User, ctrl;
|
||||
|
||||
beforeEach(function() {
|
||||
const actionClickEvent = {
|
||||
target: document.createElement('button'),
|
||||
};
|
||||
|
||||
beforeEach(function () {
|
||||
module(function($provide) {
|
||||
user = specHelper.newUser();
|
||||
User = {
|
||||
@@ -14,6 +18,9 @@ describe('Settings Controller', function() {
|
||||
User.user.ops = {
|
||||
reroll: sandbox.stub(),
|
||||
rebirth: sandbox.stub(),
|
||||
releasePets: sandbox.stub(),
|
||||
releaseMounts: sandbox.stub(),
|
||||
releaseBoth: sandbox.stub(),
|
||||
};
|
||||
|
||||
$provide.value('User', User);
|
||||
@@ -31,20 +38,20 @@ describe('Settings Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#openDayStartModal', function() {
|
||||
beforeEach(function() {
|
||||
describe('#openDayStartModal', function () {
|
||||
beforeEach(function () {
|
||||
sandbox.stub(rootScope, 'openModal');
|
||||
sandbox.stub(window, 'alert');
|
||||
});
|
||||
|
||||
it('opens the day start modal', function() {
|
||||
it('opens the day start modal', function () {
|
||||
scope.openDayStartModal(5);
|
||||
|
||||
expect(rootScope.openModal).to.be.calledOnce;
|
||||
expect(rootScope.openModal).to.be.calledWith('change-day-start', {scope: scope});
|
||||
});
|
||||
|
||||
it('sets nextCron variable', function() {
|
||||
it('sets nextCron variable', function () {
|
||||
expect(scope.nextCron).to.not.exist;
|
||||
|
||||
scope.openDayStartModal(5);
|
||||
@@ -52,7 +59,7 @@ describe('Settings Controller', function() {
|
||||
expect(scope.nextCron).to.exist;
|
||||
});
|
||||
|
||||
it('calculates the next time cron will run', function() {
|
||||
it('calculates the next time cron will run', function () {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 3, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 1, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
@@ -62,7 +69,7 @@ describe('Settings Controller', function() {
|
||||
expect(scope.nextCron).to.eq(expectedTime);
|
||||
});
|
||||
|
||||
it('calculates the next time cron will run and adds a day if cron would have already passed', function() {
|
||||
it('calculates the next time cron will run and adds a day if cron would have already passed', function () {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
||||
var expectedTime = new Date(2013, 3, 2, 5, 0, 0).getTime();
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
@@ -73,9 +80,9 @@ describe('Settings Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#saveDayStart', function() {
|
||||
describe('#saveDayStart', function () {
|
||||
|
||||
it('updates user\'s custom day start and last cron', function() {
|
||||
it('updates user\'s custom day start and last cron', function () {
|
||||
var fakeCurrentTime = new Date(2013, 3, 1, 8, 12).getTime();
|
||||
var expectedTime = fakeCurrentTime;
|
||||
sandbox.useFakeTimers(fakeCurrentTime);
|
||||
@@ -90,80 +97,190 @@ describe('Settings Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('#reroll', function() {
|
||||
beforeEach(function() {
|
||||
scope.clickReroll(document.createElement('div'));
|
||||
context('Player Reroll', function () {
|
||||
describe('#reroll', function () {
|
||||
beforeEach(function () {
|
||||
scope.clickReroll(actionClickEvent);
|
||||
});
|
||||
|
||||
it('destroys the previous popover if it exists', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
|
||||
scope.reroll(false);
|
||||
|
||||
expect(scope.popoverEl).to.exist;
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
});
|
||||
|
||||
it('doesn\'t call reroll when not confirmed', function () {
|
||||
scope.reroll(false);
|
||||
|
||||
expect(user.ops.reroll).to.not.be.calledOnce;
|
||||
});
|
||||
|
||||
it('calls reroll on the user when confirmed', function () {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
|
||||
scope.reroll(true);
|
||||
|
||||
expect(user.ops.reroll).to.be.calledWith({});
|
||||
});
|
||||
|
||||
it('navigates to the tasks page when confirmed', function () {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
|
||||
scope.reroll(true);
|
||||
|
||||
expect(rootScope.$state.go).to.be.calledWith('tasks');
|
||||
});
|
||||
});
|
||||
|
||||
it('destroys the previous popover if it exists', function() {
|
||||
expect(scope.popoverEl).to.exist;
|
||||
sandbox.spy($.fn, 'popover');
|
||||
scope.reroll(false);
|
||||
describe('#clickReroll', function () {
|
||||
it('displays a confirmation popover for the user', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
|
||||
$.fn.popover.should.have.been.calledWith('destroy');
|
||||
});
|
||||
scope.clickReroll(actionClickEvent);
|
||||
|
||||
it('doesn\'t call reroll when not confirmed', function() {
|
||||
scope.reroll(false);
|
||||
user.ops.reroll.should.not.have.been.called;
|
||||
});
|
||||
|
||||
it('calls reroll on the user when confirmed and navigates to tasks', function() {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
scope.reroll(true);
|
||||
|
||||
user.ops.reroll.should.have.been.calledWith({});
|
||||
rootScope.$state.go.should.have.been.calledWith('tasks');
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
expect($.fn.popover).to.be.calledWith('show');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clickReroll', function() {
|
||||
it('displays a confirmation popover for the user', function() {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
scope.clickReroll(document.createElement('div'));
|
||||
context('Player Rebirth', function () {
|
||||
describe('#rebirth', function () {
|
||||
beforeEach(function () {
|
||||
scope.clickRebirth(actionClickEvent);
|
||||
});
|
||||
|
||||
$.fn.popover.should.have.been.calledWith('destroy');
|
||||
$.fn.popover.should.have.been.called;
|
||||
$.fn.popover.should.have.been.calledWith('show');
|
||||
it('destroys the previous popover if it exists', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
|
||||
scope.rebirth(false);
|
||||
|
||||
expect(scope.popoverEl).to.exist;
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
});
|
||||
|
||||
it('doesn\'t call rebirth when not confirmed', function () {
|
||||
scope.rebirth(false);
|
||||
|
||||
expect(user.ops.rebirth).to.not.be.calledOnce;
|
||||
});
|
||||
|
||||
it('calls rebirth on the user when confirmed', function () {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
|
||||
scope.rebirth(true);
|
||||
|
||||
expect(user.ops.rebirth).to.be.calledWith({});
|
||||
});
|
||||
|
||||
it('navigates to tasks page when confirmed', function () {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
|
||||
scope.rebirth(true);
|
||||
|
||||
expect(rootScope.$state.go).to.be.calledWith('tasks');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clickRebirth', function () {
|
||||
it('displays a confirmation popover for the user', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
|
||||
scope.clickRebirth(actionClickEvent);
|
||||
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
expect($.fn.popover).to.be.calledWith('show');
|
||||
});
|
||||
});
|
||||
})
|
||||
|
||||
context('Releasing pets and mounts', function () {
|
||||
describe('#release', function () {
|
||||
beforeEach(function () {
|
||||
scope.clickRelease('dummy', actionClickEvent);
|
||||
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
});
|
||||
|
||||
it('destroys the previous popover if it exists', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
|
||||
scope.releaseAnimals('', false);
|
||||
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
});
|
||||
|
||||
it('doesn\'t call any release method if type is not provided', function () {
|
||||
scope.releaseAnimals();
|
||||
|
||||
expect(User.user.ops.releasePets).to.not.be.called;
|
||||
expect(User.user.ops.releaseMounts).to.not.be.called;
|
||||
expect(User.user.ops.releaseBoth).to.not.be.called;
|
||||
});
|
||||
|
||||
it('doesn\'t redirect to tasks page if type is not provided', function () {
|
||||
scope.releaseAnimals();
|
||||
|
||||
expect(rootScope.$state.go).to.not.be.called;
|
||||
})
|
||||
|
||||
it('calls releasePets when "pets" is provided', function () {
|
||||
scope.releaseAnimals('pets');
|
||||
|
||||
expect(User.user.ops.releasePets).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('navigates to the tasks page when "pets" is provided', function () {
|
||||
scope.releaseAnimals('pets');
|
||||
|
||||
expect(rootScope.$state.go).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('calls releaseMounts when "mounts" is provided', function () {
|
||||
scope.releaseAnimals('mounts');
|
||||
|
||||
expect(User.user.ops.releaseMounts).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('navigates to the tasks page when "mounts" is provided', function () {
|
||||
scope.releaseAnimals('mounts');
|
||||
|
||||
expect(rootScope.$state.go).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('calls releaseBoth when "both" is provided', function () {
|
||||
scope.releaseAnimals('both');
|
||||
|
||||
expect(User.user.ops.releaseBoth).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('navigates to the tasks page when "both" is provided', function () {
|
||||
scope.releaseAnimals('both');
|
||||
|
||||
expect(rootScope.$state.go).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('does not call release functions when non-applicable argument is passed in', function () {
|
||||
scope.releaseAnimals('dummy');
|
||||
|
||||
expect(User.user.ops.releasePets).to.not.be.called;
|
||||
expect(User.user.ops.releaseMounts).to.not.be.called;
|
||||
expect(User.user.ops.releaseBoth).to.not.be.called;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clickRelease', function () {
|
||||
it('displays a confirmation popover for the user', function () {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
scope.clickRelease('dummy', actionClickEvent);
|
||||
|
||||
expect($.fn.popover).to.be.calledWith('destroy');
|
||||
expect($.fn.popover).to.be.called;
|
||||
expect($.fn.popover).to.be.calledWith('show');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#rebirth', function() {
|
||||
beforeEach(function() {
|
||||
scope.clickRebirth(document.createElement('div'));
|
||||
});
|
||||
|
||||
it('destroys the previous popover if it exists', function() {
|
||||
expect(scope.popoverEl).to.exist;
|
||||
sandbox.spy($.fn, 'popover');
|
||||
scope.rebirth(false);
|
||||
|
||||
$.fn.popover.should.have.been.calledWith('destroy');
|
||||
});
|
||||
|
||||
it('doesn\'t call rebirth when not confirmed', function() {
|
||||
scope.rebirth(false);
|
||||
user.ops.rebirth.should.not.have.been.called;
|
||||
});
|
||||
|
||||
it('calls rebirth on the user when confirmed and navigates to tasks', function() {
|
||||
sandbox.stub(rootScope.$state, 'go');
|
||||
scope.rebirth(true);
|
||||
|
||||
user.ops.rebirth.should.have.been.calledWith({});
|
||||
rootScope.$state.go.should.have.been.calledWith('tasks');
|
||||
});
|
||||
});
|
||||
|
||||
describe('#clickRebirth', function() {
|
||||
it('displays a confirmation popover for the user', function() {
|
||||
sandbox.spy($.fn, 'popover');
|
||||
scope.clickRebirth(document.createElement('div'));
|
||||
|
||||
$.fn.popover.should.have.been.calledWith('destroy');
|
||||
$.fn.popover.should.have.been.called;
|
||||
$.fn.popover.should.have.been.calledWith('show');
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user