Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions __tests__/groups/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,19 @@ describe('Discord Groups Page', () => {
expect(buttonText).toBe('Remove me from this group');
});

test('Should decrease user count by one when user is removed from group', async () => {
const userCount = await page.$$eval('.group-role', (elements) => {
return elements[1].getAttribute('data-member-count');
});

// Wait for the btn-add-role and click it
const deleteRoleBtn = await page.$('.btn-add-role');
await deleteRoleBtn.click();

// Now, check the user count
if (userCount != null) expect(userCount).toBe(userCount - 1);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need to check for userCount not being null and skip the the assertion.

});

test('Should show role deleted', async () => {
await page.$$eval('.group-role', (elements) => {
elements[1].click();
Expand Down
9 changes: 9 additions & 0 deletions groups/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,15 @@ async function removeRoleHandler() {
memberAddRoleBody.roleid,
memberAddRoleBody.userid,
);
if (isDev) {
const groupNameElement = document.getElementById(
`name-${memberAddRoleBody.roleid}`,
);
const currentCount = groupNameElement.getAttribute('data-member-count');
if (currentCount !== null && currentCount !== undefined) {
groupNameElement.setAttribute('data-member-count', currentCount - 1);
}
}
showToaster(res.message);
UserGroupData = await getUserGroupRoles();
updateButtonState();
Expand Down