Skip to content

Commit 6aa4a49

Browse files
[PRMP-1450] Implement new PDF viewer fullscreen (#581)
* [PRMP-1450] Implement new PDF viewer fullscreen
1 parent cbe0b0d commit 6aa4a49

File tree

18 files changed

+354
-502
lines changed

18 files changed

+354
-502
lines changed

app/cypress/e2e/0-ndr-core-tests/gp_user_workflows/view_lloyd_george_is_bsol_workflow.cy.js

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -104,21 +104,25 @@ describe('GP Workflow: View Lloyd George record', () => {
104104
cy.getByTestId('pdf-viewer').should('be.visible');
105105

106106
// Act - open full screen view
107-
if (role !== Roles.GP_CLINICAL) {
108-
cy.getByTestId('full-screen-btn').click();
107+
if (Cypress.isBrowser('firefox')) {
108+
cy.getByTestId('full-screen-btn').then((el) => {
109+
el.trigger('click');
110+
});
111+
} else {
112+
cy.getByTestId('full-screen-btn').realClick();
113+
}
109114

110-
// Assert
111-
assertPatientInfo();
112-
cy.getByTestId('pdf-card').should('not.exist');
113-
cy.getByTestId('pdf-viewer').should('be.visible');
115+
// Assert
116+
assertPatientInfo();
117+
cy.getByTestId('pdf-card').should('not.exist');
118+
cy.getByTestId('pdf-viewer').should('be.visible');
114119

115-
// Act - close full screen view
116-
cy.getByTestId('back-link').click();
120+
// Act - close full screen view
121+
cy.getByTestId('back-link').click();
117122

118-
// Assert
119-
cy.getByTestId('pdf-card').should('be.visible');
120-
cy.getByTestId('pdf-viewer').should('be.visible');
121-
}
123+
// Assert
124+
cy.getByTestId('pdf-card').should('be.visible');
125+
cy.getByTestId('pdf-viewer').should('be.visible');
122126
},
123127
);
124128

app/cypress/support/e2e.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { routes } from './routes';
44
import { defaultFeatureFlags, FeatureFlags } from './feature_flags';
55
import Bluebird from 'cypress/types/bluebird';
66
import './aws.commands';
7+
import 'cypress-real-events';
78

89
/// <reference types="cypress" />
910
const registerCypressGrep = require('@cypress/grep');

app/package-lock.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
"@testing-library/jest-dom": "^5.17.0",
2424
"@testing-library/react": "^13.4.0",
2525
"@testing-library/user-event": "^13.5.0",
26+
"aws-rum-web": "^1.19.0",
2627
"aws-sdk": "^2.1510.0",
2728
"axios": "^1.7.4",
2829
"dotenv": "^16.3.1",
@@ -44,7 +45,6 @@
4445
"sass": "^1.66.1",
4546
"serve": "^14.2.1",
4647
"typescript": "^4.9.5",
47-
"aws-rum-web": "^1.19.0",
4848
"usehooks-ts": "^2.9.1",
4949
"util": "^0.12.5",
5050
"uuid": "^9.0.1",
@@ -63,6 +63,7 @@
6363
"@types/validator": "^13.11.8",
6464
"babel-plugin-named-exports-order": "^0.0.2",
6565
"cypress": "^13.13.2",
66+
"cypress-real-events": "^1.14.0",
6667
"eslint": "^8.48.0",
6768
"eslint-config-prettier": "^9.0.0",
6869
"eslint-plugin-cypress": "^2.14.0",

app/src/components/blocks/_lloydGeorge/lloydGeorgeViewRecordStage/LloydGeorgeViewRecordStage.test.tsx

Lines changed: 9 additions & 225 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import LloydGeorgeViewRecordStage, { Props } from './LloydGeorgeViewRecordStage'
1919
import { createMemoryHistory } from 'history';
2020
import { LG_RECORD_STAGE } from '../../../../types/blocks/lloydGeorgeStages';
2121
import * as ReactRouter from 'react-router-dom';
22+
import SessionProvider from '../../../../providers/sessionProvider/SessionProvider';
2223
const mockPdf = buildLgSearchResult();
2324
const mockPatientDetails = buildPatientDetails();
2425
jest.mock('../../../../helpers/hooks/useRole');
@@ -114,7 +115,7 @@ describe('LloydGeorgeViewRecordStage', () => {
114115
userEvent.click(screen.getByText('View in full screen'));
115116
});
116117
await waitFor(() => {
117-
expect(screen.queryByText('Lloyd George record')).not.toBeInTheDocument();
118+
expect(screen.queryByText('View in full screen')).not.toBeInTheDocument();
118119
});
119120
expect(screen.getByText('Exit full screen')).toBeInTheDocument();
120121
expect(screen.getByText(patientName)).toBeInTheDocument();
@@ -132,222 +133,15 @@ describe('LloydGeorgeViewRecordStage', () => {
132133
userEvent.click(screen.getByText('View in full screen'));
133134
});
134135
await waitFor(() => {
135-
expect(screen.queryByText('Lloyd George record')).not.toBeInTheDocument();
136+
expect(screen.queryByText('View in full screen')).not.toBeInTheDocument();
136137
});
137138

138139
act(() => {
139140
userEvent.click(screen.getByText('Exit full screen'));
140141
});
141142

142143
await waitFor(() => {
143-
expect(screen.getByText('Lloyd George record')).toBeInTheDocument();
144-
});
145-
});
146-
147-
describe('User is GP admin and non BSOL', () => {
148-
const renderComponentForNonBSOLGPAdmin = () => {
149-
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_ADMIN);
150-
mockedIsBSOL.mockReturnValue(false);
151-
renderComponent();
152-
};
153-
154-
const showConfirmationMessage = async () => {
155-
const sideMenuDownloadButton = screen.getByRole('button', {
156-
name: 'Download and remove files',
157-
});
158-
159-
act(() => {
160-
userEvent.click(sideMenuDownloadButton);
161-
});
162-
await waitFor(() => {
163-
expect(
164-
screen.getByText('Are you sure you want to download and remove this record?'),
165-
).toBeInTheDocument();
166-
});
167-
};
168-
169-
const clickRedDownloadButton = () => {
170-
const redDownloadButton = screen.getByRole('button', {
171-
name: 'Yes, download and remove',
172-
});
173-
174-
act(() => {
175-
userEvent.click(redDownloadButton);
176-
});
177-
};
178-
179-
it('renders warning callout, header and button', async () => {
180-
renderComponentForNonBSOLGPAdmin();
181-
182-
expect(screen.getByText('Before downloading')).toBeInTheDocument();
183-
expect(screen.getByText('Available records')).toBeInTheDocument();
184-
expect(screen.getByTestId('download-and-remove-record-btn')).toBeInTheDocument();
185-
});
186-
187-
it('clicking the side menu download button should show confirmation message, checkbox, red download button and cancel button', async () => {
188-
renderComponentForNonBSOLGPAdmin();
189-
190-
const downloadButton = screen.getByTestId('download-and-remove-record-btn');
191-
192-
act(() => {
193-
userEvent.click(downloadButton);
194-
});
195-
196-
await waitFor(() => {
197-
expect(
198-
screen.getByText('Are you sure you want to download and remove this record?'),
199-
).toBeInTheDocument();
200-
});
201-
expect(
202-
screen.getByText(
203-
"If you download this record, it removes from our storage. You must keep the patient's record safe.",
204-
),
205-
).toBeInTheDocument();
206-
expect(
207-
screen.getByRole('checkbox', {
208-
name: 'I understand that downloading this record removes it from storage.',
209-
}),
210-
).toBeInTheDocument();
211-
expect(
212-
screen.getByRole('button', { name: 'Yes, download and remove' }),
213-
).toBeInTheDocument();
214-
expect(screen.getByRole('button', { name: 'Cancel' })).toBeInTheDocument();
215-
});
216-
217-
it('when checkbox is unchecked, clicking red download button should show an alert and not allowing download', async () => {
218-
renderComponentForNonBSOLGPAdmin();
219-
await showConfirmationMessage();
220-
221-
clickRedDownloadButton();
222-
223-
await waitFor(() => {
224-
expect(
225-
screen.getByRole('alert', { name: 'There is a problem' }),
226-
).toBeInTheDocument();
227-
});
228-
expect(
229-
screen.getByText('You must confirm if you want to download and remove this record'),
230-
).toBeInTheDocument();
231-
expect(
232-
screen.getByText('Confirm if you want to download and remove this record'),
233-
).toBeInTheDocument();
234-
expect(mockSetStage).not.toBeCalled();
235-
});
236-
237-
it('when checkbox is unchecked, clicking "Download and remove" button twice will bring up a warning callout message', async () => {
238-
renderComponentForNonBSOLGPAdmin();
239-
await showConfirmationMessage();
240-
241-
act(() => {
242-
userEvent.click(
243-
screen.getByRole('button', {
244-
name: 'Download and remove files',
245-
}),
246-
);
247-
});
248-
249-
expect(
250-
screen.getByText('You must confirm if you want to download and remove this record'),
251-
).toBeInTheDocument();
252-
expect(
253-
screen.getByText('Confirm if you want to download and remove this record'),
254-
).toBeInTheDocument();
255-
expect(mockSetStage).not.toBeCalled();
256-
});
257-
258-
it('when checkbox is checked, clicking red download button should proceed to download and delete process', async () => {
259-
renderComponentForNonBSOLGPAdmin();
260-
await showConfirmationMessage();
261-
262-
act(() => {
263-
userEvent.click(screen.getByRole('checkbox'));
264-
});
265-
266-
clickRedDownloadButton();
267-
268-
await waitFor(() => {
269-
expect(mockNavigate).toBeCalledWith(
270-
routeChildren.LLOYD_GEORGE_DOWNLOAD_IN_PROGRESS,
271-
);
272-
});
273-
});
274-
275-
it('when checkbox is toggled 2 times ( = unchecked), red download button should not proceed to download', async () => {
276-
renderComponentForNonBSOLGPAdmin();
277-
await showConfirmationMessage();
278-
279-
const checkBox = screen.getByRole('checkbox');
280-
act(() => {
281-
userEvent.click(checkBox);
282-
userEvent.click(checkBox);
283-
});
284-
285-
clickRedDownloadButton();
286-
287-
await waitFor(() => {
288-
expect(
289-
screen.getByRole('alert', { name: 'There is a problem' }),
290-
).toBeInTheDocument();
291-
});
292-
expect(mockSetStage).not.toBeCalled();
293-
});
294-
295-
it('clicking cancel button will hide the confirmation message', async () => {
296-
renderComponentForNonBSOLGPAdmin();
297-
await showConfirmationMessage();
298-
299-
act(() => {
300-
userEvent.click(screen.getByRole('button', { name: 'Cancel' }));
301-
});
302-
303-
await waitFor(() => {
304-
expect(
305-
screen.queryByText('Are you sure you want to download and remove this record?'),
306-
).not.toBeInTheDocument();
307-
});
308-
});
309-
310-
describe('Accessibility (non BSOL)', () => {
311-
it('pass accessibility checks at page entry point', async () => {
312-
renderComponentForNonBSOLGPAdmin();
313-
314-
const results = await runAxeTest(document.body);
315-
expect(results).toHaveNoViolations();
316-
});
317-
318-
it('pass accessibility checks when Download & Remove confirmation message is showing up', async () => {
319-
renderComponentForNonBSOLGPAdmin();
320-
await showConfirmationMessage();
321-
322-
const results = await runAxeTest(document.body);
323-
expect(results).toHaveNoViolations();
324-
});
325-
326-
it('pass accessibility checks when error box is showing up', async () => {
327-
renderComponentForNonBSOLGPAdmin();
328-
await showConfirmationMessage();
329-
const confirmButton = await screen.findByRole('button', {
330-
name: 'Yes, download and remove',
331-
});
332-
act(() => {
333-
userEvent.click(confirmButton);
334-
});
335-
expect(
336-
await screen.findByText(
337-
'Confirm if you want to download and remove this record',
338-
),
339-
).toBeInTheDocument();
340-
341-
// to supress act() warning from non-captured classname change
342-
// eslint-disable-next-line testing-library/no-node-access
343-
const fieldsetParentDiv = screen.getByTestId('fieldset').closest('div');
344-
await waitFor(() => {
345-
expect(fieldsetParentDiv).toHaveClass('nhsuk-form-group--error');
346-
});
347-
348-
const results = await runAxeTest(document.body);
349-
expect(results).toHaveNoViolations();
350-
});
144+
expect(screen.getByText('View in full screen')).toBeInTheDocument();
351145
});
352146
});
353147

