mirror of
https://github.com/sudoxnym/habitica.git
synced 2026-08-05 03:52:14 +00:00
Merge pull request #5079 from gisikw/party-join-leave-buttons
Ensure correct join/leave button for parties
This commit is contained in:
commit
bbc9a75d49
2 changed files with 20 additions and 1 deletions
|
|
@ -1,7 +1,7 @@
|
|||
'use strict';
|
||||
|
||||
describe('Groups Controller', function() {
|
||||
var scope, ctrl, groups, user, guild, $rootScope;
|
||||
var scope, ctrl, groups, user, guild, party, $rootScope;
|
||||
|
||||
beforeEach(function() {
|
||||
module(function($provide) {
|
||||
|
|
@ -23,6 +23,19 @@ describe('Groups Controller', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it("isMemberOfGroup returns true if group is the user's party", function() {
|
||||
party = specHelper.newGroup("test-party");
|
||||
party._id = "unique-party-id";
|
||||
party.type = 'party';
|
||||
party.members = []; // Ensure we wouldn't pass automatically.
|
||||
|
||||
var partyStub = sinon.stub(groups,"party", function() {
|
||||
return party;
|
||||
});
|
||||
|
||||
expect(scope.isMemberOfGroup(user._id, party)).to.be.ok;
|
||||
});
|
||||
|
||||
it('isMemberOfGroup returns true if guild is included in myGuilds call', function(){
|
||||
|
||||
guild = specHelper.newGroup("leaders-user-id");
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ habitrpg.controller("GroupsCtrl", ['$scope', '$rootScope', 'Shared', 'Groups', '
|
|||
return _.detect(Groups.myGuilds(), function(g) { return g._id === group._id });
|
||||
}
|
||||
|
||||
// Similarly, if we're dealing with the user's current party, return true.
|
||||
if(group.type === 'party') {
|
||||
var currentParty = Groups.party();
|
||||
if(currentParty._id && currentParty._id === group._id) return true;
|
||||
}
|
||||
|
||||
if (!group.members) return false;
|
||||
var memberIds = _.map(group.members, function(x){return x._id});
|
||||
return ~(memberIds.indexOf(userid));
|
||||
|
|
|
|||
Loading…
Reference in a new issue