Skip to content

Commit ee29e50

Browse files
Achintya-Chatterjeedevanshdixitiamitprakash
authored
tests for the extension request tab in the /request route using Puppeteer (#781)
* tabs are switching on request page * added extension-request in request page * added extension-request in request page * feat: Added the whole extension page UI * refactor: Abstract fetch logic into reusable function - Created fetchData function to handle fetch requests with different query parameters and controllers. - Updated getOooRequests and getExtensionRequests to use fetchData. * refactor: Abstract fetch logic into reusable function - Created fetchData function to handle fetch requests with different query parameters and controllers. - Updated getOooRequests and getExtensionRequests to use fetchData. * refactor: createExtensionCard function to optimize element creation - Use DocumentFragment to accumulate and append elements efficiently - Simplify element creation with template literals - Extract repetitive tasks and event listeners into separate functions - Maintain coding standards and improve readability Resolves PR comment regarding optimizing document.createElement calls in createExtensionCard function. * refactor: code refactored to show superusers the extension request * Merge branch 'feat/extension-request-page' of github.com:Real-Dev-Squad/website-dashboard into feat/extension-request-page bbbjbLines starting with '#' will be ignored, and an empty message aborts e commit. :wq Merge branch 'feat/extension-request-page' of github.com:Real-Dev-Squad/website-dashboard into feat/extension-request-page This merge is necessary to integrate the latest changes from the remote branch into the local branch. * fix: delete the mock-date, will raise the test PR separately * feat: add UI for listing extension requests with status update controls - Implemented a separate tab for listing extension requests on the /requests page. - Added functionality for super users to approve or reject extension requests directly from the UI. - Updated script.js to handle API calls for both OOO and extension requests. - Ensured correct query parameters are reflected in the URL when switching between tabs. - Improved error handling and message display for extension requests. * fix(css): center the loading text on the requests page - Updated .container__body__loader class to center the loading text both horizontally and vertically using Flexbox. * add: test for listing extension request --------- Co-authored-by: devanshdixit <[email protected]> Co-authored-by: Amit Prakash <[email protected]>
1 parent 4b62a55 commit ee29e50

File tree

2 files changed

+65
-5
lines changed

2 files changed

+65
-5
lines changed

__tests__/requests/requests.test.js

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const {
33
pendingRequest,
44
requestActionResponse,
55
approvedRequest,
6+
extensionRequest,
67
} = require('../../mock-data/requests');
78
const { allUsersData } = require('../../mock-data/users');
89

910
const API_BASE_URL = 'https://api.realdevsquad.com';
1011
const SITE_URL = 'http://localhost:8000';
1112

12-
describe('Tests the request card', () => {
13+
describe('Tests the request cards', () => {
1314
let browser;
1415
let page;
1516
jest.setTimeout(60000);
@@ -50,6 +51,19 @@ describe('Tests the request card', () => {
5051
},
5152
body: JSON.stringify(pendingRequest),
5253
});
54+
} else if (
55+
url === `${API_BASE_URL}/requests?dev=true&type=extension&size=12`
56+
) {
57+
interceptedRequest.respond({
58+
status: 200,
59+
contentType: 'application/json',
60+
headers: {
61+
'Access-Control-Allow-Origin': '*',
62+
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
63+
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
64+
},
65+
body: JSON.stringify(extensionRequest),
66+
});
5367
} else if (
5468
url === `${API_BASE_URL}/requests/Wl4TTbpSrQDIjs6KLJwD?dev=true`
5569
) {
@@ -88,7 +102,7 @@ describe('Tests the request card', () => {
88102
await browser.close();
89103
});
90104

91-
it('should update the card when the accept or reject button is clicked', async () => {
105+
it('should update the card when the accept or reject button is clicked for OOO requests', async () => {
92106
await page.waitForSelector('.request__status');
93107
const statusButtonText = await page.$eval(
94108
'.request__status',
@@ -105,4 +119,21 @@ describe('Tests the request card', () => {
105119
);
106120
expect(updatedStatusButtonText).toBe('Approved');
107121
});
122+
123+
it('should load the extension request when the extension tab is clicked', async () => {
124+
await page.click('#extension_tab_link');
125+
await page.waitForSelector('.ooo_request__card');
126+
127+
const cardTitle = await page.$eval(
128+
'.request__content p',
129+
(el) => el.textContent,
130+
);
131+
expect(cardTitle).toBe('request message');
132+
133+
const statusButtonText = await page.$eval(
134+
'.request__status',
135+
(el) => el.textContent,
136+
);
137+
expect(statusButtonText).toBe('Approved');
138+
});
108139
});

mock-data/requests/index.js

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const pendingRequest = {
88
from: 1712275200000,
99
until: 1712448000000,
1010
type: 'OOO',
11-
message: 'Testing purpose',
11+
message: 'request message',
1212
lastModifiedBy: 'V4rqL1aDecNGoa1IxiCu',
1313
state: 'PENDING',
1414
updatedAt: 1711482912686,
@@ -28,7 +28,7 @@ const approvedRequest = {
2828
from: 1712275200000,
2929
until: 1712448000000,
3030
type: 'OOO',
31-
message: 'Testing purpose',
31+
message: 'request message',
3232
lastModifiedBy: 'V4rqL1aDecNGoa1IxiCu',
3333
state: 'APPROVED',
3434
updatedAt: 1711482912686,
@@ -49,4 +49,33 @@ const requestActionResponse = {
4949
},
5050
};
5151

52-
module.exports = { pendingRequest, approvedRequest, requestActionResponse };
52+
const extensionRequest = {
53+
message: 'Request fetched successfully',
54+
data: [
55+
{
56+
id: 'TlIWPP8WPcIebsVvwzxa',
57+
createdAt: 1714946917634,
58+
requestedBy: 'iODXB6ns8jaZB9p0XlBw',
59+
requestNumber: 1,
60+
newEndsOn: 1709674980000,
61+
oldEndsOn: 1703911191.083,
62+
assignee: 'sunny',
63+
type: 'EXTENSION',
64+
title: 'Extension Request',
65+
message: 'request message',
66+
taskId: 'YofR3z5fxudqrM55iXRI',
67+
lastModifiedBy: 'V4rqL1aDecNGoa1IxiCu',
68+
state: 'APPROVED',
69+
updatedAt: 1715602207156,
70+
},
71+
],
72+
next: null,
73+
prev: null,
74+
};
75+
76+
module.exports = {
77+
pendingRequest,
78+
approvedRequest,
79+
requestActionResponse,
80+
extensionRequest,
81+
};

0 commit comments

Comments
 (0)