mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
Organize challenge controllers specs
This commit is contained in:
@@ -33,496 +33,505 @@ describe('Challenges Controller', function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe('filterChallenges', function() {
|
||||
var ownMem, ownNotMem, notOwnMem, notOwnNotMem;
|
||||
context('filtering', function() {
|
||||
describe('filterChallenges', function() {
|
||||
var ownMem, ownNotMem, notOwnMem, notOwnNotMem;
|
||||
|
||||
beforeEach(function() {
|
||||
ownMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'You are the owner and member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [user],
|
||||
official: false,
|
||||
_isMember: true
|
||||
beforeEach(function() {
|
||||
ownMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'You are the owner and member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [user],
|
||||
official: false,
|
||||
_isMember: true
|
||||
});
|
||||
|
||||
ownNotMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'You are the owner, but not a member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
_isMember: false
|
||||
});
|
||||
|
||||
notOwnMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'Not owner but a member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: {_id:"test"},
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [user],
|
||||
official: false,
|
||||
_isMember: true
|
||||
});
|
||||
|
||||
notOwnNotMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'Not owner or member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: {_id:"test"},
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
_isMember: false
|
||||
});
|
||||
|
||||
scope.search = {
|
||||
group: _.transform(groups, function(m,g){m[g._id]=true;})
|
||||
};
|
||||
});
|
||||
|
||||
ownNotMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'You are the owner, but not a member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
_isMember: false
|
||||
it('displays challenges that match membership: either and owner: either', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
|
||||
notOwnMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'Not owner but a member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: {_id:"test"},
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [user],
|
||||
official: false,
|
||||
_isMember: true
|
||||
it('displays challenges that match membership: either and owner: true', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
notOwnNotMem = new challenges.Challenge({
|
||||
name: 'test',
|
||||
description: 'Not owner or member',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: {_id:"test"},
|
||||
group: "test",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
_isMember: false
|
||||
it('displays challenges that match membership: either and owner: false', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
|
||||
scope.search = {
|
||||
group: _.transform(groups, function(m,g){m[g._id]=true;})
|
||||
it('displays challenges that match membership: true and owner: either', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: true and owner: true', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: true and owner: false', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: either', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: true', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: false', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('selectAll', function() {
|
||||
it('selects all groups');
|
||||
});
|
||||
|
||||
describe('selectNone', function() {
|
||||
it('selects no groups');
|
||||
});
|
||||
});
|
||||
|
||||
context('task manipulation', function() {
|
||||
|
||||
describe('shouldShow', function() {
|
||||
it('overrides task controller function by always returning true', function() {
|
||||
expect(scope.shouldShow()).to.eq(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('edit', function() {
|
||||
it('transitions to edit page');
|
||||
});
|
||||
|
||||
describe('addTask', function() {
|
||||
it('adds default task to array');
|
||||
it('removes text from new task input box');
|
||||
});
|
||||
|
||||
describe('editTask', function() {
|
||||
it('is Tasks.editTask', function() {
|
||||
inject(function(Tasks) {
|
||||
expect(scope.editTask).to.eql(Tasks.editTask);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeTask', function() {
|
||||
it('asks user to confirm deletion');
|
||||
it('removes task from list');
|
||||
});
|
||||
|
||||
describe('saveTask', function() {
|
||||
it('sets task._editing to false');
|
||||
});
|
||||
});
|
||||
|
||||
context('challenge owner interactions', function() {
|
||||
describe("save challenge", function() {
|
||||
var alert;
|
||||
|
||||
beforeEach(function(){
|
||||
alert = sandbox.stub(window, "alert");
|
||||
});
|
||||
|
||||
it("opens an alert box if challenge.group is not specified", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without a group',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
|
||||
expect(alert).to.be.calledOnce;
|
||||
expect(alert).to.be.calledWith(window.env.t('selectGroup'));
|
||||
});
|
||||
|
||||
it("opens an alert box if isNew and user does not have enough gems", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
prize: 5,
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false
|
||||
});
|
||||
|
||||
scope.maxPrize = 4;
|
||||
scope.save(challenge);
|
||||
|
||||
expect(alert).to.be.calledOnce;
|
||||
expect(alert).to.be.calledWith(window.env.t('challengeNotEnoughGems'));
|
||||
});
|
||||
|
||||
it("saves the challenge if user does not have enough gems, but the challenge is not new", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
_id: 'challeng-id', // challenge has id, so it's not new
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: sandbox.spy()
|
||||
});
|
||||
|
||||
scope.maxPrize = 0;
|
||||
scope.save(challenge);
|
||||
|
||||
expect(challenge.$save).to.be.calledOnce;
|
||||
expect(alert).to.not.be.called;
|
||||
});
|
||||
|
||||
it("saves the challenge if user has enough gems and challenge is new", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: sandbox.spy()
|
||||
});
|
||||
|
||||
scope.maxPrize = 5;
|
||||
scope.save(challenge);
|
||||
|
||||
expect(challenge.$save).to.be.calledOnce;
|
||||
expect(alert).to.not.be.called;
|
||||
});
|
||||
|
||||
it('saves challenge and then proceeds to detail page', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'challenge-id'});
|
||||
sandbox.stub(state, 'transitionTo');
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
_id: 'challenge-id',
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
|
||||
expect(state.transitionTo).to.be.calledOnce;
|
||||
expect(state.transitionTo).to.be.calledWith(
|
||||
'options.social.challenges.detail',
|
||||
{ cid: 'challenge-id' },
|
||||
{
|
||||
reload: true, inherit: false, notify: true
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('saves new challenge and syncs User', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'new-challenge'});
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
|
||||
expect(User.sync).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('saves new challenge and syncs User', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'new-challenge'});
|
||||
sinon.stub(notification, 'text');
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
|
||||
expect(notification.text).to.be.calledOnce;
|
||||
expect(notification.text).to.be.calledWith(window.env.t('challengeCreated'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', function() {
|
||||
it('creates new challenge with group that user has selected in filter');
|
||||
|
||||
it('defaults to tavern if no group can be set as default');
|
||||
|
||||
it('calculates maxPrize');
|
||||
|
||||
it('sets newChallenge to a blank challenge');
|
||||
|
||||
context('tavern challenge', function() {
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to false if user has no gems');
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to true if user has at least one gem');
|
||||
});
|
||||
|
||||
context('non-tavern challenge', function() {
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('discard', function() {
|
||||
it('sets new challenge to null');
|
||||
});
|
||||
|
||||
describe('clone', function() {
|
||||
|
||||
var challengeToClone = {
|
||||
name: 'copyChallenge',
|
||||
description: 'copyChallenge',
|
||||
habits: [specHelper.newHabit()],
|
||||
dailys: [specHelper.newDaily()],
|
||||
todos: [specHelper.newTodo()],
|
||||
rewards: [specHelper.newReward()],
|
||||
leader: 'unique-user-id',
|
||||
group: { _id: "copyGroup" },
|
||||
timestamp: new Date("October 13, 2014 11:13:00"),
|
||||
members: ['id', 'another-id'],
|
||||
official: true,
|
||||
_isMember: true,
|
||||
prize: 1
|
||||
};
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: either and owner: either', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
it('Clones the basic challenge info', function() {
|
||||
|
||||
it('displays challenges that match membership: either and owner: true', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
it('displays challenges that match membership: either and owner: false', function() {
|
||||
scope.search._isMember = 'either';
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: true and owner: either', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: true and owner: true', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: true and owner: false', function() {
|
||||
scope.search._isMember = true;
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: either', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = 'either';
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: true', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = true;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(true);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(false);
|
||||
});
|
||||
|
||||
it('displays challenges that match membership: false and owner: false', function() {
|
||||
scope.search._isMember = false;
|
||||
scope.search._isOwner = false;
|
||||
expect(scope.filterChallenges(ownMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(ownNotMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnMem)).to.eql(false);
|
||||
expect(scope.filterChallenges(notOwnNotMem)).to.eql(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('selectAll', function() {
|
||||
it('selects all groups');
|
||||
});
|
||||
|
||||
describe('selectNone', function() {
|
||||
it('selects no groups');
|
||||
});
|
||||
|
||||
describe('shouldShow', function() {
|
||||
it('overrides task controller function by always returning true', function() {
|
||||
expect(scope.shouldShow()).to.eq(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe("save challenge", function() {
|
||||
var alert;
|
||||
|
||||
beforeEach(function(){
|
||||
alert = sandbox.stub(window, "alert");
|
||||
});
|
||||
|
||||
it("opens an alert box if challenge.group is not specified", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without a group',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false
|
||||
expect(scope.newChallenge.name).to.eql(challengeToClone.name);
|
||||
expect(scope.newChallenge.shortName).to.eql(challengeToClone.shortName);
|
||||
expect(scope.newChallenge.description).to.eql(challengeToClone.description);
|
||||
expect(scope.newChallenge.leader).to.eql(user._id);
|
||||
expect(scope.newChallenge.group).to.eql(challengeToClone.group._id);
|
||||
expect(scope.newChallenge.official).to.eql(challengeToClone.official);
|
||||
expect(scope.newChallenge.prize).to.eql(challengeToClone.prize);
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
it('does not clone members', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(alert).to.be.calledOnce;
|
||||
expect(alert).to.be.calledWith(window.env.t('selectGroup'));
|
||||
});
|
||||
|
||||
it("opens an alert box if isNew and user does not have enough gems", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
prize: 5,
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false
|
||||
expect(scope.newChallenge.members).to.not.exist;
|
||||
});
|
||||
|
||||
scope.maxPrize = 4;
|
||||
scope.save(challenge);
|
||||
it('does not clone timestamp', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(alert).to.be.calledOnce;
|
||||
expect(alert).to.be.calledWith(window.env.t('challengeNotEnoughGems'));
|
||||
});
|
||||
|
||||
it("saves the challenge if user does not have enough gems, but the challenge is not new", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
_id: 'challeng-id', // challenge has id, so it's not new
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: sandbox.spy()
|
||||
expect(scope.newChallenge.timestamp).to.not.exist;
|
||||
});
|
||||
|
||||
scope.maxPrize = 0;
|
||||
scope.save(challenge);
|
||||
it('clones habits', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(challenge.$save).to.be.calledOnce;
|
||||
expect(alert).to.not.be.called;
|
||||
});
|
||||
|
||||
it("saves the challenge if user has enough gems and challenge is new", function() {
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: sandbox.spy()
|
||||
expect(scope.newChallenge.habits.length).to.eql(challengeToClone.habits.length);
|
||||
expect(scope.newChallenge.habits[0].text).to.eql(challengeToClone.habits[0].text);
|
||||
expect(scope.newChallenge.habits[0].notes).to.eql(challengeToClone.habits[0].notes);
|
||||
});
|
||||
|
||||
scope.maxPrize = 5;
|
||||
scope.save(challenge);
|
||||
it('clones dailys', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(challenge.$save).to.be.calledOnce;
|
||||
expect(alert).to.not.be.called;
|
||||
});
|
||||
|
||||
it('saves challenge and then proceeds to detail page', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'challenge-id'});
|
||||
sandbox.stub(state, 'transitionTo');
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
_id: 'challenge-id',
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
expect(scope.newChallenge.dailys.length).to.eql(challengeToClone.dailys.length);
|
||||
expect(scope.newChallenge.dailys[0].text).to.eql(challengeToClone.dailys[0].text);
|
||||
expect(scope.newChallenge.dailys[0].notes).to.eql(challengeToClone.dailys[0].notes);
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
it('clones todos', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(state.transitionTo).to.be.calledOnce;
|
||||
expect(state.transitionTo).to.be.calledWith(
|
||||
'options.social.challenges.detail',
|
||||
{ cid: 'challenge-id' },
|
||||
{
|
||||
reload: true, inherit: false, notify: true
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
it('saves new challenge and syncs User', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'new-challenge'});
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
expect(scope.newChallenge.todos.length).to.eql(challengeToClone.todos.length);
|
||||
expect(scope.newChallenge.todos[0].text).to.eql(challengeToClone.todos[0].text);
|
||||
expect(scope.newChallenge.todos[0].notes).to.eql(challengeToClone.todos[0].notes);
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
it('clones rewards', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(User.sync).to.be.calledOnce;
|
||||
});
|
||||
|
||||
it('saves new challenge and syncs User', function() {
|
||||
var saveSpy = sandbox.stub();
|
||||
saveSpy.yields({_id: 'new-challenge'});
|
||||
sinon.stub(notification, 'text');
|
||||
|
||||
var challenge = new challenges.Challenge({
|
||||
name: 'Challenge without enough gems',
|
||||
description: '',
|
||||
habits: [],
|
||||
dailys: [],
|
||||
todos: [],
|
||||
rewards: [],
|
||||
leader: user._id,
|
||||
group: "a-group-id",
|
||||
prize: 5,
|
||||
timestamp: +(new Date),
|
||||
members: [],
|
||||
official: false,
|
||||
// Mock $save
|
||||
$save: saveSpy
|
||||
});
|
||||
|
||||
scope.save(challenge);
|
||||
|
||||
expect(notification.text).to.be.calledOnce;
|
||||
expect(notification.text).to.be.calledWith(window.env.t('challengeCreated'));
|
||||
});
|
||||
});
|
||||
|
||||
describe('create', function() {
|
||||
it('creates new challenge with group that user has selected in filter');
|
||||
|
||||
it('defaults to tavern if no group can be set as default');
|
||||
|
||||
it('calculates maxPrize');
|
||||
|
||||
it('sets newChallenge to a blank challenge');
|
||||
|
||||
context('tavern challenge', function() {
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to false if user has no gems');
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to true if user has at least one gem');
|
||||
});
|
||||
|
||||
context('non-tavern challenge', function() {
|
||||
it('sets isTavernChallengeAndUserCannotProvidePrize to false');
|
||||
});
|
||||
});
|
||||
|
||||
describe('discard', function() {
|
||||
it('sets new challenge to null');
|
||||
});
|
||||
|
||||
describe('edit', function() {
|
||||
it('transitions to edit page');
|
||||
});
|
||||
|
||||
describe('addTask', function() {
|
||||
it('adds default task to array');
|
||||
it('removes text from new task input box');
|
||||
});
|
||||
|
||||
describe('editTask', function() {
|
||||
it('is Tasks.editTask', function() {
|
||||
inject(function(Tasks) {
|
||||
expect(scope.editTask).to.eql(Tasks.editTask);
|
||||
expect(scope.newChallenge.rewards.length).to.eql(challengeToClone.rewards.length);
|
||||
expect(scope.newChallenge.rewards[0].text).to.eql(challengeToClone.rewards[0].text);
|
||||
expect(scope.newChallenge.rewards[0].notes).to.eql(challengeToClone.rewards[0].notes);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeTask', function() {
|
||||
it('asks user to confirm deletion');
|
||||
it('removes task from list');
|
||||
});
|
||||
|
||||
describe('saveTask', function() {
|
||||
it('sets task._editing to false');
|
||||
});
|
||||
|
||||
describe('join', function() {
|
||||
it('calls challenge join endpoint');
|
||||
});
|
||||
|
||||
describe('clickLeave', function() {
|
||||
it('opens a popover to confirm');
|
||||
});
|
||||
|
||||
describe('leave', function() {
|
||||
it('(@TODO: write tests)');
|
||||
});
|
||||
|
||||
describe('clone', function() {
|
||||
|
||||
var challengeToClone = {
|
||||
name: 'copyChallenge',
|
||||
description: 'copyChallenge',
|
||||
habits: [specHelper.newHabit()],
|
||||
dailys: [specHelper.newDaily()],
|
||||
todos: [specHelper.newTodo()],
|
||||
rewards: [specHelper.newReward()],
|
||||
leader: 'unique-user-id',
|
||||
group: { _id: "copyGroup" },
|
||||
timestamp: new Date("October 13, 2014 11:13:00"),
|
||||
members: ['id', 'another-id'],
|
||||
official: true,
|
||||
_isMember: true,
|
||||
prize: 1
|
||||
};
|
||||
|
||||
it('Clones the basic challenge info', function() {
|
||||
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.name).to.eql(challengeToClone.name);
|
||||
expect(scope.newChallenge.shortName).to.eql(challengeToClone.shortName);
|
||||
expect(scope.newChallenge.description).to.eql(challengeToClone.description);
|
||||
expect(scope.newChallenge.leader).to.eql(user._id);
|
||||
expect(scope.newChallenge.group).to.eql(challengeToClone.group._id);
|
||||
expect(scope.newChallenge.official).to.eql(challengeToClone.official);
|
||||
expect(scope.newChallenge.prize).to.eql(challengeToClone.prize);
|
||||
describe('User interactions', function() {
|
||||
describe('join', function() {
|
||||
it('calls challenge join endpoint');
|
||||
});
|
||||
|
||||
it('does not clone members', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.members).to.not.exist;
|
||||
describe('clickLeave', function() {
|
||||
it('opens a popover to confirm');
|
||||
});
|
||||
|
||||
it('does not clone timestamp', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.timestamp).to.not.exist;
|
||||
});
|
||||
|
||||
it('clones habits', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.habits.length).to.eql(challengeToClone.habits.length);
|
||||
expect(scope.newChallenge.habits[0].text).to.eql(challengeToClone.habits[0].text);
|
||||
expect(scope.newChallenge.habits[0].notes).to.eql(challengeToClone.habits[0].notes);
|
||||
});
|
||||
|
||||
it('clones dailys', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.dailys.length).to.eql(challengeToClone.dailys.length);
|
||||
expect(scope.newChallenge.dailys[0].text).to.eql(challengeToClone.dailys[0].text);
|
||||
expect(scope.newChallenge.dailys[0].notes).to.eql(challengeToClone.dailys[0].notes);
|
||||
});
|
||||
|
||||
it('clones todos', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.todos.length).to.eql(challengeToClone.todos.length);
|
||||
expect(scope.newChallenge.todos[0].text).to.eql(challengeToClone.todos[0].text);
|
||||
expect(scope.newChallenge.todos[0].notes).to.eql(challengeToClone.todos[0].notes);
|
||||
});
|
||||
|
||||
it('clones rewards', function() {
|
||||
scope.clone(challengeToClone);
|
||||
|
||||
expect(scope.newChallenge.rewards.length).to.eql(challengeToClone.rewards.length);
|
||||
expect(scope.newChallenge.rewards[0].text).to.eql(challengeToClone.rewards[0].text);
|
||||
expect(scope.newChallenge.rewards[0].notes).to.eql(challengeToClone.rewards[0].notes);
|
||||
describe('leave', function() {
|
||||
it('(@TODO: write tests)');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user