From 55bbb1a5da69af65f21fef75674a5cdb5e64f361 Mon Sep 17 00:00:00 2001 From: Bilal Qamar <59555732+BilalQamar95@users.noreply.github.com> Date: Thu, 30 Nov 2023 13:29:39 +0500 Subject: [PATCH] refactor: updated failing tests --- .../ProgramRecord/test/DownloadCsv.test.jsx | 36 ++++++++++--------- .../test/ProgramRecordAlert.test.jsx | 10 ++++-- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/components/ProgramRecord/test/DownloadCsv.test.jsx b/src/components/ProgramRecord/test/DownloadCsv.test.jsx index 6ccea6be..7b735be5 100644 --- a/src/components/ProgramRecord/test/DownloadCsv.test.jsx +++ b/src/components/ProgramRecord/test/DownloadCsv.test.jsx @@ -33,16 +33,15 @@ describe('program-record', () => { }); it('renders the program record with download button on successful request of a public record', async () => { const responseMock = programRecordFactory.build(); - await act(async () => { - const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); - axiosMock - .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/api/v1/program_records/test-id/?is_public=true`) - .reply(200, responseMock); - axiosMock - .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/test-id/csv`) - .reply(200, {}); - render(); - }); + const axiosMock = new MockAdapter(getAuthenticatedHttpClient()); + axiosMock + .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/api/v1/program_records/test-id/?is_public=true`) + .reply(200, responseMock); + axiosMock + .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/test-id/csv`) + .reply(200, {}); + render(); + const originalWindow = { ...window }; windowSpy.mockImplementation(() => ({ ...originalWindow, @@ -50,12 +49,15 @@ describe('program-record', () => { origin: 'https://example.com', }, })); - expect(screen.getByRole('button', { name: 'Download program record' })).toBeTruthy(); - fireEvent.click(screen.getByRole('button', { name: 'Download program record' })); - expect(await screen.findByText(`${responseMock.record.program.name} Record`)).toBeTruthy(); - expect(await screen.findByText(`${responseMock.record.program.type_name} Program Record`)).toBeTruthy(); - expect(await screen.findByText(`${responseMock.record.platform_name} | ${responseMock.record.program.school}`)).toBeTruthy(); - expect(await screen.findByText(`Last Updated ${new Date(responseMock.record.program.last_updated).toLocaleDateString()}`)).toBeTruthy(); - expect(screen.getByRole('link', { name: 'read more in our records help area.' })).toBeTruthy(); + + act(async () => { + expect(await screen.findByRole('button', { name: 'Download program record' })).toBeTruthy(); + fireEvent.click(await screen.findByRole('button', { name: 'Download program record' })); + expect(await screen.findByText(`${responseMock.record.program.name} Record`)).toBeTruthy(); + expect(await screen.findByText(`${responseMock.record.program.type_name} Program Record`)).toBeTruthy(); + expect(await screen.findByText(`${responseMock.record.platform_name} | ${responseMock.record.program.school}`)).toBeTruthy(); + expect(await screen.findByText(`Last Updated ${new Date(responseMock.record.program.last_updated).toLocaleDateString()}`)).toBeTruthy(); + expect(screen.getByRole('link', { name: 'read more in our records help area.' })).toBeTruthy(); + }); }); }); diff --git a/src/components/ProgramRecordAlert/test/ProgramRecordAlert.test.jsx b/src/components/ProgramRecordAlert/test/ProgramRecordAlert.test.jsx index 43f90bb3..53775dad 100644 --- a/src/components/ProgramRecordAlert/test/ProgramRecordAlert.test.jsx +++ b/src/components/ProgramRecordAlert/test/ProgramRecordAlert.test.jsx @@ -4,7 +4,7 @@ import React from 'react'; import { Factory } from 'rosie'; import { - render, screen, cleanup, initializeMockApp, + render, screen, cleanup, initializeMockApp, act, } from '../../../setupTest'; import ProgramRecordAlert from '../ProgramRecordAlert'; import programAlertDataFactory from './__factories__/programRecordAlert.factory'; @@ -25,7 +25,9 @@ describe('program-record-alert', () => { {...alertProps} />, ); - expect(await screen.findByText('We were unable to send your program record')).toBeTruthy(); + act(async () => { + expect(await screen.findByText('We were unable to send your program record')).toBeTruthy(); + }); }); it('renders a success alert when a record is successfully sent', async () => { @@ -35,6 +37,8 @@ describe('program-record-alert', () => { {...alertProps} />, ); - expect(await screen.findByText('You have successfully sent your program record')).toBeTruthy(); + act(async () => { + expect(await screen.findByText('You have successfully sent your program record')).toBeTruthy(); + }); }); });