From 3c76d636f50b64799f5e7678e0c90490ae390d53 Mon Sep 17 00:00:00 2001 From: laurenyj <44596134+laurenyj@users.noreply.github.com> Date: Tue, 1 Oct 2024 11:28:07 -0500 Subject: [PATCH] Fix API error in DocumentViewer.test.js with document API setup --- .../components/Comments/List.jsx | 2 +- .../components/DocumentViewer.test.js | 181 +++++++++--------- .../app/readerprototype/data/documents.js | 151 +++++++++++++++ 3 files changed, 239 insertions(+), 95 deletions(-) create mode 100644 client/test/app/readerprototype/data/documents.js diff --git a/client/app/readerprototype/components/Comments/List.jsx b/client/app/readerprototype/components/Comments/List.jsx index f2ce872fae3..85eb66995ef 100644 --- a/client/app/readerprototype/components/Comments/List.jsx +++ b/client/app/readerprototype/components/Comments/List.jsx @@ -48,7 +48,7 @@ const List = (props) => { }; List.propTypes = { - annotations: PropTypes.object, + annotations: PropTypes.array, onSelect: PropTypes.func, selectedAnnotationId: PropTypes.number, }; diff --git a/client/test/app/readerprototype/components/DocumentViewer.test.js b/client/test/app/readerprototype/components/DocumentViewer.test.js index b642aa15e0e..e540116e886 100644 --- a/client/test/app/readerprototype/components/DocumentViewer.test.js +++ b/client/test/app/readerprototype/components/DocumentViewer.test.js @@ -1,83 +1,62 @@ import { render, waitFor } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; -import DocumentViewer from 'app/readerprototype/DocumentViewer'; import React, { useState } from 'react'; import { Provider } from 'react-redux'; import { MemoryRouter } from 'react-router-dom'; import { applyMiddleware, createStore } from 'redux'; import thunk from 'redux-thunk'; -import { rootReducer } from 'app/reader/reducers'; -import ApiUtil from 'app/util/ApiUtil'; +import { rootReducer } from '../../../../app/reader/reducers'; +import DocumentViewer from '../../../../app/readerprototype/DocumentViewer'; +import ApiUtil from '../../../../app/util/ApiUtil'; +import { documents } from '../data/documents'; + +window.IntersectionObserver = jest.fn(() => ({ + observe: jest.fn(), + disconnect: jest.fn() +})); +window.HTMLElement.prototype.scrollIntoView = jest.fn; + +jest.mock('../../../../app/util/ApiUtil', () => ({ + get: jest.fn().mockResolvedValue({ + body: { + appeal: { + data: {} + } + }, + header: { 'x-document-source': 'VBMS' } + }), + patch: jest.fn().mockResolvedValue({}) +})); + +jest.mock('../../../../app/util/NetworkUtil', () => ({ + connectionInfo: jest.fn(), +})); + +jest.mock('../../../../app/util/Metrics', () => ({ + storeMetrics: jest.fn().mockResolvedValue(), + recordAsyncMetrics: jest.fn().mockResolvedValue(), +})); + +jest.mock('pdfjs-dist', () => ({ + getDocument: jest.fn().mockImplementation(() => ({ + docId: 1, + promise: Promise.resolve({ + numPages: 2, + getPage: jest.fn((pageNumber) => ({ + render: jest.fn(pageNumber), + getTextContent: jest.fn().mockResolvedValue({ items: [] }), + getViewport: jest.fn(() => ({ width: 100, height: 200 })) + })), + }), + })), + renderTextLayer: jest.fn(), + GlobalWorkerOptions: jest.fn().mockResolvedValue(), +})); afterEach(() => jest.clearAllMocks()); -const doc = { - id: 1, - tags: [], - category_procedural: true, - category_other: false, - category_medical: false, - category_case_summary: false, - opened_by_current_user: false, -}; - -const props = { - allDocuments: [ - { - id: 1, - category_medical: null, - category_other: null, - category_procedural: true, - created_at: '2024-09-17T12:30:52.925-04:00', - description: null, - file_number: '216979849', - previous_document_version_id: null, - received_at: '2024-09-14', - series_id: '377120', - type: 'NOD', - updated_at: '2024-09-17T12:41:11.000-04:00', - upload_date: '2024-09-15', - vbms_document_id: '1', - content_url: '/document/39/pdf', - filename: 'filename-798447.pdf', - category_case_summary: true, - serialized_vacols_date: '', - serialized_receipt_date: '09/14/2024', - matching: false, - opened_by_current_user: false, - tags: [], - receivedAt: '2024-09-14', - listComments: false, - wasUpdated: false, - }, - { - id: 2, - category_medical: null, - category_other: null, - category_procedural: true, - created_at: '2024-09-17T12:30:52.925-04:00', - description: null, - file_number: '216979849', - previous_document_version_id: null, - received_at: '2024-09-14', - series_id: '377120', - type: 'NOD', - updated_at: '2024-09-17T12:41:11.000-04:00', - upload_date: '2024-09-15', - vbms_document_id: '1', - content_url: '/document/39/pdf', - filename: 'filename-798447.pdf', - category_case_summary: true, - serialized_vacols_date: '', - serialized_receipt_date: '09/14/2024', - matching: false, - opened_by_current_user: false, - tags: [], - receivedAt: '2024-09-14', - listComments: false, - wasUpdated: false, - }, - ], +const props1 = { + allDocuments: [documents[1], documents[2]], showPdf: jest.fn(), documentPathBase: '/3575931/documents', match: { @@ -85,6 +64,23 @@ const props = { }, }; +const defaultProps = (docId) => { + return { + allDocuments: [ + documents[1], + documents[2], + documents[3], + documents[4], + documents[5], + ], + showPdf: jest.fn(), + documentPathBase: '/3575931/documents', + match: { + params: { docId, vacolsId: '3575931' }, + }, + }; +}; + const getStore = () => createStore( rootReducer, @@ -94,7 +90,7 @@ const getStore = () => deleteAnnotationModalIsOpenFor: null, shareAnnotationModalIsOpenFor: null }, - documents: { 1: doc }, + documents, documentList: { pdfList: { lastReadDocId: null, @@ -118,7 +114,7 @@ const getStore = () => }, applyMiddleware(thunk)); -const Component = () => { +const Component = (props) => { const [zoomLevel, setZoomLevel] = useState(100); return @@ -129,31 +125,25 @@ const Component = () => { ; }; -describe('user visiting a document', () => { - +describe('Marked as Read', () => { beforeEach(() => { + jest.clearAllMocks(); jest.mock('app/util/ApiUtil', () => ({ patch: jest.fn(), })); }); - it('records the viewing of the document', () => { + it('marks document with docId 1 as read', () => { const spy = jest.spyOn(ApiUtil, 'patch'); - render(); - expect(spy). - toHaveBeenCalledWith( - '/document/1/mark-as-read', - { start: '2020-07-06T06:00:00-04:00', t0: 'RUNNING_IN_NODE' }, - 'mark-doc-as-read'); + render(); + expect(spy).toHaveBeenCalledWith('/document/1/mark-as-read', {}, 'mark-doc-as-read'); }); }); -describe('Open Document and Close Issue tags Sidebar Section', () => { - it('Navigate to next document and verify Issue tags stay closed', async () => { - const { container, getByText } = render( - - ); +describe('Sidebar Section', () => { + it('closes Issue Tags section and verify it stays closed on next document', async () => { + const { container, getByText } = render(); expect(container).toHaveTextContent('Select or tag issues'); expect(container).toHaveTextContent('Add a comment'); @@ -176,17 +166,20 @@ describe('Open Document and Close Issue tags Sidebar Section', () => { }); }); -test('should change zoom level to 80%, then to 60% to simulate parent states update', async () => { - const { container, getByRole } = render(); +describe('Zoom Out', () => { + it('zooms out and verify zoom level persists on next document', async() => { + + const { container, getByRole } = render(); - expect(container).toHaveTextContent('100%'); - const zoomOutButton = getByRole('button', { name: /zoom out/i }); + expect(container).toHaveTextContent('100%'); + const zoomOutButton = getByRole('button', { name: /zoom out/i }); - userEvent.click(zoomOutButton); + userEvent.click(zoomOutButton); - await waitFor(() => expect(container).toHaveTextContent('90%')); + await waitFor(() => expect(container).toHaveTextContent('90%')); - userEvent.click(zoomOutButton); + userEvent.click(zoomOutButton); - await waitFor(() => expect(container).toHaveTextContent('80%')); + await waitFor(() => expect(container).toHaveTextContent('80%')); + }); }); diff --git a/client/test/app/readerprototype/data/documents.js b/client/test/app/readerprototype/data/documents.js new file mode 100644 index 00000000000..2ab36c512ec --- /dev/null +++ b/client/test/app/readerprototype/data/documents.js @@ -0,0 +1,151 @@ +export const documents = { + 1: { + id: 1, + category_medical: null, + category_other: null, + category_procedural: null, + created_at: '2024-08-23T11:13:40.444-04:00', + description: null, + file_number: '686623298', + previous_document_version_id: null, + received_at: '2024-09-14', + series_id: '9204496', + type: 'VA 8 Certification of Appeal', + updated_at: '2024-09-18T11:35:31.925-04:00', + upload_date: '2024-09-15', + vbms_document_id: '100', + content_url: '/document/1/pdf', + filename: 'filename-5230058.pdf', + category_case_summary: true, + serialized_vacols_date: '', + serialized_receipt_date: '09/14/2024', + 'matching?': false, + opened_by_current_user: true, + tags: [ + { + id: 1, + created_at: '2024-08-23T10:02:12.994-04:00', + text: 'Service Connected', + updated_at: '2024-08-23T10:02:12.994-04:00' + } + ], + receivedAt: '2024-09-14', + listComments: false, + wasUpdated: false + }, + 2: { + id: 2, + category_medical: null, + category_other: null, + category_procedural: null, + created_at: '2024-08-23T11:13:40.444-04:00', + description: null, + file_number: '686623298', + previous_document_version_id: null, + received_at: '2024-09-14', + series_id: '8175113', + type: 'Supplemental Statement of the Case', + updated_at: '2024-09-18T11:35:31.925-04:00', + upload_date: '2024-09-15', + vbms_document_id: '101', + content_url: '/document/2/pdf', + filename: 'filename-4796387.pdf', + category_case_summary: true, + serialized_vacols_date: '', + serialized_receipt_date: '09/14/2024', + 'matching?': false, + opened_by_current_user: true, + tags: [ + { + id: 2, + created_at: '2024-08-23T10:02:13.006-04:00', + text: 'Right Knee', + updated_at: '2024-08-23T10:02:13.006-04:00' + } + ], + receivedAt: '2024-09-14', + listComments: false, + wasUpdated: false + }, + 3: { + id: 3, + category_medical: null, + category_other: null, + category_procedural: null, + created_at: '2024-08-23T11:13:40.444-04:00', + description: null, + file_number: '686623298', + previous_document_version_id: null, + received_at: '2024-09-14', + series_id: '6766186', + type: 'CAPRI', + updated_at: '2024-09-18T11:35:31.925-04:00', + upload_date: '2024-09-15', + vbms_document_id: '102', + content_url: '/document/3/pdf', + filename: 'filename-5857054.pdf', + category_case_summary: true, + serialized_vacols_date: '', + serialized_receipt_date: '09/14/2024', + 'matching?': false, + opened_by_current_user: true, + tags: [], + receivedAt: '2024-09-14', + listComments: false, + wasUpdated: false + }, + 4: { + id: 4, + category_medical: null, + category_other: null, + category_procedural: null, + created_at: '2024-08-23T11:13:40.444-04:00', + description: null, + file_number: '686623298', + previous_document_version_id: null, + received_at: '2024-09-14', + series_id: '210244', + type: 'Notice of Disagreement', + updated_at: '2024-09-18T11:35:31.925-04:00', + upload_date: '2024-09-15', + vbms_document_id: '103', + content_url: '/document/4/pdf', + filename: 'filename-9812435.pdf', + category_case_summary: true, + serialized_vacols_date: '', + serialized_receipt_date: '09/14/2024', + 'matching?': false, + opened_by_current_user: true, + tags: [], + receivedAt: '2024-09-14', + listComments: false, + wasUpdated: false + }, + 5: { + id: 5, + category_medical: null, + category_other: null, + category_procedural: null, + created_at: '2024-08-23T11:13:40.444-04:00', + description: null, + file_number: '686623298', + previous_document_version_id: null, + received_at: '2024-09-14', + series_id: '9038784', + type: 'Rating Decision - Codesheet', + updated_at: '2024-09-18T11:35:31.925-04:00', + upload_date: '2024-09-15', + vbms_document_id: '104', + content_url: '/document/5/pdf', + filename: 'filename-3019855.pdf', + category_case_summary: true, + serialized_vacols_date: '', + serialized_receipt_date: '09/14/2024', + 'matching?': false, + opened_by_current_user: true, + tags: [], + receivedAt: '2024-09-14', + listComments: false, + wasUpdated: false + }, +};