mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 15:17:25 +01:00
clean up party {up,on} tests, add calls to $controller after setup
This commit is contained in:
@@ -8,12 +8,10 @@ describe("Party Controller", function() {
|
|||||||
user._id = "unique-user-id";
|
user._id = "unique-user-id";
|
||||||
User = {
|
User = {
|
||||||
user: user,
|
user: user,
|
||||||
sync: sandbox.spy,
|
sync: sandbox.spy(),
|
||||||
set: function() {} // no-op
|
set: sandbox.spy()
|
||||||
}
|
}
|
||||||
|
|
||||||
sandbox.stub(User, 'set');
|
|
||||||
|
|
||||||
module(function($provide) {
|
module(function($provide) {
|
||||||
$provide.value('User', User);
|
$provide.value('User', User);
|
||||||
});
|
});
|
||||||
@@ -42,61 +40,66 @@ describe("Party Controller", function() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
context('party has 1 member', function() {
|
context('party has 1 member', function() {
|
||||||
beforeEach(function() {
|
it('awards no new achievements', function() {
|
||||||
scope.group = { memberCount: 1 };
|
sandbox.stub(groups, 'party').returns({
|
||||||
|
$syncParty: function() {},
|
||||||
|
memberCount: 1
|
||||||
});
|
});
|
||||||
|
|
||||||
it('awards no new achievements', function() {
|
$controller('PartyCtrl', { $scope: scope, User: User });
|
||||||
|
|
||||||
expect(User.set).to.not.be.called;
|
expect(User.set).to.not.be.called;
|
||||||
expect(rootScope.openModal).to.not.be.called;
|
expect(rootScope.openModal).to.not.be.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('party has 2 members', function() {
|
context('party has 2 members', function() {
|
||||||
beforeEach(function() {
|
|
||||||
scope.group = { memberCount: 2 };
|
|
||||||
});
|
|
||||||
|
|
||||||
context('user does not have "Party Up" achievement', function() {
|
context('user does not have "Party Up" achievement', function() {
|
||||||
it('awards "Party Up" achievement', function() {
|
it('awards "Party Up" achievement', function() {
|
||||||
|
sandbox.stub(groups, 'party').returns({
|
||||||
|
$syncParty: function() {},
|
||||||
|
memberCount: 2
|
||||||
|
});
|
||||||
|
|
||||||
|
$controller('PartyCtrl', { $scope: scope, User: User });
|
||||||
|
|
||||||
expect(User.set).to.be.calledOnce;
|
expect(User.set).to.be.calledOnce;
|
||||||
expect(User.set).to.be.calledWith(
|
expect(User.set).to.be.calledWith(
|
||||||
{ 'achievements.partyUp': true }
|
{ 'achievements.partyUp': true }
|
||||||
);
|
);
|
||||||
expect(rootScope.openModal).to.be.calledOnce;
|
expect(rootScope.openModal).to.be.calledOnce;
|
||||||
expect(rootScope.openModal).to.be.calledWith(
|
expect(rootScope.openModal).to.be.calledWith('achievements/partyUp');
|
||||||
'achievements/partyUp',
|
|
||||||
{ controller: 'UserCtrl' }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('party has 4 members', function() {
|
context('party has 4 members', function() {
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
scope.group = { memberCount: 4 };
|
sandbox.stub(groups, 'party').returns({
|
||||||
|
$syncParty: function() {},
|
||||||
|
memberCount: 4
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('user has "Party Up" but not "Party On" achievement', function() {
|
context('user has "Party Up" but not "Party On" achievement', function() {
|
||||||
beforeEach(function() {
|
|
||||||
user.achievements.partyUp = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
it('awards "Party On" achievement', function() {
|
it('awards "Party On" achievement', function() {
|
||||||
|
user.achievements.partyUp = true;
|
||||||
|
|
||||||
|
$controller('PartyCtrl', { $scope: scope, User: User });
|
||||||
|
|
||||||
expect(User.set).to.be.calledOnce;
|
expect(User.set).to.be.calledOnce;
|
||||||
expect(User.set).to.be.calledWith(
|
expect(User.set).to.be.calledWith(
|
||||||
{ 'achievements.partyOn': true }
|
{ 'achievements.partyOn': true }
|
||||||
);
|
);
|
||||||
expect(rootScope.openModal).to.be.calledOnce;
|
expect(rootScope.openModal).to.be.calledOnce;
|
||||||
expect(rootScope.openModal).to.be.calledWith(
|
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
|
||||||
'achievements/partyOn',
|
|
||||||
{ controller: 'UserCtrl' }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('user has neither "Party Up" nor "Party On" achievements', function() {
|
context('user has neither "Party Up" nor "Party On" achievements', function() {
|
||||||
it('awards "Party Up" and "Party On" achievements', function() {
|
it('awards "Party Up" and "Party On" achievements', function() {
|
||||||
|
$controller('PartyCtrl', { $scope: scope, User: User });
|
||||||
|
|
||||||
expect(User.set).to.be.calledTwice;
|
expect(User.set).to.be.calledTwice;
|
||||||
expect(User.set).to.be.calledWith(
|
expect(User.set).to.be.calledWith(
|
||||||
{ 'achievements.partyUp': true}
|
{ 'achievements.partyUp': true}
|
||||||
@@ -105,29 +108,22 @@ describe("Party Controller", function() {
|
|||||||
{ 'achievements.partyOn': true}
|
{ 'achievements.partyOn': true}
|
||||||
);
|
);
|
||||||
expect(rootScope.openModal).to.be.calledTwice;
|
expect(rootScope.openModal).to.be.calledTwice;
|
||||||
expect(rootScope.openModal).to.be.calledWith(
|
expect(rootScope.openModal).to.be.calledWith('achievements/partyUp');
|
||||||
'achievements/partyUp',
|
expect(rootScope.openModal).to.be.calledWith('achievements/partyOn');
|
||||||
{ controller: 'UserCtrl' }
|
|
||||||
);
|
|
||||||
expect(rootScope.openModal).to.be.calledWith(
|
|
||||||
'achievements/partyOn',
|
|
||||||
{ controller: 'UserCtrl' }
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
context('user has both "Party Up" and "Party On" achievements', function() {
|
context('user has both "Party Up" and "Party On" achievements', function() {
|
||||||
beforeEach(function() {
|
it('awards no new achievements', function() {
|
||||||
user.achievements.partyUp = true;
|
user.achievements.partyUp = true;
|
||||||
user.achievements.partyOn = true;
|
user.achievements.partyOn = true;
|
||||||
});
|
|
||||||
|
|
||||||
it('awards no new achievements', function() {
|
$controller('PartyCtrl', { $scope: scope, User: User });
|
||||||
|
|
||||||
expect(User.set).to.not.be.called;
|
expect(User.set).to.not.be.called;
|
||||||
expect(rootScope.openModal).to.not.be.called;
|
expect(rootScope.openModal).to.not.be.called;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user