diff --git a/app/assets/javascripts/discourse/components/group-membership-button.js.es6 b/app/assets/javascripts/discourse/components/group-membership-button.js.es6 index 8f1ac5798a7..b78bb902064 100644 --- a/app/assets/javascripts/discourse/components/group-membership-button.js.es6 +++ b/app/assets/javascripts/discourse/components/group-membership-button.js.es6 @@ -17,7 +17,7 @@ export default Ember.Component.extend({ if (isGroupUser) { return isGroupUser; } else { - return groupUserIds.includes(groupId); + return !!groupUserIds && groupUserIds.includes(groupId); } }, diff --git a/test/javascripts/components/group-membership-button-test.js.es6 b/test/javascripts/components/group-membership-button-test.js.es6 index 579aa6f1adf..b1796078d87 100644 --- a/test/javascripts/components/group-membership-button-test.js.es6 +++ b/test/javascripts/components/group-membership-button-test.js.es6 @@ -35,3 +35,27 @@ test('canRequestMembership', function() { equal(this.subject().get('canRequestMembership'), false); }); + +test('userIsGroupUser', function() { + this.subject().setProperties({ + model: { is_group_user: true } + }); + + equal(this.subject().get('userIsGroupUser'), true); + + this.subject().set('model.is_group_user', false); + + equal(this.subject().get('userIsGroupUser'), false); + + this.subject().setProperties({ model: { id: 1 }, groupUserIds: [1] }); + + equal(this.subject().get('userIsGroupUser'), true); + + this.subject().set('groupUserIds', [3]); + + equal(this.subject().get('userIsGroupUser'), false); + + this.subject().set('groupUserIds', undefined); + + equal(this.subject().get('userIsGroupUser'), false); +});