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,9 @@ describe('DocumentSelectOrderStage', () => {
128132 renderSut ( documents ) ;
129133
130134 await waitFor ( ( ) => {
131- expect ( screen . getByText ( 'Preview this Lloyd George record' ) ) . toBeInTheDocument ( ) ;
135+ expect (
136+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
137+ ) . toBeInTheDocument ( ) ;
132138 expect ( screen . getByTestId ( 'lloyd-george-preview' ) ) . toBeInTheDocument ( ) ;
133139 } ) ;
134140 } ) ;
@@ -476,7 +482,46 @@ describe('DocumentSelectOrderStage', () => {
476482
477483 await waitFor ( ( ) => {
478484 expect (
479- screen . getByText ( 'Lloyd George Preview for 2 documents' ) ,
485+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
486+ ) . toBeInTheDocument ( ) ;
487+ } ) ;
488+ } ) ;
489+
490+ it ( 'loads currently selected document into PDF viewer' , async ( ) => {
491+ docConfig = buildDocumentConfig ( {
492+ stitched : false ,
493+ snomedCode : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
494+ } ) ;
495+
496+ const multipleDocuments = [
497+ {
498+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
499+ id : '1' ,
500+ file : buildLgFile ( 1 ) ,
501+ attempts : 0 ,
502+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
503+ numPages : 5 ,
504+ position : 1 ,
505+ } ,
506+ {
507+ docType : DOCUMENT_TYPE . EHR_ATTACHMENTS ,
508+ id : '2' ,
509+ file : buildLgFile ( 2 ) ,
510+ attempts : 0 ,
511+ state : DOCUMENT_UPLOAD_STATE . SELECTED ,
512+ numPages : 3 ,
513+ position : 2 ,
514+ } ,
515+ ] ;
516+
517+ renderSut ( multipleDocuments ) ;
518+
519+ await waitFor ( ( ) => {
520+ expect (
521+ screen . getByText ( docConfig . content . previewUploadTitle as string ) ,
522+ ) . toBeInTheDocument ( ) ;
523+ expect (
524+ screen . getByText ( `Previewing: ${ multipleDocuments [ 0 ] . file . name } ` ) ,
480525 ) . toBeInTheDocument ( ) ;
481526 } ) ;
482527 } ) ;
@@ -544,7 +589,7 @@ describe('DocumentSelectOrderStage', () => {
544589
545590 expect (
546591 screen . getByText (
547- " When you upload your files, they will be added to the end of the patient's existing Lloyd George record." ,
592+ ` When you upload your files, they will be added to the end of the patient's existing ${ docConfig . displayName } .` ,
548593 ) ,
549594 ) . toBeInTheDocument ( ) ;
550595 expect (
@@ -562,7 +607,7 @@ describe('DocumentSelectOrderStage', () => {
562607
563608 expect (
564609 screen . getByText (
565- " When you upload your files, they will be added to the end of the patient's existing Lloyd George record." ,
610+ ` When you upload your files, they will be added to the end of the patient's existing ${ docConfig . displayName } .` ,
566611 ) ,
567612 ) . toBeInTheDocument ( ) ;
568613
@@ -593,7 +638,7 @@ describe('DocumentSelectOrderStage', () => {
593638
594639 renderSutWithExistingDocs ( documents , existingDocs ) ;
595640
596- expect ( screen . getByText ( ' Existing Lloyd George record' ) ) . toBeInTheDocument ( ) ;
641+ expect ( screen . getByText ( ` Existing ${ docConfig . displayName } ` ) ) . toBeInTheDocument ( ) ;
597642 } ) ;
598643
599644 it ( 'existing Lloyd George record has position 1 and cannot be repositioned or removed' , ( ) => {
@@ -613,7 +658,7 @@ describe('DocumentSelectOrderStage', () => {
613658
614659 const rows = screen . getAllByRole ( 'row' ) ;
615660 const existingRow = rows . find ( ( row ) =>
616- row . textContent ?. includes ( ' Existing Lloyd George record' ) ,
661+ row . textContent ?. includes ( ` Existing ${ docConfig . displayName } ` ) ,
617662 ) ;
618663
619664 expect ( existingRow ) . toBeInTheDocument ( ) ;
@@ -817,6 +862,7 @@ function renderSutWithExistingDocs(
817862 setDocuments = { mockSetDocuments }
818863 setMergedPdfBlob = { mockSetMergedPdfBlob }
819864 existingDocuments = { existingDocuments }
865+ documentConfig = { docConfig }
820866 />
821867 </ MemoryRouter > ,
822868 ) ;
@@ -830,6 +876,7 @@ function renderSut(documents: UploadDocument[]): void {
830876 setDocuments = { mockSetDocuments }
831877 setMergedPdfBlob = { mockSetMergedPdfBlob }
832878 existingDocuments = { [ ] }
879+ documentConfig = { docConfig }
833880 />
834881 </ MemoryRouter > ,
835882 ) ;
0 commit comments