Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ashboard into Fix/fix-the-broken-UI-of-discord-users-in-mobile-view
  • Loading branch information
ankitbajpai65 committed Oct 9, 2023
2 parents 10b0aad + a1fb689 commit d5bec81
Show file tree
Hide file tree
Showing 9 changed files with 360 additions and 5 deletions.
28 changes: 28 additions & 0 deletions __tests__/groups/group.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,21 @@ describe('Discord Groups Page', () => {
} else {
interceptedRequest.continue();
}
} else if (interceptedRequest.method() === 'DELETE') {
if (url === `${BASE_URL}/discord-actions/roles`) {
interceptedRequest.respond({
status: 200,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify({ message: 'Role deleted successfully' }),
});
} else {
interceptedRequest.continue();
}
} else {
interceptedRequest.continue();
}
Expand Down Expand Up @@ -208,6 +223,19 @@ describe('Discord Groups Page', () => {
expect(buttonText).toBe('Remove me from this group');
});

test('Should show role deleted', async () => {
await page.$$eval('.group-role', (elements) => {
elements[1].click();
});
// Wait for the btn-add-role and click it
const addRoleBtn = await page.$('.btn-add-role');
await addRoleBtn.click();

await page.waitForNetworkIdle();
const toast = await page.$('.toaster-container');
expect(toast).toBeTruthy();
});

test('Should display an error message if the role name contains "group"', async () => {
createGroup = await page.$('.create-groups-tab');
await createGroup.click();
Expand Down
179 changes: 179 additions & 0 deletions __tests__/home/home.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,38 @@ describe('Home Page', () => {
},
body: JSON.stringify(superUserData),
});
} else if (
url === `https://api.realdevsquad.com/discord-actions/group-idle-7d`
) {
interceptedRequest.respond({
status: 200,
ok: true,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify({
message: 'All Idle 7d+ Users updated successfully.',
totalArchivedUsers: 1,
totalGroupIdle7dRolesApplied: {
count: 3,
response: [
{ message: 'Role added successfully' },
{ message: 'Role added successfully' },
{ message: 'Role added successfully' },
],
},
totalGroupIdle7dRolesNotApplied: { count: 0, errors: [] },
totalGroupIdle7dRolesNotRemoved: { count: 0, errors: [] },
totalGroupIdle7dRolesRemoved: { count: 0, response: [] },
totalIdle7dUsers: 4,
totalUserRoleToBeAdded: 4,
totalUserRoleToBeRemoved: 0,
totalUsersHavingNoDiscordId: 0,
}),
});
} else if (
url ===
`https://api.realdevsquad.com/discord-actions/nicknames/sync?dev=true`
Expand All @@ -46,6 +78,74 @@ describe('Home Page', () => {
message: 'Users Nicknames updated successfully',
}),
});
} else if (
url ===
`https://api.realdevsquad.com/discord-actions/group-onboarding-31d-plus`
) {
interceptedRequest.respond({
status: 200,
ok: true,
contentType: 'application/json',
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
},
body: JSON.stringify({
message:
'All Users with 31 Days Plus Onboarding are updated successfully.',
totalOnboardingUsers31DaysCompleted: {
users: [
{
userId: 'R4qppGmmAvJzQXI4jvuc',
discordId: '799600467218923521',
username: 'AnishPawaskar',
},
{
userId: 'W7hqS6BJqWzNW2ejeimC',
discordId: '700385688557715456',
username: 'amandixit',
},
],
count: 2,
},
totalUsersHavingNoDiscordId: 0,
totalArchivedUsers: 0,
usersAlreadyHavingOnboaring31DaysRole: {
users: [],
count: 0,
},
totalOnboarding31dPlusRoleApplied: {
count: 2,
response: [
{
message: 'Role added successfully',
discordId: '799600467218923521',
},
{
message: 'Role added successfully',
discordId: '700385688557715456',
},
],
},
totalOnboarding31dPlusRoleNoteApplied: {
count: 0,
errors: [],
},
totalOnboarding31dPlusRoleRemoved: {
count: 0,
response: [],
},
totalOnboarding31dPlusRoleNotRemoved: {
count: 0,
errors: [],
},
errorInFetchingUserDetailsForRoleRemoval: {
count: 0,
errors: [],
},
}),
});
} else {
interceptedRequest.continue();
}
Expand Down Expand Up @@ -155,6 +255,45 @@ describe('Home Page', () => {
expect(latestSyncStatusText).not.toBe(`Last Sync: In progress`);
});

