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 ( ) ;
@@ -44,17 +44,21 @@ vi.mock('../documentUploadLloydGeorgePreview/DocumentUploadLloydGeorgePreview',
4444 }
4545 return (
4646 < div data-testid = "lloyd-george-preview" >
47- Lloyd George Preview for { documents . length } documents
47+ < h2 > { docConfig . content . previewUploadTitle } </ h2 >
48+ < p > Previewing: { documents [ 0 ] ?. file . name } </ p >
4849 </ div >
4950 ) ;
5051 } ,
5152} ) ) ;
5253
54+ let docConfig : DOCUMENT_TYPE_CONFIG ;
55+
5356describe ( 'DocumentSelectOrderStage' , ( ) => {
5457 let documents : UploadDocument [ ] = [ ] ;
5558
5659 beforeEach ( ( ) => {
5760 import . meta. env . VITE_ENVIRONMENT = 'vitest' ;
61+ docConfig = buildDocumentConfig ( ) ;
5862 documents = [
5963 {
6064 docType : DOCUMENT_TYPE . LLOYD_GEORGE ,
@@ -128,7 +132,7 @@ describe('DocumentSelectOrderStage', () => {
128132 renderSut ( documents ) ;
129133
130134 await waitFor ( ( ) => {
131- expect ( screen . getByText ( 'Preview this Lloyd George record' ) ) . toBeInTheDocument ( ) ;
135+ expect ( screen . getByText ( docConfig . content . previewUploadTitle as string ) ) . toBeInTheDocument ( ) ;
132136 expect ( screen . getByTestId ( 'lloyd-george-preview' ) ) . toBeInTheDocument ( ) ;
133137 } ) ;
134138 } ) ;
@@ -476,7 +480,46 @@ describe('DocumentSelectOrderStage', () => {
476480
477481 await waitFor ( ( ) => {
478482 expect (
479- screen . getByText ( 'Lloyd George Preview for 2 documents' ) ,
483+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
484+ ) . toBeInTheDocument ( ) ;
485+ } ) ;
486+ } ) ;
487+
488+ it ( 'loads currently selected document into PDF viewer' , async ( ) => {
489+ docConfig = buildDocumentConfig ( {
490+ stitched : false ,
491+ snomedCode : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
492+ } ) ;
493+
494+ const multipleDocuments = [
495+ {
496+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
497+ id : '1' ,
498+ file : buildLgFile ( 1 ) ,
499+ attempts : 0 ,
500+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
501+ numPages : 5 ,
502+ position : 1 ,
503+ } ,
504+ {
505+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
506+ id : '2' ,
507+ file : buildLgFile ( 2 ) ,
508+ attempts : 0 ,
509+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
510+ numPages : 3 ,
511+ position : 2 ,
512+ } ,
513+ ] ;
514+
515+ renderSut ( multipleDocuments ) ;
516+
517+ await waitFor ( ( ) => {
518+ expect (
519+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
520+ ) . toBeInTheDocument ( ) ;
521+ expect (
522+ screen . getByText ( `Previewing: ${ multipleDocuments [ 0 ] . file . name } ` ) ,
480523 ) . toBeInTheDocument ( ) ;
481524 } ) ;
482525 } ) ;
@@ -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,7 @@ function renderSutWithExistingDocs(
817860 setDocuments = { mockSetDocuments }
818861 setMergedPdfBlob = { mockSetMergedPdfBlob }
819862 existingDocuments = { existingDocuments }
863+ documentConfig = { docConfig }
820864 />
821865 </ MemoryRouter > ,
822866 ) ;
@@ -830,6 +874,7 @@ function renderSut(documents: UploadDocument[]): void {
830874 setDocuments = { mockSetDocuments }
831875 setMergedPdfBlob = { mockSetMergedPdfBlob }
832876 existingDocuments = { [ ] }
877+ documentConfig = { docConfig }
833878 />
834879 </ MemoryRouter > ,
835880 ) ;
0 commit comments