Skip to content

Commit

Permalink
[PRMP-866] - Modify fullscreen button to not render as GP_CLINICAL (#434
Browse files Browse the repository at this point in the history
)

* [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 <abdur.abid1@nhs.net>
  • Loading branch information
MohammadIqbalAD-NHS and abid-nhs authored Oct 1, 2024
1 parent 0e70091 commit 3b3a36a
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
},
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions app/src/components/generic/recordCard/RecordCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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(<RecordCard {...props} />);

await waitFor(() => {
expect(screen.getByTestId('full-screen-btn')).toBeInTheDocument();
});
});

it('does not render PdfViewer or full-screen button when cloudFrontUrl is empty', async () => {
render(<RecordCard {...props} cloudFrontUrl="" />);
expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument();
Expand All @@ -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(<RecordCard {...props} />);

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(<RecordCard {...props} cloudFrontUrl="" />);
expect(screen.queryByTestId('pdf-viewer')).not.toBeInTheDocument();
Expand Down
6 changes: 5 additions & 1 deletion app/src/components/generic/recordCard/RecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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);

Expand Down Expand Up @@ -65,7 +69,7 @@ function RecordCard({
</Card.Heading>
{detailsElement}

{cloudFrontUrl && (
{cloudFrontUrl && !userIsGpClinical && (
<button
className="lloydgeorge_record-stage_pdf-content-button link-button clickable"
data-testid="full-screen-btn"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('LloydGeorgeRecordPage', () => {
expect(screen.getByText(`${lgResult.number_of_files} files`)).toBeInTheDocument();
});

expect(screen.getByText('View in full screen')).toBeInTheDocument();
expect(screen.getByText('File format: PDF')).toBeInTheDocument();
});

Expand Down Expand Up @@ -193,7 +192,6 @@ describe('LloydGeorgeRecordPage', () => {
await waitFor(() => {
expect(screen.getByTitle('Embedded PDF')).toBeInTheDocument();
});
expect(screen.getByText('View in full screen')).toBeInTheDocument();

expect(screen.getByText('Lloyd George record')).toBeInTheDocument();
expect(screen.queryByText('No documents are available')).not.toBeInTheDocument();
Expand Down

0 comments on commit 3b3a36a

Please sign in to comment.