it('should display the Sync Idle 7d+ Users On Discord button', async () => {
const syncIdle7dPlusUsersButton = await page.$('#sync-idle-7d-Plus-users');
expect(syncIdle7dPlusUsersButton).toBeTruthy();

const spinnerInsideSyncIdle7dPlusUsers = await syncIdle7dPlusUsersButton.$(
'.spinner',
);
expect(spinnerInsideSyncIdle7dPlusUsers).toBeTruthy();

const syncIdle7dPlusUsersUpdate = await page.$(
'#sync-idle-7d-Plus-users-update',
);
expect(syncIdle7dPlusUsersUpdate).toBeTruthy();
});

it('should display the latest sync date when a super_user clicks on the Sync Idle 7d+ Users On Discord button', async () => {
await page.evaluate(() => {
document.querySelector('#sync-idle-7d-Plus-users').click();
});
await page.waitForNetworkIdle();

const latestSyncStatusElement = await page.waitForSelector(
'#sync-idle-7d-Plus-users-update',
);

expect(latestSyncStatusElement).toBeTruthy();

const latestSyncStatusText = await page.evaluate(
(element) => element.textContent,
latestSyncStatusElement,
);

expect(latestSyncStatusText).not.toBe(`Last Sync: Failed`);
expect(latestSyncStatusText).not.toBe(
`Last Sync: Synced Data Not Available`,
);
expect(latestSyncStatusText).not.toBe(`Last Sync: In progress`);
});

it('should display the Create Goals anchor button', async () => {
const createGoalsButton = await page.$('#create-goal');
expect(createGoalsButton).toBeTruthy();
Expand Down Expand Up @@ -247,4 +386,44 @@ describe('Home Page', () => {
const repoLinkStyle = await page.evaluate((el) => el.style, repoLink);
expect(repoLinkStyle).toBeTruthy();
});

it('should display the Sync Onboarding 31d+ button', async () => {
const syncOnboarding31dPlusUsersButton = await page.$(
'#sync-onboarding-31d-plus-users',
);
expect(syncOnboarding31dPlusUsersButton).toBeTruthy();

const spinnerInsideSyncOnboarding31dPlusUsers =
await syncOnboarding31dPlusUsersButton.$('.spinner');
expect(spinnerInsideSyncOnboarding31dPlusUsers).toBeTruthy();

const syncOnboarding31dPlusUsersUpdate = await page.$(
'#sync-onboarding-31d-plus-users-update',
);
expect(syncOnboarding31dPlusUsersUpdate).toBeTruthy();
});

it('should display the latest sync date when a super_user clicks on the Sync Onboarding 31d+ button', async () => {
await page.evaluate(() => {
document.querySelector('#sync-onboarding-31d-plus-users').click();
});
await page.waitForNetworkIdle();

const latestSyncStatusElement = await page.waitForSelector(
'#sync-onboarding-31d-plus-users-update',
);

expect(latestSyncStatusElement).toBeTruthy();

const latestSyncStatusText = await page.evaluate(
(element) => element.textContent,
latestSyncStatusElement,
);

expect(latestSyncStatusText).not.toBe(`Last Sync: Failed`);
expect(latestSyncStatusText).not.toBe(
`Last Sync: Synced Data Not Available`,
);
expect(latestSyncStatusText).not.toBe(`Last Sync: In progress`);
});
});
5 changes: 5 additions & 0 deletions constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ const SYNC_EXTERNAL_ACCOUNTS_UPDATE = 'sync-external-accounts-update';
const SYNC_UNVERIFIED_USERS_UPDATE = 'sync-unverified-users-update';
const SYNC_NICKNAMES = 'sync-nicknames';
const SYNC_NICKNAMES_STATUS_UPDATE = 'sync-nicknames-status-update';
const SYNC_IDLE_7D_Plus_USERS = 'sync-idle-7d-Plus-users';
const SYNC_IDLE_7D_Plus_USERS_UPDATE = 'sync-idle-7d-Plus-users-update';
const SYNC_ONBOARDING_31D_PLUS_USERS = 'sync-onboarding-31d-plus-users';
const SYNC_ONBOARDING_31D_PLUS_USERS_UPDATE =
'sync-onboarding-31d-plus-users-update';
const SYNC_IN_PROGRESS = 'Last Sync: In progress';
const SYNC_SUCCESSFUL = 'Last Sync: Successful';
const SYNC_FAILED = 'Last Sync: Failed';
Expand Down
4 changes: 3 additions & 1 deletion groups/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ <h3 class="not-verified-tag hidden">
<h2 id="no-results-message">No results found.</h2>
</main>
</div>

