|
3 | 3 | urlMappings,
|
4 | 4 | defaultMockResponseHeaders,
|
5 | 5 | } = require('../../mock-data/taskRequests');
|
| 6 | +const { user } = require('../../mock-data/users/index.js'); |
| 7 | + |
| 8 | +describe('Request container for non-super users', () => { |
| 9 | + let browser; |
| 10 | + let page; |
| 11 | + jest.setTimeout(60000); |
| 12 | + |
| 13 | + beforeAll(async () => { |
| 14 | + browser = await puppeteer.launch({ |
| 15 | + headless: 'new', |
| 16 | + ignoreHTTPSErrors: true, |
| 17 | + args: ['--incognito', '--disable-web-security'], |
| 18 | + devtools: false, |
| 19 | + }); |
| 20 | + page = await browser.newPage(); |
| 21 | + await page.setRequestInterception(true); |
| 22 | + page.on('request', (interceptedRequest) => { |
| 23 | + const url = interceptedRequest.url(); |
| 24 | + if (url == 'https://staging-api.realdevsquad.com/users/self') { |
| 25 | + interceptedRequest.respond({ |
| 26 | + ...defaultMockResponseHeaders, |
| 27 | + body: JSON.stringify(user), |
| 28 | + }); |
| 29 | + } else if (urlMappings.hasOwnProperty(url)) { |
| 30 | + interceptedRequest.respond({ |
| 31 | + ...defaultMockResponseHeaders, |
| 32 | + body: JSON.stringify(urlMappings[url]), |
| 33 | + }); |
| 34 | + } else { |
| 35 | + interceptedRequest.continue(); |
| 36 | + } |
| 37 | + }); |
| 38 | + await page.goto( |
| 39 | + 'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&dev=true', |
| 40 | + ); |
| 41 | + }); |
| 42 | + |
| 43 | + afterAll(async () => { |
| 44 | + await browser.close(); |
| 45 | + }); |
| 46 | + |
| 47 | + it('Approve and Reject buttons should not render for non-super users', async function () { |
| 48 | + await page.waitForNetworkIdle(); |
| 49 | + const approveButton = await page.$('[data-testid="task-approve-button"]'); |
| 50 | + const rejectButton = await page.$('[data-testid="task-reject-button"]'); |
| 51 | + expect(approveButton).toBeNull(); |
| 52 | + expect(rejectButton).toBeNull(); |
| 53 | + }); |
| 54 | + |
| 55 | + it('Should render task status for non-super users', async function () { |
| 56 | + await page.waitForNetworkIdle(); |
| 57 | + const taskRequestStatus = await page.$( |
| 58 | + '[data-testid="requestors-task-status"]', |
| 59 | + ); |
| 60 | + expect(taskRequestStatus).toBeTruthy(); |
| 61 | + }); |
| 62 | +}); |
6 | 63 |
|
7 | 64 | describe('Task request details page', () => {
|
8 | 65 | let browser;
|
@@ -89,9 +146,13 @@ describe('Task request details page', () => {
|
89 | 146 | );
|
90 | 147 | });
|
91 | 148 |
|
92 |
| - it('Should contain Approve and Reject buttons', async function () { |
93 |
| - const approveButton = await page.$('.requestors__conatainer__list__button'); |
94 |
| - const rejectButton = await page.$('.request-details__reject__button'); |
| 149 | + it('Should render Approve and Reject buttons for super users', async function () { |
| 150 | + await page.goto( |
| 151 | + 'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq5&dev=true', |
| 152 | + ); |
| 153 | + await page.waitForNetworkIdle(); |
| 154 | + const approveButton = await page.$('[data-testid="task-approve-button"]'); |
| 155 | + const rejectButton = await page.$('[data-testid="task-reject-button"]'); |
95 | 156 | expect(approveButton).toBeTruthy();
|
96 | 157 | expect(rejectButton).toBeTruthy();
|
97 | 158 | });
|
@@ -180,9 +241,13 @@ describe('Task request details page with markdown support in description', () =>
|
180 | 241 | expect(descriptionHtmlValue).toContain('<h3 id="heading">Heading</h3>');
|
181 | 242 | });
|
182 | 243 |
|
183 |
| - it('Should contain Approve and Reject buttons', async function () { |
184 |
| - const approveButton = await page.$('.requestors__conatainer__list__button'); |
185 |
| - const rejectButton = await page.$('.request-details__reject__button'); |
| 244 | + it('Should render Approve and Reject buttons for super users', async function () { |
| 245 | + await page.goto( |
| 246 | + 'http://localhost:8000/task-requests/details/?id=dM5wwD9QsiTzi7eG7Oq6&dev=true', |
| 247 | + ); |
| 248 | + await page.waitForNetworkIdle(); |
| 249 | + const approveButton = await page.$('[data-testid="task-approve-button"]'); |
| 250 | + const rejectButton = await page.$('[data-testid="task-reject-button"]'); |
186 | 251 | expect(approveButton).toBeTruthy();
|
187 | 252 | expect(rejectButton).toBeTruthy();
|
188 | 253 | });
|
|
0 commit comments