-
{documents.length}
-
{documentType}
-
-
- {filesErrorRef.current !== undefined ? 'has ref' : 'no ref'}
-
-
- )),
+const mockNavigate = vi.fn();
+
+// Mock pdfjs-dist to avoid DOMMatrix issues in test environment
+vi.mock('pdfjs-dist', () => ({
+ getDocument: vi.fn(() => ({
+ promise: Promise.resolve({
+ getPage: vi.fn(() => Promise.resolve({})),
+ numPages: 1,
+ destroy: vi.fn(() => Promise.resolve()),
+ }),
+ })),
+}));
+
+// Mock PatientSummary component as it's not relevant for these tests
+vi.mock('../../../generic/patientSummary/PatientSummary', () => ({
+ default: Object.assign(
+ vi.fn(() => null),
+ {
+ Child: vi.fn(() => null),
+ },
+ ),
+ PatientInfo: {
+ FULL_NAME: 'fullName',
+ NHS_NUMBER: 'nhsNumber',
+ BIRTH_DATE: 'birthDate',
+ },
}));
+// Mock Spinner component
vi.mock('../../../generic/spinner/Spinner', () => ({
default: vi.fn(() => Loading...
),
}));
vi.mock('react-router-dom', () => ({
- useNavigate: vi.fn(() => vi.fn()),
+ useNavigate: vi.fn(() => mockNavigate),
}));
describe('ReviewDetailsDocumentSelectStage', () => {
- const testReviewSnoMed: DOCUMENT_TYPE = '16521000000101' as DOCUMENT_TYPE;
- const mockReviewData: ReviewDetails = new ReviewDetails(
- 'test-review-id',
- testReviewSnoMed,
- '2024-01-01T12:00:00Z',
- 'Test Uploader',
- '2024-01-01T12:00:00Z',
- 'Test Reason',
- '1',
- '1234567890',
- );
-
- mockReviewData.files = [];
-
- const mockDocuments: UploadDocument[] = [];
- const mockSetDocuments = vi.fn();
+ const testReviewSnoMed: DOCUMENT_TYPE = DOCUMENT_TYPE.LLOYD_GEORGE;
+
+ let mockReviewData: ReviewDetails;
+ let mockDocuments: UploadDocument[];
+ let mockSetDocuments: SetUploadDocuments;
+
+ beforeEach(() => {
+ vi.clearAllMocks();
+
+ mockReviewData = new ReviewDetails(
+ 'test-review-id',
+ testReviewSnoMed,
+ '2024-01-01T12:00:00Z',
+ 'Test Uploader',
+ '2024-01-01T12:00:00Z',
+ 'Test Reason',
+ '1',
+ '1234567890',
+ );
+ mockReviewData.files = [];
+
+ mockDocuments = [];
+ mockSetDocuments = vi.fn() as SetUploadDocuments;
+ });
describe('Rendering', () => {
it('shows spinner when reviewData is null', () => {
@@ -103,8 +112,8 @@ describe('ReviewDetailsDocumentSelectStage', () => {
});
});
- describe('Props handling', () => {
- it('passes correct props to DocumentSelectStage', async () => {
+ describe('Integration with DocumentSelectStage', () => {
+ it('renders the DocumentSelectStage component when documents are initialized', async () => {
const testDocuments: UploadDocument[] = [
{
id: 'test-id',
@@ -135,12 +144,58 @@ describe('ReviewDetailsDocumentSelectStage', () => {
);
await waitFor(() => {
- expect(screen.getByTestId('document-type')).toBeInTheDocument();
+ expect(screen.queryByTestId('mock-spinner')).not.toBeInTheDocument();
});
- expect(screen.getByTestId('document-type')).toHaveTextContent(testReviewSnoMed);
+
+ // Check that the actual DocumentSelectStage component is rendered
+ // by looking for the page title
+ expect(
+ screen.getByText('Choose scanned paper notes files to upload'),
+ ).toBeInTheDocument();
});
- it('passes documents array to DocumentSelectStage', async () => {
+ it('displays document information correctly', async () => {
+ const testDocuments: UploadDocument[] = [
+ {
+ id: 'test-id',
+ file: new File(['test content'], 'test-document.pdf', {
+ type: 'application/pdf',
+ }),
+ state: DOCUMENT_UPLOAD_STATE.SELECTED,
+ progress: 0,
+ docType: testReviewSnoMed,
+ attempts: 0,
+ numPages: 1,
+ validated: false,
+ },
+ ];
+
+ const { rerender } = render(
+