@@ -363,18 +157,6 @@ describe('LloydGeorgeViewRecordStage', () => {
363157
).not.toBeInTheDocument();
364158
});
365159

366-
it('does not render warning callout or button when user is GP clinical and non BSOL', async () => {
367-
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_CLINICAL);
368-
mockedIsBSOL.mockReturnValue(false);
369-
370-
renderComponent();
371-
372-
expect(screen.queryByText('Before downloading')).not.toBeInTheDocument();
373-
expect(
374-
screen.queryByRole('button', { name: 'Download and remove files' }),
375-
).not.toBeInTheDocument();
376-
});
377-
378160
it('does not render warning callout or button when user is GP clinical and BSOL', async () => {
379161
mockedUseRole.mockReturnValue(REPOSITORY_ROLE.GP_CLINICAL);
380162
mockedIsBSOL.mockReturnValue(true);
@@ -482,13 +264,15 @@ const renderComponent = (propsOverride?: Partial<Props>) => {
482264
const props: Omit<Props, 'setStage' | 'stage'> = {
483265
downloadStage: DOWNLOAD_STAGE.SUCCEEDED,
484266
lastUpdated: mockPdf.lastUpdated,
485-
numberOfFiles: mockPdf.numberOfFiles,
486-
totalFileSizeInBytes: mockPdf.totalFileSizeInBytes,
487267
refreshRecord: jest.fn(),
488268
cloudFrontUrl: 'http://test.com',
489269
showMenu: true,
490270
resetDocState: jest.fn(),
491271
...propsOverride,
492272
};
493-
render(<TestApp {...props} />);
273+
render(
274+
<SessionProvider sessionOverride={{ isLoggedIn: true }}>
275+
<TestApp {...props} />
276+
</SessionProvider>,
277+
);
494278
};

0 commit comments

Comments
 (0)