<div class="toaster-container">
<div id="toaster" class="toaster-message hidden"></div>
</div>
<div class="create-group hidden">
<div class="group-fields">
<label for="new-group" class="label-for-new-group"
Expand Down
43 changes: 39 additions & 4 deletions groups/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
removeGroupKeywordFromDiscordRoleName,
getDiscordGroups,
addGroupRoleToMember,
removeRoleFromMember,
createDiscordGroupRole,
getUserSelf,
getUserGroupRoles,
Expand Down Expand Up @@ -196,6 +197,18 @@ function debounce(func, delay) {
};
}

function showToaster(message) {
const toaster = document.getElementById('toaster');
toaster.innerText = message;
toaster.classList.add('show');
toaster.classList.remove('hidden');

setTimeout(() => {
toaster.classList.remove('show');
toaster.classList.add('hidden');
}, 3000);
}

searchInput.addEventListener(
'input',
debounce(() => {
Expand Down Expand Up @@ -245,16 +258,22 @@ async function addrole() {
if (currentCount !== null && currentCount !== undefined) {
groupNameElement.setAttribute('data-member-count', +currentCount + 1);
}
alert(res.message);
if (isDev) {
// After adding the role, re-fetch the user group data to update it
UserGroupData = await getUserGroupRoles();

// Update the button state with the refreshed data
updateButtonState();
showToaster(res.message);
} else {
alert(res.message);
}
} catch (err) {
alert(err.message);
if (isDev) {
showToaster(err.message);
} else {
alert(err.message);
}
} finally {
loader.classList.add('hidden');
}
Expand All @@ -264,10 +283,26 @@ async function addrole() {
/**
* TO REMOVE YOURSELF OF A ROLE
*/

async function removeRoleHandler() {
console.log('Remove function to be added after this pr');
if (memberAddRoleBody?.userid && memberAddRoleBody?.roleid !== '') {
loader.classList.remove('hidden');

// TODO: REMOVE ME BUTTON FUNCTIONALITY TO BE ADDED
try {
// Remove the role from the member
const res = await removeRoleFromMember(
memberAddRoleBody.roleid,
memberAddRoleBody.userid,
);
showToaster(res.message);
UserGroupData = await getUserGroupRoles();
updateButtonState();
} catch (err) {
showToaster(err.message);
} finally {
loader.classList.add('hidden');
}
}
}

/**
Expand Down
38 changes: 38 additions & 0 deletions groups/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,44 @@
background-color: var(--color-active-groups-background);
}

/*
FOR Message toaster box
*/

.toaster-container {
position: fixed;
top: 20px;
right: 20px;
width: 300px;
}

.toaster-message {
padding: 15px;
background-color: #4caf50;
color: white;
border-radius: 5px;
margin-bottom: 10px;
display: none;
}

.hidden {
display: none;
}

.show {
display: block;
animation: fadeOut 2s forwards;
}

@keyframes fadeOut {
0% {
opacity: 1;
}
100% {
opacity: 0;
}
}

/*
FOR MANAGE GROUPS
*/
Expand Down
Loading

0 comments on commit d5bec81

Please sign in to comment.