Skip to content
Open
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 @@ -71,7 +71,7 @@ vi.mock('./ExistingRecordTable', () => ({
}));

vi.mock(
'../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
'../../_documentManagement/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
() => ({
default: ({
documents,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
ReviewUploadDocument,
UploadDocumentType,
} from '../../../../types/pages/UploadDocumentsPage/types';
import DocumentUploadLloydGeorgePreview from '../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import DocumentUploadLloydGeorgePreview from '../../_documentManagement/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import { AxiosError } from 'axios';
import { errorToParams } from '../../../../helpers/utils/errorToParams';
import PatientSummary, { PatientInfo } from '../../../generic/patientSummary/PatientSummary';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UploadDocumentType,
} from '../../../../types/pages/UploadDocumentsPage/types';
import Spinner from '../../../generic/spinner/Spinner';
import DocumentUploadRemoveFilesStage from '../../_documentUpload/documentUploadRemoveFilesStage/DocumentUploadRemoveFilesStage';
import DocumentUploadRemoveFilesStage from '../../_documentManagement/documentUploadRemoveFilesStage/DocumentUploadRemoveFilesStage';
import BackButton from '../../../generic/backButton/BackButton';

type ReviewDetailsDocumentRemoveAllStageProps = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ReviewDetails } from '../../../../types/generic/reviews';
import { UploadDocument } from '../../../../types/pages/UploadDocumentsPage/types';
import userEvent from '@testing-library/user-event';

vi.mock('../../_documentUpload/documentSelectOrderStage/DocumentSelectOrderStage', () => ({
vi.mock('../../_documentManagement/documentSelectOrderStage/DocumentSelectOrderStage', () => ({
default: vi.fn(
({ documents, setDocuments, setMergedPdfBlob, existingDocuments, onSuccess }) => (
<div data-testid="mock-document-select-order-stage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
UploadDocument,
} from '../../../../types/pages/UploadDocumentsPage/types';
import Spinner from '../../../generic/spinner/Spinner';
import DocumentSelectOrderStage from '../../_documentUpload/documentSelectOrderStage/DocumentSelectOrderStage';
import DocumentSelectOrderStage from '../../_documentManagement/documentSelectOrderStage/DocumentSelectOrderStage';
import { getConfigForDocType } from '../../../../helpers/utils/documentType';

type Props = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { JSX, useEffect, useRef, useState } from 'react';
import DocumentSelectStage from '../../_documentUpload/documentSelectStage/DocumentSelectStage';
import DocumentSelectStage from '../../_documentManagement/documentSelectStage/DocumentSelectStage';
import { getConfigForDocType } from '../../../../helpers/utils/documentType';
import { useNavigate } from 'react-router-dom';
import { ReviewDetails } from '../../../../types/generic/reviews';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ vi.mock('../../../../helpers/utils/urlManipulations', () => ({
},
}));

vi.mock('../../_documentUpload/documentUploadingStage/DocumentUploadingStage', () => ({
vi.mock('../../_documentManagement/documentUploadingStage/DocumentUploadingStage', () => ({
default: ({ documents, startUpload }: any): JSX.Element => (
<div data-testid="mock-document-uploading-stage">
<button data-testid="start-upload-button" onClick={startUpload}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
UploadDocumentType,
} from '../../../../types/pages/UploadDocumentsPage/types';
import Spinner from '../../../generic/spinner/Spinner';
import DocumentUploadingStage from '../../_documentUpload/documentUploadingStage/DocumentUploadingStage';
import DocumentUploadingStage from '../../_documentManagement/documentUploadingStage/DocumentUploadingStage';

type Props = {
reviewData: ReviewDetails | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ vi.mock('../../../../providers/sessionProvider/SessionProvider', () => ({
}));

vi.mock(
'../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
'../../_documentManagement/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
() => ({
default: (): React.JSX.Element => <div data-testid="lloyd-george-preview">Preview</div>,
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import BackButton from '../../../generic/backButton/BackButton';
import SpinnerButton from '../../../generic/spinnerButton/SpinnerButton';
import ErrorBox from '../../../layout/errorBox/ErrorBox';
import ServiceError from '../../../layout/serviceErrorBox/ServiceErrorBox';
import DocumentUploadLloydGeorgePreview from '../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import DocumentUploadLloydGeorgePreview from '../../_documentManagement/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import { RecordLayout } from '../../../generic/recordCard/RecordCard';
import { RecordLoader, RecordLoaderProps } from '../../../generic/recordLoader/RecordLoader';
import { getConfigForDocType } from '../../../../helpers/utils/documentType';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import { useForm } from 'react-hook-form';
import { AxiosError } from 'axios';
import { errorToParams } from '../../../../helpers/utils/errorToParams';
import waitForSeconds from '../../../../helpers/utils/waitForSeconds';
import DocumentUploadLloydGeorgePreview from '../../_documentUpload/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';
import { NHS_NUMBER_UNKNOWN } from '../../../../helpers/constants/numbers';
import DocumentUploadLloydGeorgePreview from '../../_documentManagement/documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview';

export type ReviewsDetailsStageProps = {
reviewData: ReviewDetails;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const DocumentSelectFileErrorsPage = ({ documents }: Props): JSX.Element => {
useEffect(() => {
if (documents.length === 0) {
navigate(routes.HOME);
return;
}
}, []);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ const DocumentSelectOrderStage = ({
});
}, [documents.length, existingDocuments]);

const DocumentPositionDropdown = (
documentId: string,
currentPosition: number | undefined,
): React.JSX.Element => {
const getDocumentPositionDropdown = (documentId: string): React.JSX.Element => {
const key = documentPositionKey(documentId);

const positionOffset = existingDocuments && existingDocuments.length > 0 ? 1 : 0;
Expand Down Expand Up @@ -263,7 +260,7 @@ const DocumentSelectOrderStage = ({
{id === 'existing-documents' ? <b>{filename}</b> : filename}
</Table.Cell>
<Table.Cell className="position-cell">
{ableToReposition && DocumentPositionDropdown(id, position)}
{ableToReposition && getDocumentPositionDropdown(id)}
{!ableToReposition && position}
</Table.Cell>
<Table.Cell className="view-cell">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { render, screen } from '@testing-library/react';
import DocumentSelectPagesStage from './DocumentSelectPagesStage';

describe('DocumentSelectPagesStage', () => {
it('renders', () => {
render(<DocumentSelectPagesStage />);

expect(screen.getByText('Document select page')).toBeInTheDocument();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const DocumentSelectPagesStage = (): React.JSX.Element => {
return (
<>
<p>Document select page</p>
</>
);
};

export default DocumentSelectPagesStage;
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ describe('DocumentSelectStage', () => {
expect(
screen.getByText('Drag and drop a file or multiple files here'),
).toBeInTheDocument();
expect(dropzone);
expect(dropzone).toBeInTheDocument();

fireEvent.drop(dropzone, { dataTransfer: { files: [lgDocumentOne] } });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ const DocumentSelectStage = ({
useEffect(() => {
if (filesErrorRef.current) {
navigate(routes.HOME);
return;
}
}, []);

Expand Down Expand Up @@ -216,16 +215,16 @@ const DocumentSelectStage = ({
};

const updateDocuments = (docs: UploadDocument[]): void => {
const sortedDocs = docs
.sort((a, b) => a.file.lastModified - b.file.lastModified)
.map((doc, index) => ({
...doc,
position: index + 1,
}));
const sortedDocs = docs.toSorted((a, b) => a.file.lastModified - b.file.lastModified);

const docsWithPositions = sortedDocs.map((doc, index) => ({
...doc,
position: index + 1,
}));

setDocuments((previousState) => {
const docs = previousState.filter((doc) => doc.docType !== documentType);
return [...docs, ...sortedDocs];
return [...docs, ...docsWithPositions];
});
};

Expand Down Expand Up @@ -299,7 +298,7 @@ const DocumentSelectStage = ({
resetErrors();
};

const DocumentRow = (
const getDocumentRow = (
document: UploadDocument | ReviewUploadDocument,
index: number,
): JSX.Element => {
Expand Down Expand Up @@ -570,7 +569,7 @@ const DocumentSelectStage = ({
</Table.Head>

<Table.Body>
{documents.map((document, index) => DocumentRow(document, index))}
{documents.map((document, index) => getDocumentRow(document, index))}
</Table.Body>
</Table>
{multifile && (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
.document_record-stage {
.card-links {
.nhsuk-card__content {
padding: 15px 25px 20px 25px;
min-height: 105px;

.nhsuk-card__heading {
margin: 0;
}

.nhsuk-card__description {
margin: 0;
}

.nhsuk-card__link {
font-size: 19px;
}
}
}

#pdf-viewer {
height: 90vh;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ import { routeChildren, routes } from '../../../../types/generic/routes';
import { buildDocumentConfig, buildPatientDetails } from '../../../../helpers/test/testBuilders';
import userEvent from '@testing-library/user-event';
import { getFormattedDate } from '../../../../helpers/utils/formatDate';
import { lloydGeorgeRecordLinks } from '../../../../types/blocks/lloydGeorgeActions';
import { ACTION_LINK_KEY } from '../../../../types/blocks/lloydGeorgeActions';
import SessionProvider from '../../../../providers/sessionProvider/SessionProvider';
import { createMemoryHistory } from 'history';
import * as ReactRouter from 'react-router-dom';
import { REPOSITORY_ROLE } from '../../../../types/generic/authRole';
import useRole from '../../../../helpers/hooks/useRole';
import useConfig from '../../../../helpers/hooks/useConfig';

// Mock dependencies
vi.mock('../../../../helpers/hooks/usePatient');
vi.mock('../../../../helpers/hooks/useConfig');
vi.mock('../../../../helpers/hooks/useTitle');
vi.mock('../../../../helpers/hooks/useRole');
vi.mock('../../../../helpers/utils/documentType', async () => {
Expand All @@ -40,6 +42,7 @@ vi.mock('react-router-dom', async () => {
});

const mockUsePatient = usePatient as Mock;
const mockUseConfig = useConfig as Mock;
const mockUseTitle = useTitle as Mock;
const mockUseRole = useRole as Mock;
const mockUseNavigate = vi.fn();
Expand Down Expand Up @@ -108,6 +111,11 @@ describe('DocumentView', () => {
beforeEach(() => {
import.meta.env.VITE_ENVIRONMENT = 'vitest';
mockUsePatient.mockReturnValue(mockPatientDetails);
mockUseConfig.mockReturnValue({
featureFlags: {
documentCorrectEnabled: false,
},
});
mockUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);
vi.mocked(getConfigForDocType).mockReturnValue(buildDocumentConfig());

Expand Down Expand Up @@ -238,7 +246,7 @@ describe('DocumentView', () => {
it('navigates to upload page when add files is clicked', async () => {
renderComponent();

const addFilesButton = screen.getByTestId('add-files-btn');
const addFilesButton = screen.getByTestId(ACTION_LINK_KEY.ADD);
fireEvent.click(addFilesButton);

await waitFor(() => {
Expand All @@ -265,7 +273,7 @@ describe('DocumentView', () => {

renderComponent();

const addFilesButton = screen.getByTestId('add-files-btn');
const addFilesButton = screen.getByTestId(ACTION_LINK_KEY.ADD);
fireEvent.click(addFilesButton);

await waitFor(() => {
Expand Down Expand Up @@ -337,7 +345,7 @@ describe('DocumentView', () => {
}

await waitFor(() => {
expect(screen.queryAllByTestId('add-files-btn')).toHaveLength(
expect(screen.queryAllByTestId(ACTION_LINK_KEY.ADD)).toHaveLength(
addBtnVisible ? 1 : 0,
);
});
Expand All @@ -349,8 +357,7 @@ describe('DocumentView', () => {
it('calls removeDocument when remove action is triggered', () => {
renderComponent();

// assume first link is remove
const removeRecordLink = screen.getByTestId(lloydGeorgeRecordLinks[0].key);
const removeRecordLink = screen.getByTestId(ACTION_LINK_KEY.DELETE);
fireEvent.click(removeRecordLink);
expect(mockRemoveDocument).toHaveBeenCalled();
});
Expand All @@ -359,14 +366,64 @@ describe('DocumentView', () => {
vi.useFakeTimers();
renderComponent();

// assume second link is download
const downloadRecordLink = screen.getByTestId(lloydGeorgeRecordLinks[1].key);
const downloadRecordLink = screen.getByTestId(ACTION_LINK_KEY.DOWNLOAD);
fireEvent.click(downloadRecordLink);

vi.advanceTimersByTime(5000000);
expect(mockUseNavigate).toHaveBeenCalledWith(routes.DOWNLOAD_COMPLETE);
vi.useRealTimers();
});

it('does not show reassign button when document type does not support it', () => {
vi.mocked(getConfigForDocType).mockReturnValue(
buildDocumentConfig({ canBeUpdated: false }),
);

renderComponent();

const reassignRecordLink = screen.queryByTestId(ACTION_LINK_KEY.REASSIGN);
expect(reassignRecordLink).not.toBeInTheDocument();
});

it('does not show reassign button when feature flag is disabled', () => {
renderComponent();

const reassignRecordLink = screen.queryByTestId(ACTION_LINK_KEY.REASSIGN);
expect(reassignRecordLink).not.toBeInTheDocument();
});

it('does not show reassign button when patient is deceased', () => {
mockUsePatient.mockReturnValue(buildPatientDetails({ deceased: true }));

renderComponent();

const reassignRecordLink = screen.queryByTestId(ACTION_LINK_KEY.REASSIGN);
expect(reassignRecordLink).not.toBeInTheDocument();
});

it('navigates to document reassign page when reassign action is triggered', async () => {
mockUseConfig.mockReturnValue({
featureFlags: {
documentCorrectEnabled: true,
},
});

renderComponent();

const reassignRecordLink = screen.getByTestId(ACTION_LINK_KEY.REASSIGN);
await userEvent.click(reassignRecordLink);

expect(mockUseNavigate).toHaveBeenCalledWith(
expect.objectContaining({
pathname: routeChildren.DOCUMENT_REASSIGN_SELECT_PAGES,
}),
expect.objectContaining({
state: expect.objectContaining({
documentReference: mockDocumentReference,
}),
}),
);
});
});

describe('Role-based rendering', () => {
Expand Down
Loading
Loading