Skip to content

Commit

Permalink
[prmp-1035] PR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
NogaNHS committed Oct 22, 2024
1 parent 3ae8345 commit a40f848
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,34 +211,16 @@ function LloydGeorgeViewRecordStage({
<h1>{pageHeader}</h1>
<PatientSimpleSummary />
{!fullScreen ? (
<>
<>
<div className="lloydgeorge_record-stage_flex">
<RecordMenuCard
className="lloydgeorge_record-stage_flex-row"
recordLinks={recordLinksToShow}
setStage={setStage}
showMenu={showMenu}
/>
<div className="lloydgeorge_record-stage_flex">
<RecordMenuCard
recordLinks={recordLinksToShow}
setStage={setStage}
showMenu={showMenu}
/>

<div
className={`lloydgeorge_record-stage_flex-row lloydgeorge_record-stage_flex-row${menuClass}`}
>
<RecordCard
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
</div>
</div>
</>
</>
) : (
<>
<div className="lloydgeorge_record-stage_fs">
<div
className={`lloydgeorge_record-stage_flex-row lloydgeorge_record-stage_flex-row${menuClass}`}
>
<RecordCard
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
Expand All @@ -248,7 +230,18 @@ function LloydGeorgeViewRecordStage({
cloudFrontUrl={cloudFrontUrl}
/>
</div>
</>
</div>
) : (
<div className="lloydgeorge_record-stage_fs">
<RecordCard
heading="Lloyd George record"
fullScreenHandler={setFullScreen}
detailsElement={<RecordDetails {...recordDetailsProps} />}
isFullScreen={fullScreen}
refreshRecord={refreshRecord}
cloudFrontUrl={cloudFrontUrl}
/>
</div>
)}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion app/src/components/generic/pdfViewer/PdfViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type Props = { fileUrl: String };
const PdfViewer = ({ fileUrl }: Props) => {
useEffect(() => {
const pdfObject = require('pdfobject');
pdfObject.embed(fileUrl + '#toolbar', '#pdf-viewer');
pdfObject.embed(fileUrl + '#toolbar=0', '#pdf-viewer');
}, [fileUrl]);

if (!fileUrl) return null;
Expand Down
5 changes: 1 addition & 4 deletions app/src/components/generic/recordCard/RecordCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@ function RecordCard({
}, [refreshRecord]);

const Record = () => {
if (!cloudFrontUrl) {
return null;
}
return <PdfViewer fileUrl={cloudFrontUrl} />;
return cloudFrontUrl ? <PdfViewer fileUrl={cloudFrontUrl} /> : null;
};

const RecordLayout = ({ children }: { children: ReactNode }) => {
Expand Down
46 changes: 6 additions & 40 deletions app/src/components/generic/recordMenuCard/RecordMenuCard.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,6 @@ const mockLinks: Array<LGRecordActionLink> = [
},
];

const className = 'lloydgeorge_record-stage_flex-row';

jest.mock('react-router-dom', () => ({
Link: (props: LinkProps) => <a {...props} role="link" />,
useNavigate: () => mockedUseNavigate,
Expand All @@ -69,12 +67,7 @@ describe('RecordMenuCard', () => {
describe('Rendering', () => {
it('renders menu', () => {
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} showMenu={true} />,
);
expect(screen.getByRole('heading', { name: 'Download record' })).toBeInTheDocument();
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
Expand All @@ -92,7 +85,6 @@ describe('RecordMenuCard', () => {
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksUpdateOnly}
className={className}
showMenu={true}
/>,
);
Expand All @@ -111,7 +103,6 @@ describe('RecordMenuCard', () => {
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinksDownloadOnly}
className={className}
showMenu={true}
/>,
);
Expand All @@ -127,24 +118,14 @@ describe('RecordMenuCard', () => {

it('does not render anything if the given record links array is empty', () => {
const { container } = render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={[]}
className={className}
showMenu={false}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={[]} showMenu={false} />,
);
expect(container).toBeEmptyDOMElement();
});

it('render menu item as a <button> if link item does not have stage or href', () => {
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} showMenu={true} />,
);
expect(
screen.getByRole('button', { name: 'Download and remove files' }),
Expand All @@ -159,12 +140,7 @@ describe('RecordMenuCard', () => {

it('Does not render the MenuCard if showMenu is false', () => {
const { container } = render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={false}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} showMenu={false} />,
);
expect(container).toBeEmptyDOMElement();
});
Expand All @@ -173,12 +149,7 @@ describe('RecordMenuCard', () => {
describe('Navigation', () => {
it('navigates to href when clicked', () => {
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} showMenu={true} />,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Upload files' })).toBeInTheDocument();
Expand All @@ -190,12 +161,7 @@ describe('RecordMenuCard', () => {

it('change stage when clicked', () => {
render(
<RecordMenuCard
setStage={mockSetStage}
recordLinks={mockLinks}
className={className}
showMenu={true}
/>,
<RecordMenuCard setStage={mockSetStage} recordLinks={mockLinks} showMenu={true} />,
);
expect(screen.getByRole('heading', { name: 'Update record' })).toBeInTheDocument();
expect(screen.getByRole('link', { name: 'Remove files' })).toBeInTheDocument();
Expand Down
8 changes: 6 additions & 2 deletions app/src/components/generic/recordMenuCard/RecordMenuCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ function RecordMenuCard({ recordLinks, setStage, showMenu, className }: Props) {
}

if (!showMenu) {
return null;
return <></>;
}
return (
<div className={className}>
<div className={className} data-testid="record-menu-card">
<Card className="lloydgeorge_record-stage_menu">
<Card.Content className="lloydgeorge_record-stage_menu-content">
{updateActions.length > 0 && (
Expand Down Expand Up @@ -97,4 +97,8 @@ const LinkItem = ({ link, setStage }: LinkItemProps) => {
);
}
};

RecordMenuCard.defaultProps = {
className: 'lloydgeorge_record-stage_flex-row',
};
export default RecordMenuCard;
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ describe('LloydGeorgeRecordPage', () => {
await waitFor(async () => {
expect(screen.getByText('No documents are available.')).toBeInTheDocument();
});
expect(screen.queryByTestId('record-menu-card')).not.toBeInTheDocument();
});

it('renders initial lg record view with docs are uploading text if response status is 423', async () => {
Expand Down

0 comments on commit a40f848

Please sign in to comment.