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 @@ -14,6 +14,8 @@ import * as getReviewsModule from '../../../../helpers/requests/getReviews';
import { DOCUMENT_TYPE } from '../../../../helpers/utils/documentType';

const mockedUseNavigate = vi.fn();
const mockSetPatientDetails = vi.fn();
const mockUsePatientDetailsContext = vi.fn();

vi.mock('../../../../helpers/utils/getPdfObjectUrl', () => ({
getPdfObjectUrl: vi.fn().mockResolvedValue(200),
Expand Down Expand Up @@ -91,6 +93,10 @@ vi.mock(
}),
);

vi.mock('../../../../providers/patientProvider/PatientProvider', () => ({
usePatientDetailsContext: (): unknown => mockUsePatientDetailsContext(),
}));

const mockSetReviewData = vi.fn();
const mockSetDownloadStage = vi.fn();

Expand Down Expand Up @@ -175,6 +181,8 @@ describe('ReviewDetailsAssessmentPage', () => {

describe('Rendering', () => {
it('displays spinner when reviewData is null', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={null}
Expand All @@ -190,6 +198,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('displays spinner only when uploadDocuments is null/undefined or reviewData is null', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const { rerender } = render(
<ReviewDetailsAssessmentStage
reviewData={null}
Expand Down Expand Up @@ -220,6 +230,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('renders page title for review with existing and new files', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(true, true, true)}
Expand All @@ -237,6 +249,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('renders accept/reject radio buttons when only canBeDiscarded is true', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(
Expand All @@ -258,6 +272,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('renders add-all and choose-files radio buttons when no existing record', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(true, true, false)}
Expand All @@ -277,6 +293,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('renders all radio options when has existing record in storage', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(true, true, true)}
Expand Down Expand Up @@ -304,6 +322,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('displays existing files table when available', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(true, true, true)}
Expand All @@ -319,6 +339,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('displays new files table', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData(true, true, true)}
Expand All @@ -336,6 +358,8 @@ describe('ReviewDetailsAssessmentPage', () => {
});

it('displays "all files" viewing message by default', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData()}
Expand All @@ -349,6 +373,26 @@ describe('ReviewDetailsAssessmentPage', () => {

expect(screen.getByText('You are currently viewing: all files')).toBeInTheDocument();
});

it('displays patient demographics', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsAssessmentStage
reviewData={createMockReviewData()}
setReviewData={mockSetReviewData}
uploadDocuments={createMockUploadDocuments()}
downloadStage={DOWNLOAD_STAGE.SUCCEEDED}
setDownloadStage={mockSetDownloadStage}
hasExistingRecordInStorage={false}
/>,
);

expect(screen.getByTestId('patient-summary')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-full-name')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-nhs-number')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-date-of-birth')).toBeInTheDocument();
});
});

describe('File viewing', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
import DocumentUploadLloydGeorgePreview from '../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import { AxiosError } from 'axios';
import { errorToParams } from '../../../../helpers/utils/errorToParams';
import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/PatientSummary';

type FileAction = 'add-all' | 'choose-files' | 'duplicate' | 'accept' | 'reject' | '';

Expand Down Expand Up @@ -327,6 +328,14 @@ const ReviewDetailsAssessmentStage = ({

<h1>{pageTitle}</h1>

<div className="nhsuk-inset-text">
<PatientSummary>
<PatientSummary.Child item={PatientInfo.FULL_NAME} />
<PatientSummary.Child item={PatientInfo.NHS_NUMBER} />
<PatientSummary.Child item={PatientInfo.BIRTH_DATE} />
</PatientSummary>
</div>

{canBeUpdatedAndDiscarded && reviewData.existingFiles!.length > 0 && (
<ExistingRecordTable
existingFiles={reviewData.existingFiles!}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ vi.mock('../../../../helpers/hooks/useTitle', () => ({
}));

const mockNavigate = vi.fn();
const mockSetPatientDetails = vi.fn();
const mockUsePatientDetailsContext = vi.fn();
const mockReviewId = 'test-review-123';
let currentReviewId: string | undefined = mockReviewId;

Expand All @@ -30,6 +32,10 @@ vi.mock('react-router-dom', async (): Promise<unknown> => {
};
});

vi.mock('../../../../providers/patientProvider/PatientProvider', () => ({
usePatientDetailsContext: (): unknown => mockUsePatientDetailsContext(),
}));

const mockGetConfigForDocType = getConfigForDocType as Mock;

const makeReviewDoc = (
Expand Down Expand Up @@ -76,6 +82,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('renders a spinner when reviewData is null', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

render(
<ReviewDetailsFileSelectStage
reviewData={null}
Expand All @@ -88,6 +96,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('renders heading and only shows REVIEW documents in the table', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const documents: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.UNSELECTED, UploadDocumentType.REVIEW),
makeReviewDoc(
Expand Down Expand Up @@ -116,7 +126,36 @@ describe('ReviewDetailsFileSelectStage', () => {
expect(screen.queryByText('existing.pdf')).not.toBeInTheDocument();
});

it('renders patient demograhics', () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const documents: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.UNSELECTED, UploadDocumentType.REVIEW),
makeReviewDoc(
'existing.pdf',
DOCUMENT_UPLOAD_STATE.UNSELECTED,
UploadDocumentType.EXISTING,
),
];

render(
<ReviewDetailsFileSelectStage
reviewData={mockReviewData}
uploadDocuments={documents}
setUploadDocuments={vi.fn() as any}
/>,
);

expect(screen.getByTestId('patient-summary')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-full-name')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-nhs-number')).toBeInTheDocument();
expect(screen.getByTestId('patient-summary-date-of-birth')).toBeInTheDocument();

});

it('allows viewing a selected file and passes the object URL to the PDF viewer', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const user = userEvent.setup();
const documents: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.UNSELECTED, UploadDocumentType.REVIEW),
Expand Down Expand Up @@ -165,6 +204,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('clears the error summary after selecting a file', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const user = userEvent.setup();
const initialDocs: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.UNSELECTED, UploadDocumentType.REVIEW),
Expand Down Expand Up @@ -194,6 +235,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('navigates to add-more-choice when all files are selected', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const user = userEvent.setup();
const initialDocs: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.SELECTED, UploadDocumentType.REVIEW),
Expand All @@ -217,6 +260,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('navigates to download-choice when some files are unselected', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const user = userEvent.setup();
const initialDocs: ReviewUploadDocument[] = [
makeReviewDoc('file1.pdf', DOCUMENT_UPLOAD_STATE.SELECTED, UploadDocumentType.REVIEW),
Expand All @@ -238,6 +283,8 @@ describe('ReviewDetailsFileSelectStage', () => {
});

it('does not navigate if reviewId is missing', async () => {
mockUsePatientDetailsContext.mockReturnValue([null, mockSetPatientDetails]);

const user = userEvent.setup();
currentReviewId = undefined;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
ReviewUploadDocument,
UploadDocumentType,
} from '../../../../types/pages/UploadDocumentsPage/types';
import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/PatientSummary';

export type ReviewDetailsFileSelectStageProps = {
reviewData: ReviewDetails | null;
Expand Down Expand Up @@ -142,6 +143,14 @@ const ReviewDetailsFileSelectStage = ({

<h1>Choose files to add to the existing {reviewTypeLabel.toSentenceCase()}</h1>

<div className="nhsuk-inset-text">
<PatientSummary>
<PatientSummary.Child item={PatientInfo.FULL_NAME} />
<PatientSummary.Child item={PatientInfo.NHS_NUMBER} />
<PatientSummary.Child item={PatientInfo.BIRTH_DATE} />
</PatientSummary>
</div>

<section id="new-files-table" className="new-files mb-4">
<h2>New files</h2>
<form>
Expand Down
Loading