Skip to content

Commit

Permalink
refactor: updated failing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
BilalQamar95 committed Nov 30, 2023
1 parent 693413e commit 55bbb1a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
36 changes: 19 additions & 17 deletions src/components/ProgramRecord/test/DownloadCsv.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,29 +33,31 @@ 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(<ProgramRecord isPublic />);
});
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(<ProgramRecord isPublic />);

const originalWindow = { ...window };
windowSpy.mockImplementation(() => ({
...originalWindow,
location: {
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();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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 () => {
Expand All @@ -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();
});
});
});

0 comments on commit 55bbb1a

Please sign in to comment.