Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AnujChhikara committed Oct 28, 2024
1 parent 89e7f92 commit 63ecc76
Showing 1 changed file with 56 additions and 6 deletions.
62 changes: 56 additions & 6 deletions __tests__/users/App.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const puppeteer = require('puppeteer');
const { filteredUsersData } = require('../../mock-data/users');
const { mockUserData } = require('../../mock-data/users/mockdata');
const API_BASE_URL = 'https://staging-api.realdevsquad.com';
const API_BASE_URL = 'https://api.realdevsquad.com';

describe('App Component', () => {
let browser;
Expand Down Expand Up @@ -37,9 +37,13 @@ describe('App Component', () => {
headers,
body: JSON.stringify({
...filteredUsersData,
users: filteredUsersData.users.filter(
(user) => user.roles.in_discord,
),
...mockUserData,
users: [
...filteredUsersData.users.filter(
(user) => user.roles.in_discord,
),
...mockUserData.users.filter((user) => user.roles.in_discord),
],
}),
});
} else if (url === `${API_BASE_URL}/users/search/?verified=true`) {
Expand All @@ -49,9 +53,11 @@ describe('App Component', () => {
headers,
body: JSON.stringify({
...filteredUsersData,
users: filteredUsersData.users.filter((user) => user.discordId),
...mockUserData,
users: mockUserData.users.filter((user) => user.discordId),
users: [
...filteredUsersData.users.filter((user) => user.discordId),
...mockUserData.users.filter((user) => user.discordId),
],
}),
});
} else {
Expand Down Expand Up @@ -96,4 +102,48 @@ describe('App Component', () => {
const url = await page.url();
expect(url).toContain('?tab=verified');
});

it('should handle user card clicks and apply active_tab class to clicked card only in discord tab', async () => {
await page.goto(`${BASE_URL}/users/discord/?tab=in_discord`);
await page.waitForNetworkIdle();
await page.waitForSelector('.user_card[data-key]');
const userCardTestIds = await page.$$eval(
'[data-testid^="user-card-"]',
(cards) => cards.map((card) => card.getAttribute('data-testid')),
);
for (let i = 0; i < userCardTestIds.length; i++) {
const userCardSelector = `[data-testid="${userCardTestIds[i]}"]`;
const userCardElement = await page.$(userCardSelector);
await userCardElement.click();
await page.waitForTimeout(1000);
const isActive = await page.evaluate((selector) => {
return document
.querySelector(selector)
?.classList.contains('active_tab');
}, userCardSelector);
expect(isActive).toBe(true);
}
});

it('should handle user card clicks and apply active_tab class to clicked card only verified tab', async () => {
await page.goto(`${BASE_URL}/users/discord/?tab=verified`);
await page.waitForNetworkIdle();
await page.waitForSelector('.user_card[data-key]');
const userCardTestIds = await page.$$eval(
'[data-testid^="user-card-"]',
(cards) => cards.map((card) => card.getAttribute('data-testid')),
);
for (let i = 0; i < userCardTestIds.length; i++) {
const userCardSelector = `[data-testid="${userCardTestIds[i]}"]`;
const userCardElement = await page.$(userCardSelector);
await userCardElement.click();
await page.waitForTimeout(1000);
const isActive = await page.evaluate((selector) => {
return document
.querySelector(selector)
?.classList.contains('active_tab');
}, userCardSelector);
expect(isActive).toBe(true);
}
});
});

0 comments on commit 63ecc76

Please sign in to comment.