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 @@ -11,16 +11,16 @@ describe('PCSE Workflow: Access and download found files', () => {
fileName: 'Screenshot 2023-09-11 at 16.06.40.png',
virusScannerResult: 'Not Scanned',
created: new Date('2023-09-12T10:41:41.747836Z'),
documentSnomedCodeType: DOCUMENT_TYPE.LLOYD_GEORGE,
},
{
fileName: 'Screenshot 2023-09-08 at 14.53.47.png',
virusScannerResult: 'Not Scanned',
created: new Date('2023-09-12T10:41:41.749341Z'),
documentSnomedCodeType: DOCUMENT_TYPE.EHR,
},
];

const homeUrl = '/';

beforeEach(() => {
cy.login(Roles.PCSE);
cy.navigateToPatientSearchPage();
Expand Down
50 changes: 30 additions & 20 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"history": "^5.3.0",
"jwt-decode": "^4.0.0",
"moment": "^2.30.1",
"nhsapp-frontend": "^4.0.0",
"nhsuk-frontend": "^9.6.4",
"nhsuk-react-components": "^5.0.0",
"pdf-lib": "^1.17.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ import { MemoryRouter } from 'react-router-dom';
import { fileUploadErrorMessages } from '../../../../helpers/utils/fileUploadErrorMessages';
import { buildDocumentConfig, buildLgFile } from '../../../../helpers/test/testBuilders';
import { Mock } from 'vitest';
import { DOCUMENT_TYPE, DOCUMENT_TYPE_CONFIG } from '../../../../helpers/utils/documentType';
import {
AllContentKeys,
DOCUMENT_TYPE,
DOCUMENT_TYPE_CONFIG_GENERIC,
} from '../../../../helpers/utils/documentType';

const mockNavigate = vi.fn();
const mockSetDocuments = vi.fn();
Expand Down Expand Up @@ -54,7 +58,7 @@ vi.mock('../documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
},
}));

let docConfig: DOCUMENT_TYPE_CONFIG;
let docConfig: DOCUMENT_TYPE_CONFIG_GENERIC<AllContentKeys>;

