Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { beforeEach, describe, expect, it, vi, Mock } from 'vitest';
import ReviewDetailsCompleteStage, { getReviewStatus } from './ReviewDetailsCompleteStage';
import ReviewDetailsCompleteStage from './ReviewDetailsCompleteStage';
import { runAxeTest } from '../../../../helpers/test/axeTestHelper';
import { CompleteState } from '../../../../pages/adminRoutesPage/AdminRoutesPage';
import { routeChildren } from '../../../../types/generic/routes';
import { buildPatientDetails } from '../../../../helpers/test/testBuilders';
import { DOCUMENT_TYPE } from '../../../../helpers/utils/documentType';
import { DOCUMENT_UPLOAD_STATE, UploadDocument } from '../../../../types/pages/UploadDocumentsPage/types';
import {
DOCUMENT_UPLOAD_STATE,
UploadDocument,
} from '../../../../types/pages/UploadDocumentsPage/types';
import { DocumentReviewStatus } from '../../../../types/blocks/documentReview';
import { patchReview } from '../../../../helpers/requests/patchReviews';
import { ReviewDetails } from '../../../../types/generic/reviews';
Expand Down Expand Up @@ -64,32 +67,6 @@ describe('ReviewDetailsCompletePage', () => {
mockUsePatientDetailsContext.mockReturnValue([mockPatientDetails, mockSetPatientDetails]);
});

describe('getReviewStatus', () => {
it('maps PATIENT_MATCHED to REASSIGNED', () => {
expect(getReviewStatus(CompleteState.PATIENT_MATCHED)).toBe(
DocumentReviewStatus.REASSIGNED,
);
});

it('maps PATIENT_UNKNOWN to REASSIGNED_PATIENT_UNKNOWN', () => {
expect(getReviewStatus(CompleteState.PATIENT_UNKNOWN)).toBe(
DocumentReviewStatus.REASSIGNED_PATIENT_UNKNOWN,
);
});

it('maps NO_FILES_CHOICE to REJECTED', () => {
expect(getReviewStatus(CompleteState.NO_FILES_CHOICE)).toBe(
DocumentReviewStatus.REJECTED,
);
});

it('defaults to APPROVED (e.g. REVIEW_COMPLETE)', () => {
expect(getReviewStatus(CompleteState.REVIEW_COMPLETE)).toBe(
DocumentReviewStatus.APPROVED,
);
});
});

