Skip to content

Commit

Permalink
PRMP-310 - LG "Remove all files" show Spinner button (#380)
Browse files Browse the repository at this point in the history
* [PRMP-310] add unit test for spinner button, make spinner button appear when deletion taken place

* [PRMP-310] remove unused prop setIsDeletingDocuments

* remove unused mock function
  • Loading branch information
joefong-nhs authored Jun 13, 2024
1 parent bc126bb commit 7a16e16
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import usePatient from '../../../../helpers/hooks/usePatient';
import { runAxeTest } from '../../../../helpers/test/axeTestHelper';
import { MemoryHistory, createMemoryHistory } from 'history';
import * as ReactRouter from 'react-router';
import waitForSeconds from '../../../../helpers/utils/waitForSeconds';

jest.mock('../../../../helpers/hooks/useConfig');
jest.mock('../deleteResultStage/DeleteResultStage', () => () => <div>Deletion complete</div>);
Expand Down Expand Up @@ -44,8 +45,6 @@ const mockPatientDetails = buildPatientDetails();
const mockLgSearchResult = buildLgSearchResult();

const mockSetStage = jest.fn();
const mockSetIsDeletingDocuments = jest.fn();
const mockSetDownloadStage = jest.fn();

describe('DeleteSubmitStage', () => {
beforeEach(() => {
Expand Down Expand Up @@ -261,6 +260,22 @@ describe('DeleteSubmitStage', () => {
),
).toBeInTheDocument();
});

it('change the button to spinner button when deletion is taken place in background', async () => {
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);
mockedAxios.delete.mockReturnValue(waitForSeconds(1));

renderComponent(DOCUMENT_TYPE.LLOYD_GEORGE, history);

act(() => {
userEvent.click(screen.getByRole('radio', { name: 'Yes' }));
userEvent.click(screen.getByRole('button', { name: 'Continue' }));
});

await waitFor(() => {
expect(screen.getByTestId('delete-submit-spinner-btn')).toBeInTheDocument();
});
});
});

describe('Accessibility', () => {
Expand Down Expand Up @@ -325,15 +340,15 @@ describe('Navigation', () => {
});

const renderComponent = (docType: DOCUMENT_TYPE, history: MemoryHistory) => {
const props: Omit<Props, 'setStage' | 'setIsDeletingDocuments' | 'setDownloadStage'> = {
const props: Omit<Props, 'setStage' | 'setDownloadStage'> = {
numberOfFiles: mockLgSearchResult.number_of_files,
docType,
recordType: docType.toString(),
};

return render(
<ReactRouter.Router navigator={history} location={history.location}>
<DeleteSubmitStage {...props} setIsDeletingDocuments={mockSetIsDeletingDocuments} />,
<DeleteSubmitStage {...props} />,
</ReactRouter.Router>,
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import DeleteResultStage from '../deleteResultStage/DeleteResultStage';
export type Props = {
docType: DOCUMENT_TYPE;
numberOfFiles: number;
setIsDeletingDocuments?: Dispatch<boolean>;
setDownloadStage?: Dispatch<SetStateAction<DOWNLOAD_STAGE>>;
recordType: string;
};
Expand All @@ -40,13 +39,7 @@ enum DELETE_DOCUMENTS_OPTION {
NO = 'no',
}

function DeleteSubmitStage({
docType,
numberOfFiles,
setIsDeletingDocuments,
setDownloadStage,
recordType,
}: Props) {
function DeleteSubmitStage({ docType, numberOfFiles, setDownloadStage, recordType }: Props) {
const patientDetails = usePatient();
const role = useRole();
const { register, handleSubmit } = useForm();
Expand All @@ -73,6 +66,7 @@ function DeleteSubmitStage({
}
};
try {
setDeletionStage(SUBMISSION_STATE.PENDING);
const response: DeleteResponse = await deleteAllDocuments({
docType: docType,
nhsNumber: nhsNumber,
Expand Down Expand Up @@ -177,7 +171,12 @@ function DeleteSubmitStage({
</Radios>
</Fieldset>
{deletionStage === SUBMISSION_STATE.PENDING ? (
<SpinnerButton id="delete-docs-spinner" status="Deleting..." disabled={true} />
<SpinnerButton
id="delete-docs-spinner"
dataTestId="delete-submit-spinner-btn"
status="Deleting..."
disabled={true}
/>
) : (
<Button type="submit" id="delete-submit-button" data-testid="delete-submit-btn">
Continue
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ function DocumentSearchResultsPage() {
<DeleteSubmitStage
recordType="ARF"
numberOfFiles={searchResults.length}
setIsDeletingDocuments={setIsDeletingDocuments}
docType={DOCUMENT_TYPE.ALL}
/>
}
Expand Down

0 comments on commit 7a16e16

Please sign in to comment.