describe('DocumentSelectOrderStage', () => {
let documents: UploadDocument[] = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { SearchResult } from '../../../../types/generic/searchResult';
import { useSessionContext } from '../../../../providers/sessionProvider/SessionProvider';
import { REPOSITORY_ROLE } from '../../../../types/generic/authRole';
import { getFormattedDate } from '../../../../helpers/utils/formatDate';
import { DOCUMENT_TYPE_CONFIG, getDocumentTypeLabel } from '../../../../helpers/utils/documentType';
import {
DOCUMENT_TYPE_CONFIG,
getConfigForDocTypeGeneric,
getDocumentTypeLabel,
} from '../../../../helpers/utils/documentType';
import LinkButton from '../../../generic/linkButton/LinkButton';

type Props = {
Expand All @@ -23,6 +27,19 @@ const DocumentSearchResults = ({
session.auth!.role === REPOSITORY_ROLE.GP_ADMIN ||
session.auth!.role === REPOSITORY_ROLE.GP_CLINICAL;

const documentTypeLabel = (doc: SearchResult): string => {
let docconfig = getConfigForDocTypeGeneric(doc.documentSnomedCodeType);

const heading = docconfig.content.getValueFormatString<string>(
'searchResultDocumentTypeLabel',
{
version: doc.version,
},
);

return heading ?? getDocumentTypeLabel(doc.documentSnomedCodeType) ?? 'Documents';
};

return (
<div className="document-search-results">
<h3 className="subtitle" data-testid="subtitle">
Expand Down Expand Up @@ -54,7 +71,7 @@ const DocumentSearchResults = ({
id={`available-files-row-${index}-document-type`}
data-testid="doctype"
>
{getDocumentTypeLabel(result.documentSnomedCodeType) ?? 'Other'}
{documentTypeLabel(result)}
</Table.Cell>
<Table.Cell
id={`available-files-row-${index}-filename`}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { render, screen, fireEvent, waitFor, act } from '@testing-library/react';
import { describe, it, expect, vi, beforeEach, Mock } from 'vitest';
import DocumentView from './DocumentView';
import DocumentView, { DOCUMENT_VIEW_STATE } from './DocumentView';
import usePatient from '../../../../helpers/hooks/usePatient';
import useTitle from '../../../../helpers/hooks/useTitle';
import { DOCUMENT_TYPE, getConfigForDocType } from '../../../../helpers/utils/documentType';
import {
DOCUMENT_TYPE,
GetConfigForDocTypeGenericType,
getConfigForDocTypeGeneric,
} from '../../../../helpers/utils/documentType';
import { DocumentReference } from '../../../../types/pages/documentSearchResultsPage/types';
import { routeChildren, routes } from '../../../../types/generic/routes';
import { buildDocumentConfig, buildPatientDetails } from '../../../../helpers/test/testBuilders';
Expand All @@ -22,11 +26,16 @@ vi.mock('../../../../helpers/hooks/usePatient');
vi.mock('../../../../helpers/hooks/useConfig');
vi.mock('../../../../helpers/hooks/useTitle');
vi.mock('../../../../helpers/hooks/useRole');
var realGetConfigForDocTypeGeneric: GetConfigForDocTypeGenericType;

vi.mock('../../../../helpers/utils/documentType', async () => {
const actual = await vi.importActual('../../../../helpers/utils/documentType');
const actual = await vi.importActual<typeof import('../../../../helpers/utils/documentType')>(
'../../../../helpers/utils/documentType',
);
realGetConfigForDocTypeGeneric = actual.getConfigForDocTypeGeneric;
return {
...actual,
getConfigForDocType: vi.fn(),
getConfigForDocTypeGeneric: vi.fn(actual.getConfigForDocTypeGeneric),
};
});
vi.mock('../../../../providers/analyticsProvider/AnalyticsProvider', () => ({
Expand Down Expand Up @@ -111,6 +120,19 @@ const TestApp = ({ documentReference }: Props): React.JSX.Element => {
);
};

const TestAppViewState = ({ documentReference }: Props): React.JSX.Element => {
const history = createMemoryHistory();
return (
<ReactRouter.Router navigator={history} location={history.location}>
<DocumentView
viewState={DOCUMENT_VIEW_STATE.VERSION_HISTORY}
documentReference={documentReference}
removeDocument={mockRemoveDocument}
/>
</ReactRouter.Router>
);
};

const renderComponent = (
documentReference: DocumentReference | null = mockDocumentReference,
): void => {
Expand All @@ -129,10 +151,12 @@ describe('DocumentView', () => {
mockUseConfig.mockReturnValue({
featureFlags: {
documentCorrectEnabled: false,
versionHistoryEnabled: false,
},
});
mockUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);
vi.mocked(getConfigForDocType).mockReturnValue(buildDocumentConfig());

vi.mocked(getConfigForDocTypeGeneric).mockImplementation(realGetConfigForDocTypeGeneric);

// Mock fullscreen API
Object.defineProperty(document, 'fullscreenEnabled', {
Expand Down Expand Up @@ -349,8 +373,12 @@ describe('DocumentView', () => {
])(
'displays add button when %s',
async ({ canBeUpdated, role, deceased, fullscreen, addBtnVisible }) => {
vi.mocked(getConfigForDocType).mockReturnValue(
buildDocumentConfig({ canBeUpdated }),
vi.mocked(getConfigForDocTypeGeneric).mockImplementation(
(docType) =>
({
...realGetConfigForDocTypeGeneric(docType),
canBeUpdated,
}) as any,
);

mockUseRole.mockReturnValue(role);
Expand Down Expand Up @@ -397,8 +425,12 @@ describe('DocumentView', () => {
});

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

renderComponent();
Expand Down Expand Up @@ -446,6 +478,33 @@ describe('DocumentView', () => {
}),
);
});

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

renderComponent();

const versionHistoryLink = screen.getByTestId(ACTION_LINK_KEY.HISTORY);
await userEvent.click(versionHistoryLink);

await waitFor(() => {
expect(mockUseNavigate).toHaveBeenCalledWith(
expect.objectContaining({
pathname: routeChildren.DOCUMENT_VERSION_HISTORY,
}),
expect.objectContaining({
state: expect.objectContaining({
documentReference: mockDocumentReference,
}),
}),
);
});
});
});

describe('Role-based rendering', () => {
Expand All @@ -470,4 +529,16 @@ describe('DocumentView', () => {
expect(screen.queryByTestId('record-menu-card')).not.toBeInTheDocument();
});
});

describe('Document view state', () => {
it('renders version history view when viewState is set to VERSION_HISTORY', () => {
render(
<SessionProvider sessionOverride={{ isLoggedIn: true }}>
<TestAppViewState documentReference={mockDocumentReference} />
</SessionProvider>,
);

expect(screen.getByText('Lloyd George records')).toBeInTheDocument();
});
});
});
Loading
Loading