describe('Rendering', () => {
it('renders the page with correct test id', () => {
render(
Expand Down Expand Up @@ -128,7 +105,7 @@ describe('ReviewDetailsCompletePage', () => {
);

expect(
screen.getByRole('button', { name: 'Review another document' }),
screen.getByRole('button', { name: 'Go to Documents to Review' }),
).toBeInTheDocument();
});
});
Expand Down Expand Up @@ -439,10 +416,10 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

expect(screen.getByRole('heading', { name: 'Review complete' })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Upload complete' })).toBeInTheDocument();
});

it('renders correct panel body message', () => {
it('renders completion message', () => {
render(
<ReviewDetailsCompleteStage
completeState={CompleteState.REVIEW_COMPLETE}
Expand All @@ -453,7 +430,7 @@ describe('ReviewDetailsCompletePage', () => {

expect(
screen.getByText(
/You've completed the review of this document. It has been removed from your list/,
/You have completed the review of this document. It has been removed from your list of documents to review/,
),
).toBeInTheDocument();
});
Expand Down Expand Up @@ -494,7 +471,7 @@ describe('ReviewDetailsCompletePage', () => {
expect(screen.getByTestId('dob')).toHaveTextContent('Date of birth: 1 January 1970');
});

it('renders files added section', () => {
it('renders "What to do next" heading', () => {
render(
<ReviewDetailsCompleteStage
completeState={CompleteState.REVIEW_COMPLETE}
Expand All @@ -503,13 +480,10 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

expect(
screen.getByRole('heading', { name: 'Files added for this patient' }),
).toBeInTheDocument();
expect(screen.getByText('LloydGeorgerecords.zip')).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'What to do next' })).toBeInTheDocument();
});

it('renders "What happens next" heading', () => {
it('renders ordered list with instructions', () => {
render(
<ReviewDetailsCompleteStage
completeState={CompleteState.REVIEW_COMPLETE}
Expand All @@ -518,10 +492,22 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

expect(screen.getByRole('heading', { name: 'What happens next' })).toBeInTheDocument();
expect(
screen.getByText(
/You'll find this document in the patient's record within this service/,
),
).toBeInTheDocument();
expect(
screen.getByText(/Follow your usual process for managing a new patient record/),
).toBeInTheDocument();
expect(
screen.getByText(
/When you've done this, you can remove any digital copies of these files/,
),
).toBeInTheDocument();
});

it('does not render duplicate "What happens next" heading outside panel', () => {
it('renders link to search for patient', () => {
render(
<ReviewDetailsCompleteStage
completeState={CompleteState.REVIEW_COMPLETE}
Expand All @@ -530,8 +516,9 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

const headings = screen.getAllByRole('heading', { name: 'What happens next' });
expect(headings).toHaveLength(1);
const searchLink = screen.getByRole('link', { name: 'searching using their NHS number' });
expect(searchLink).toBeInTheDocument();
expect(searchLink).toHaveAttribute('href', '/patient/search');
});

it('renders PRM team contact email link', () => {
Expand Down Expand Up @@ -590,7 +577,7 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

const button = screen.getByRole('button', { name: 'Review another document' });
const button = screen.getByRole('button', { name: 'Go to Documents to Review' });
await user.click(button);

expect(mockSetPatientDetails).toHaveBeenCalledWith(null);
Expand All @@ -607,7 +594,7 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

const button = screen.getByRole('button', { name: 'Review another document' });
const button = screen.getByRole('button', { name: 'Go to Documents to Review' });
await user.click(button);

expect(mockNavigate).toHaveBeenCalledWith(routeChildren.ADMIN_REVIEW, {
Expand All @@ -626,7 +613,7 @@ describe('ReviewDetailsCompletePage', () => {
/>,
);

const button = screen.getByRole('button', { name: 'Review another document' });
const button = screen.getByRole('button', { name: 'Go to Documents to Review' });
await user.click(button);

expect(mockSetPatientDetails).toHaveBeenCalledBefore(mockNavigate as Mock);
Expand Down Expand Up @@ -724,7 +711,7 @@ describe('ReviewDetailsCompletePage', () => {
reviewData.id,
reviewData.version,
reviewData.nhsNumber,
expectedRequest
expectedRequest,
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,6 @@ type ReviewDetailsCompleteStageProps = {
newPatientDetails?: PatientDetails;
};

export const getReviewStatus = (completeState: CompleteState): DocumentReviewStatus => {
if (completeState === CompleteState.PATIENT_MATCHED) {
return DocumentReviewStatus.REASSIGNED;
}
if (completeState === CompleteState.PATIENT_UNKNOWN) {
return DocumentReviewStatus.REASSIGNED_PATIENT_UNKNOWN;
}
if (completeState === CompleteState.NO_FILES_CHOICE) {
return DocumentReviewStatus.REJECTED;
}
return DocumentReviewStatus.APPROVED;
};

const ReviewDetailsCompleteStage = ({
completeState,
reviewData,
Expand All @@ -56,6 +43,19 @@ const ReviewDetailsCompleteStage = ({

useTitle({ pageTitle: 'Review complete' });

const getReviewStatus = (completeState: CompleteState): DocumentReviewStatus => {
if (completeState === CompleteState.PATIENT_MATCHED) {
return DocumentReviewStatus.REASSIGNED;
}
if (completeState === CompleteState.PATIENT_UNKNOWN) {
return DocumentReviewStatus.REASSIGNED_PATIENT_UNKNOWN;
}
if (completeState === CompleteState.NO_FILES_CHOICE) {
return DocumentReviewStatus.REJECTED;
}
return DocumentReviewStatus.APPROVED;
};

const patchReviewStatus = async (): Promise<void> => {
try {
setLoading(true);
Expand All @@ -66,9 +66,10 @@ const ReviewDetailsCompleteStage = ({
const status = getReviewStatus(completeState);
const req: PatchDocumentReviewRequestDto = {
reviewStatus: status,
documentReferenceId: status === DocumentReviewStatus.APPROVED
? reviewUploadDocuments[0].ref
: undefined,
documentReferenceId:
status === DocumentReviewStatus.APPROVED
? reviewUploadDocuments[0].ref
: undefined,
};
if (newPatientDetails) {
req.nhsNumber = newPatientDetails.nhsNumber;
Expand Down Expand Up @@ -126,7 +127,7 @@ const ReviewDetailsCompleteStage = ({
return 'Review complete';
}
if (completeState === CompleteState.REVIEW_COMPLETE) {
return 'Review complete';
return 'Upload complete';
}
return '';
};
Expand All @@ -141,6 +142,7 @@ const ReviewDetailsCompleteStage = ({
</p>
);
}

if (completeState === CompleteState.PATIENT_UNKNOWN) {
return (
<p>
Expand All @@ -149,6 +151,7 @@ const ReviewDetailsCompleteStage = ({
</p>
);
}

if (completeState === CompleteState.NO_FILES_CHOICE && patientDetails) {
const formattedNhsNumber = formatNhsNumber(patientDetails.nhsNumber);
const dob = getFormattedDateFromString(patientDetails.birthDate);
Expand All @@ -171,26 +174,20 @@ const ReviewDetailsCompleteStage = ({
</>
);
}

if (completeState === CompleteState.REVIEW_COMPLETE && patientDetails) {
const formattedNhsNumber = formatNhsNumber(patientDetails.nhsNumber);
const dob = getFormattedDateFromString(patientDetails.birthDate);
const patientName = getFormattedPatientFullName(patientDetails);

return (
<>
<p>
You've completed the review of this document. It has been removed from your
list of documents to review.
</p>
<div className="mt-p pt-9">
<strong data-testid="patient-name">Patient name: {patientName}</strong>
<br />
<div>
<strong data-testid="patient-name">Patient name: {patientName}</strong>
<br />
<span data-testid="nhs-number">NHS number: {formattedNhsNumber}</span>
<br />
<span data-testid="dob">Date of birth: {dob}</span>
</div>
</>
<span data-testid="nhs-number">NHS number: {formattedNhsNumber}</span>
<br />
<span data-testid="dob">Date of birth: {dob}</span>
</div>
);
}
return <></>;
Expand Down Expand Up @@ -226,9 +223,29 @@ const ReviewDetailsCompleteStage = ({
if (completeState === CompleteState.REVIEW_COMPLETE) {
return (
<>
<h2>Files added for this patient</h2>
<p>{reviewUploadDocuments.map((doc) => doc.file.name).join(', ')}</p>
<h2>What happens next</h2>
<p className="nhsuk-u-font-weight-bold nhsuk-u-font-size-22">
<strong>
You have completed the review of this document. It has been removed from
your list of documents to review.
</strong>
</p>
<h2>What to do next</h2>
<ol>
<li>
You'll find this document in the patient's record within this service,
which you can access by{' '}
<a href={routes.SEARCH_PATIENT}>searching using their NHS number</a>.
</li>
<li>
Follow your usual process for managing a new patient record. For
example, storing and summarising on the clinical system and logging any
SNOMED codes.
</li>
<li>
When you've done this, you can remove any digital copies of these files
from your computer.
</li>
</ol>
{getDefaultPrmEmailSupportMessage()}
</>
);
Expand All @@ -255,7 +272,7 @@ const ReviewDetailsCompleteStage = ({
{getBody()}

<Button data-testid="review-another-btn" type="button" onClick={OnComplete}>
Review another document
Go to Documents to Review
</Button>
</div>
);
Expand Down
Loading