Skip to content

Commit

Permalink
test: add coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
RRanath committed May 15, 2024
1 parent fa40d6d commit 3043e70
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions app/tests/components/Analyst/PendingChangeRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@ import compiledQuery, {
} from '__generated__/PendingChangeRequestTestQuery.graphql';
import { act, screen, fireEvent } from '@testing-library/react';
import { PendingChangeRequest } from 'components/Analyst';
import { performQuery } from '../../../backend/lib/graphql';
import ComponentTestingHelper from '../../utils/componentTestingHelper';

jest.mock('../../../backend/lib/graphql', () => ({
performQuery: jest.fn(),
}));

const testQuery = graphql`
query PendingChangeRequestTestQuery($rowId: Int!) {
applicationByRowId(rowId: $rowId) {
Expand Down Expand Up @@ -305,4 +310,60 @@ describe('The Pending Change Request component', () => {
}
);
});

it('pending change request comment edit close button handle modal close only', async () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();

const commentIcon = screen.getByTestId('pending-change-request-comments');

expect(commentIcon).toBeVisible();

await act(async () => {
fireEvent.click(commentIcon);
});

expect(
screen.getByText('Comments on pending changes (optional)')
).toBeVisible();

const cancelButton = screen.getByRole('button', { name: 'Cancel' });

await act(async () => {
fireEvent.click(cancelButton);
});

expect(
screen.getByText('Comments on pending changes (optional)')
).not.toBeVisible();

expect(performQuery).not.toHaveBeenCalled();
});

it('Closing change request modal keep pending button closes modal and keep change request', async () => {
componentTestingHelper.loadQuery();
componentTestingHelper.renderComponent();

const checkbox = screen.getByTestId('pending-change-request-checkbox');

expect(checkbox).toBeVisible();

await act(async () => {
fireEvent.click(checkbox);
});

const cancelButton = screen.getByRole('button', {
name: 'No, Keep Pending',
});

await act(async () => {
fireEvent.click(cancelButton);
});

expect(
screen.getByText('Done with this change request?')
).not.toBeVisible();

expect(performQuery).not.toHaveBeenCalled();
});
});

0 comments on commit 3043e70

Please sign in to comment.