diff --git a/__tests__/discord-groups/discord-group.test.js b/__tests__/groups/group.test.js similarity index 85% rename from __tests__/discord-groups/discord-group.test.js rename to __tests__/groups/group.test.js index 41a00de6..146542cc 100644 --- a/__tests__/discord-groups/discord-group.test.js +++ b/__tests__/groups/group.test.js @@ -1,7 +1,7 @@ const puppeteer = require('puppeteer'); const { allUsersData } = require('../../mock-data/users'); const { API_BASE_URL } = require('../../constants'); -const { discordGroups } = require('../../mock-data/discord-groups'); +const { discordGroups } = require('../../mock-data/groups'); const BASE_URL = 'https://api.realdevsquad.com'; @@ -99,7 +99,7 @@ describe('Discord Groups Page', () => { interceptedRequest.continue(); } }); - await page.goto('http://localhost:8000/discord-groups'); + await page.goto('http://localhost:8000/groups'); await page.waitForNetworkIdle(); }); @@ -133,7 +133,7 @@ describe('Discord Groups Page', () => { '.group-role', (list) => list.length, ); - expect(groupListLength).toBe(1); + expect(groupListLength).toBe(3); }); test('Should not display an error message if the role name contains "group"', async () => { @@ -165,4 +165,28 @@ describe('Discord Groups Page', () => { await createGroupBtn.click(); await expect(alertMessage).toContain("Roles cannot contain 'group'."); }); + + test('Filter groups based on search input', async () => { + const searchInput = await page.$('#search-groups'); + await searchInput.type('DSA'); + + const filteredGroupNames = await page.$$eval('.group-role', (elements) => { + return elements + .map((element) => element.querySelector('.group-name').textContent) + .filter((name) => name.includes('DSA')); + }); + + expect(filteredGroupNames).toEqual( + expect.arrayContaining(['group-DSA', 'group-DSA-Coding-Group']), + ); + }); + + test('should update the URL when a group role is clicked', async () => { + await page.$$eval('.group-role', (elements) => { + elements[1].click(); + }); + const url = await page.url(); + const searchParams = decodeURIComponent(url.split('?')[1]); + expect(searchParams).toMatch('group-DSA'); + }); }); diff --git a/__tests__/standup/standup.test.js b/__tests__/standup/standup.test.js new file mode 100644 index 00000000..02736c4d --- /dev/null +++ b/__tests__/standup/standup.test.js @@ -0,0 +1,118 @@ +const puppeteer = require('puppeteer'); +const API_BASE_URL = 'https://staging-api.realdevsquad.com'; +const { user } = require('../../mock-data/users'); +const { standup } = require('../../mock-data/standup'); + +describe('Standup Page', () => { + let browser; + let page; + jest.setTimeout(60000); + + beforeAll(async () => { + browser = await puppeteer.launch({ + headless: true, + ignoreHTTPSErrors: true, + args: ['--incognito', '--disable-web-security'], + devtools: false, + }); + page = await browser.newPage(); + + await page.setRequestInterception(true); + + page.on('request', (interceptedRequest) => { + const url = interceptedRequest.url(); + + if (url === `${API_BASE_URL}/users/sunny`) { + 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(user), + }); + } else if ( + url === `${API_BASE_URL}/progresses?userId=YleviOe1SsOML8eitV9W` + ) { + 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(standup), + }); + } else { + interceptedRequest.continue(); + } + }); + await page.goto('http://localhost:8000/standup'); + await page.waitForNetworkIdle(); + }); + + afterAll(async () => { + await browser.close(); + }); + + it('should display the table when the search button is clicked', async () => { + const userInput = await page.$('#user-search-input'); + const searchButton = await page.$('#search-button'); + + await userInput.type('sunny'); + await searchButton.click(); + await page.waitForSelector('#table-container'); + const table = await page.$('.user-standup-table'); + expect(table).toBeTruthy(); + }); + + it('should display the loader when the search button is clicked', async () => { + const userInput = await page.$('#user-search-input'); + const searchButton = await page.$('#search-button'); + + await userInput.type('sunny'); + await searchButton.click(); + await page.waitForSelector('#table-container'); + const loader = await page.$('.loader'); + expect(loader).toBeTruthy(); + }); + + it('should update the URL with the query parameter when the user writes a name', async () => { + const userInput = await page.$('#user-search-input'); + const searchButton = await page.$('#search-button'); + await userInput.click({ clickCount: 3 }); + await userInput.press('Backspace'); + await userInput.type('sunny'); + await searchButton.click(); + await page.waitForTimeout(1000); + const updatedUrl = page.url(); + expect(updatedUrl).toContain('q=user:sunny'); + }); + + it('should update the URL with the query parameter when the user writes multiple names', async () => { + const userInput = await page.$('#user-search-input'); + const searchButton = await page.$('#search-button'); + await userInput.click({ clickCount: 3 }); + await userInput.press('Backspace'); + await userInput.type('sunny,pratiyush'); + await searchButton.click(); + await page.waitForTimeout(1000); + const updatedUrl = page.url(); + expect(updatedUrl).toContain('q=user:sunny+user:pratiyush'); + }); + + it('should update the URL with the query parameter when the user writes duplicate names', async () => { + const userInput = await page.$('#user-search-input'); + const searchButton = await page.$('#search-button'); + await userInput.click({ clickCount: 3 }); + await userInput.press('Backspace'); + await userInput.type('sunny,sunny,pratiyush'); + await searchButton.click(); + await page.waitForTimeout(1000); + const updatedUrl = page.url(); + expect(updatedUrl).toContain('q=user:sunny+user:pratiyush'); + }); +}); diff --git a/discord-groups/constants.js b/groups/constants.js similarity index 100% rename from discord-groups/constants.js rename to groups/constants.js diff --git a/discord-groups/index.html b/groups/index.html similarity index 83% rename from discord-groups/index.html rename to groups/index.html index 9ee857ab..c5e25462 100644 --- a/discord-groups/index.html +++ b/groups/index.html @@ -7,9 +7,9 @@ Discord Groups | Real Dev Squad - + - +