@@ -7,13 +7,14 @@ import {
77} from '../../../../types/pages/UploadDocumentsPage/types' ;
88import { MemoryRouter } from 'react-router-dom' ;
99import { fileUploadErrorMessages } from '../../../../helpers/utils/fileUploadErrorMessages' ;
10- import { buildLgFile } from '../../../../helpers/test/testBuilders' ;
10+ import { buildDocumentConfig , buildLgFile } from '../../../../helpers/test/testBuilders' ;
1111import { Mock } from 'vitest' ;
12- import { DOCUMENT_TYPE } from '../../../../helpers/utils/documentType' ;
12+ import { DOCUMENT_TYPE , DOCUMENT_TYPE_CONFIG } from '../../../../helpers/utils/documentType' ;
1313
1414const mockNavigate = vi . fn ( ) ;
1515const mockSetDocuments = vi . fn ( ) ;
1616const mockSetMergedPdfBlob = vi . fn ( ) ;
17+ const mockConfirmFiles = vi . fn ( ) ;
1718
1819vi . mock ( '../../../../helpers/hooks/usePatient' ) ;
1920vi . mock ( '../../../../helpers/hooks/useTitle' ) ;
@@ -44,17 +45,21 @@ vi.mock('../documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
4445 }
4546 return (
4647 < div data-testid = "lloyd-george-preview" >
47- Lloyd George Preview for { documents . length } documents
48+ < h2 > { docConfig . content . previewUploadTitle } </ h2 >
49+ < p > Previewing: { documents [ 0 ] ?. file . name } </ p >
4850 </ div >
4951 ) ;
5052 } ,
5153} ) ) ;
5254
55+ let docConfig : DOCUMENT_TYPE_CONFIG ;
56+
5357describe ( 'DocumentSelectOrderStage' , ( ) => {
5458 let documents : UploadDocument [ ] = [ ] ;
5559
5660 beforeEach ( ( ) => {
5761 import . meta. env . VITE_ENVIRONMENT = 'vitest' ;
62+ docConfig = buildDocumentConfig ( ) ;
5863 documents = [
5964 {
6065 docType : DOCUMENT_TYPE . LLOYD_GEORGE ,
@@ -128,7 +133,9 @@ describe('DocumentSelectOrderStage', () => {
128133 renderSut ( documents ) ;
129134
130135 await waitFor ( ( ) => {
131- expect ( screen . getByText ( 'Preview this Lloyd George record' ) ) . toBeInTheDocument ( ) ;
136+ expect (
137+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
138+ ) . toBeInTheDocument ( ) ;
132139 expect ( screen . getByTestId ( 'lloyd-george-preview' ) ) . toBeInTheDocument ( ) ;
133140 } ) ;
134141 } ) ;
@@ -476,7 +483,46 @@ describe('DocumentSelectOrderStage', () => {
476483
477484 await waitFor ( ( ) => {
478485 expect (
479- screen . getByText ( 'Lloyd George Preview for 2 documents' ) ,
486+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
487+ ) . toBeInTheDocument ( ) ;
488+ } ) ;
489+ } ) ;
490+
491+ it ( 'loads currently selected document into PDF viewer' , async ( ) => {
492+ docConfig = buildDocumentConfig ( {
493+ stitched : false ,
494+ snomedCode : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
495+ } ) ;
496+
497+ const multipleDocuments = [
498+ {
499+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
500+ id : '1' ,
501+ file : buildLgFile ( 1 ) ,
502+ attempts : 0 ,
503+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
504+ numPages : 5 ,
505+ position : 1 ,
506+ } ,
507+ {
508+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
509+ id : '2' ,
510+ file : buildLgFile ( 2 ) ,
511+ attempts : 0 ,
512+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
513+ numPages : 3 ,
514+ position : 2 ,
515+ } ,
516+ ] ;
517+
518+ renderSut ( multipleDocuments ) ;
519+
520+ await waitFor ( ( ) => {
521+ expect (
522+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
523+ ) . toBeInTheDocument ( ) ;
524+ expect (
525+ screen . getByText ( `Previewing: ${ multipleDocuments [ 0 ] . file . name } ` ) ,
480526 ) . toBeInTheDocument ( ) ;
481527 } ) ;
482528 } ) ;
@@ -502,10 +548,7 @@ describe('DocumentSelectOrderStage', () => {
502548 await user . click ( continueButton ! ) ;
503549
504550 await waitFor ( ( ) => {
505- expect ( mockNavigate ) . toHaveBeenCalledWith ( {
506- pathname : '/patient/document-upload/in-progress' ,
507- search : 'journey=update' ,
508- } ) ;
551+ expect ( mockConfirmFiles ) . toHaveBeenCalled ( ) ;
509552 } ) ;
510553 } ) ;
511554
@@ -544,7 +587,7 @@ describe('DocumentSelectOrderStage', () => {
544587
545588 expect (
546589 screen . getByText (
547- " When you upload your files, they will be added to the end of the patient's existing Lloyd George record." ,
590+ ` When you upload your files, they will be added to the end of the patient's existing ${ docConfig . displayName } .` ,
548591 ) ,
549592 ) . toBeInTheDocument ( ) ;
550593 expect (
@@ -562,7 +605,7 @@ describe('DocumentSelectOrderStage', () => {
562605
563606 expect (
564607 screen . getByText (
565- " When you upload your files, they will be added to the end of the patient's existing Lloyd George record." ,
608+ ` When you upload your files, they will be added to the end of the patient's existing ${ docConfig . displayName } .` ,
566609 ) ,
567610 ) . toBeInTheDocument ( ) ;
568611
@@ -593,7 +636,7 @@ describe('DocumentSelectOrderStage', () => {
593636
594637 renderSutWithExistingDocs ( documents , existingDocs ) ;
595638
596- expect ( screen . getByText ( ' Existing Lloyd George record' ) ) . toBeInTheDocument ( ) ;
639+ expect ( screen . getByText ( ` Existing ${ docConfig . displayName } ` ) ) . toBeInTheDocument ( ) ;
597640 } ) ;
598641
599642 it ( 'existing Lloyd George record has position 1 and cannot be repositioned or removed' , ( ) => {
@@ -613,7 +656,7 @@ describe('DocumentSelectOrderStage', () => {
613656
614657 const rows = screen . getAllByRole ( 'row' ) ;
615658 const existingRow = rows . find ( ( row ) =>
616- row . textContent ?. includes ( ' Existing Lloyd George record' ) ,
659+ row . textContent ?. includes ( ` Existing ${ docConfig . displayName } ` ) ,
617660 ) ;
618661
619662 expect ( existingRow ) . toBeInTheDocument ( ) ;
@@ -817,6 +860,8 @@ function renderSutWithExistingDocs(
817860 setDocuments = { mockSetDocuments }
818861 setMergedPdfBlob = { mockSetMergedPdfBlob }
819862 existingDocuments = { existingDocuments }
863+ documentConfig = { docConfig }
864+ confirmFiles = { mockConfirmFiles }
820865 />
821866 </ MemoryRouter > ,
822867 ) ;
@@ -830,6 +875,8 @@ function renderSut(documents: UploadDocument[]): void {
830875 setDocuments = { mockSetDocuments }
831876 setMergedPdfBlob = { mockSetMergedPdfBlob }
832877 existingDocuments = { [ ] }
878+ documentConfig = { docConfig }
879+ confirmFiles = { mockConfirmFiles }
833880 />
834881 </ MemoryRouter > ,
835882 ) ;
0 commit comments