@@ -19,6 +19,7 @@ import LloydGeorgeViewRecordStage, { Props } from './LloydGeorgeViewRecordStage'
1919import { createMemoryHistory } from 'history' ;
2020import { LG_RECORD_STAGE } from '../../../../types/blocks/lloydGeorgeStages' ;
2121import * as ReactRouter from 'react-router-dom' ;
22+ import SessionProvider from '../../../../providers/sessionProvider/SessionProvider' ;
2223const mockPdf = buildLgSearchResult ( ) ;
2324const mockPatientDetails = buildPatientDetails ( ) ;
2425jest . 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