From 3b3a36a78857d85b9aba867be2ca51d01c2167cb Mon Sep 17 00:00:00 2001 From: MohammadIqbalAD-NHS <127403145+MohammadIqbalAD-NHS@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:09:23 +0100 Subject: [PATCH] [PRMP-866] - Modify fullscreen button to not render as GP_CLINICAL (#434) * [PRMP-866] - Modify fullscreen button to not render as GP_CLINICAL * [PRMP-866] - Modify full screen button tests to align with new structure of main * [PRMP-866] - Remove redundant tests * [PRMP-866] - Remove unnecessary role mocks * [PRMP-866] - fix broken cypress test * [PRMP-866] - Removed redundant mock * [PRMP-866] - Remove redundant mock --------- Co-authored-by: abid-nhs --- .../view_lloyd_george_is_bsol_workflow.cy.js | 22 ++++++++++--------- .../LloydGeorgeViewRecordStage.test.tsx | 1 - .../generic/recordCard/RecordCard.test.tsx | 22 +++++++++++++++++++ .../generic/recordCard/RecordCard.tsx | 6 ++++- .../LloydGeorgeRecordPage.test.tsx | 2 -- 5 files changed, 39 insertions(+), 14 deletions(-) diff --git a/app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/view_lloyd_george_is_bsol_workflow.cy.js b/app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/view_lloyd_george_is_bsol_workflow.cy.js index b93a04986..b53ef97f3 100644 --- a/app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/view_lloyd_george_is_bsol_workflow.cy.js +++ b/app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/view_lloyd_george_is_bsol_workflow.cy.js @@ -85,19 +85,21 @@ describe('GP Workflow: View Lloyd George record', () => { cy.getByTestId('pdf-viewer').should('be.visible'); // Act - open full screen view - cy.getByTestId('full-screen-btn').click(); + if (role !== Roles.GP_CLINICAL) { + cy.getByTestId('full-screen-btn').click(); - // Assert - assertPatientInfo(); - cy.getByTestId('pdf-card').should('not.exist'); - cy.getByTestId('pdf-viewer').should('be.visible'); + // Assert + assertPatientInfo(); + cy.getByTestId('pdf-card').should('not.exist'); + cy.getByTestId('pdf-viewer').should('be.visible'); - // Act - close full screen view - cy.getByTestId('back-link').click(); + // Act - close full screen view + cy.getByTestId('back-link').click(); - // Assert - cy.getByTestId('pdf-card').should('be.visible'); - cy.getByTestId('pdf-viewer').should('be.visible'); + // Assert + cy.getByTestId('pdf-card').should('be.visible'); + cy.getByTestId('pdf-viewer').should('be.visible'); + } }, ); diff --git a/app/src/components/blocks/_lloydGeorge/lloydGeorgeViewRecordStage/LloydGeorgeViewRecordStage.test.tsx b/app/src/components/blocks/_lloydGeorge/lloydGeorgeViewRecordStage/LloydGeorgeViewRecordStage.test.tsx index 76e646c01..3d6718b5a 100644 --- a/app/src/components/blocks/_lloydGeorge/lloydGeorgeViewRecordStage/LloydGeorgeViewRecordStage.test.tsx +++ b/app/src/components/blocks/_lloydGeorge/lloydGeorgeViewRecordStage/LloydGeorgeViewRecordStage.test.tsx @@ -59,7 +59,6 @@ describe('LloydGeorgeViewRecordStage', () => { expect(screen.getByTitle('Embedded PDF')).toBeInTheDocument(); }); expect(screen.getByText('View in full screen')).toBeInTheDocument(); - expect(screen.getByText('Lloyd George record')).toBeInTheDocument(); expect(screen.getByText(`Last updated: ${mockPdf.last_updated}`)).toBeInTheDocument(); expect(screen.getByText(`${mockPdf.number_of_files} files`)).toBeInTheDocument(); diff --git a/app/src/components/generic/recordCard/RecordCard.test.tsx b/app/src/components/generic/recordCard/RecordCard.test.tsx index cb9af3d66..572219b1a 100644 --- a/app/src/components/generic/recordCard/RecordCard.test.tsx +++ b/app/src/components/generic/recordCard/RecordCard.test.tsx @@ -9,11 +9,14 @@ import RecordCard, { Props } from './RecordCard'; import { buildLgSearchResult } from '../../../helpers/test/testBuilders'; import { act } from 'react-dom/test-utils'; import userEvent from '@testing-library/user-event'; +import { REPOSITORY_ROLE } from '../../../types/generic/authRole'; +import useRole from '../../../helpers/hooks/useRole'; const mockedUseNavigate = jest.fn(); jest.mock('../../../helpers/hooks/useBaseAPIHeaders'); jest.mock('../../../helpers/hooks/usePatient'); jest.mock('../../../helpers/hooks/useConfig'); +jest.mock('../../../helpers/hooks/useRole'); jest.mock('../../../helpers/hooks/useBaseAPIUrl'); jest.mock('../../../helpers/requests/getLloydGeorgeRecord'); jest.mock('axios'); @@ -29,6 +32,7 @@ const mockUsePatient = usePatient as jest.Mock; const mockUseConfig = useConfig as jest.Mock; const mockUseBaseAPIUrl = useBaseAPIUrl as jest.Mock; const mockUseBaseAPIHeaders = useBaseAPIHeaders as jest.Mock; +const mockUseRole = useRole as jest.Mock; it('passes a test', () => {}); describe('RecordCard Component', () => { @@ -122,6 +126,14 @@ describe('RecordCard Component', () => { expect(screen.queryByTestId('pdf-card')).not.toBeInTheDocument(); // Shouldn't show the card layout }); + it('renders the "View in full screen" button if the user is GP_ADMIN', async () => { + render(); + + await waitFor(() => { + expect(screen.getByTestId('full-screen-btn')).toBeInTheDocument(); + }); + }); + it('does not render PdfViewer or full-screen button when cloudFrontUrl is empty', async () => { render(); expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument(); @@ -138,6 +150,16 @@ describe('RecordCard Component', () => { }); }); + it('does not render the "View in full screen" button if the user is GP_CLINICAL', async () => { + mockUseRole.mockReturnValue(REPOSITORY_ROLE.GP_CLINICAL); + + render(); + + await waitFor(() => { + expect(screen.queryByTestId('full-screen-btn')).not.toBeInTheDocument(); + }); + }); + it('does not render the "View in full screen" button or pdf view when recordUrl is not set', () => { render(); expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument(); diff --git a/app/src/components/generic/recordCard/RecordCard.tsx b/app/src/components/generic/recordCard/RecordCard.tsx index b39fb21e0..3d910a16a 100644 --- a/app/src/components/generic/recordCard/RecordCard.tsx +++ b/app/src/components/generic/recordCard/RecordCard.tsx @@ -2,6 +2,8 @@ import { Card } from 'nhsuk-react-components'; import React, { ReactNode, useEffect, useRef, useState } from 'react'; import { DOWNLOAD_STAGE } from '../../../types/generic/downloadStage'; import PdfViewer from '../pdfViewer/PdfViewer'; +import useRole from '../../../helpers/hooks/useRole'; +import { REPOSITORY_ROLE } from '../../../types/generic/authRole'; import ProgressBar from '../progressBar/ProgressBar'; export type Props = { @@ -22,6 +24,8 @@ function RecordCard({ cloudFrontUrl, refreshRecord, }: Props) { + const role = useRole(); + const userIsGpClinical = role === REPOSITORY_ROLE.GP_CLINICAL; const [isLoading, setIsLoading] = useState(true); const mounted = useRef(false); @@ -65,7 +69,7 @@ function RecordCard({ {detailsElement} - {cloudFrontUrl && ( + {cloudFrontUrl && !userIsGpClinical && (