From 2be62ef01f3812d82ea2c9824c47176c76b0df36 Mon Sep 17 00:00:00 2001 From: Hana Worku Date: Thu, 20 Jul 2023 18:19:51 -0500 Subject: [PATCH] Web unit tests green --- .../UploadedDocumentsTable.test.tsx | 10 +-- .../UploadedDocumentsTable.tsx | 11 ++-- .../makeDocumentDateLookupTable.ts | 4 +- .../SubmissionRevisionSummary.test.tsx | 7 +- .../SubmissionSummary.test.tsx | 66 +++++++------------ 5 files changed, 44 insertions(+), 54 deletions(-) diff --git a/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.test.tsx b/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.test.tsx index f5c4cae7b5..dd4bd3f34b 100644 --- a/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.test.tsx +++ b/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.test.tsx @@ -5,6 +5,8 @@ import { fetchCurrentUserMock, mockValidCMSUser, } from '../../../testHelpers/apolloMocks' +import { DocumentDateLookupTableType } from '../../../documentHelpers/makeDocumentDateLookupTable' +import { SubmissionDocument } from '../../../common-code/healthPlanFormDataType' describe('UploadedDocumentsTable', () => { const emptyDocumentsTable = () => { @@ -153,7 +155,7 @@ describe('UploadedDocumentsTable', () => { }) }) it('renders date added when supplied with a date lookup table', async () => { - const testDocuments = [ + const testDocuments: SubmissionDocument[] = [ { s3URL: 's3://foo/bar/test-1', name: 'supporting docs test 1', @@ -173,7 +175,7 @@ describe('UploadedDocumentsTable', () => { ], }, ] - const dateLookupTable = { + const dateLookupTable: DocumentDateLookupTableType = { 's3://foo/bar/test-1': 'Fri Mar 25 2022 16:13:20 GMT-0500 (Central Daylight Time)', 's3://foo/bar/test-2': @@ -213,7 +215,7 @@ describe('UploadedDocumentsTable', () => { }) }) it('shows the NEW tag when a document is submitted after the last submission', async () => { - const testDocuments = [ + const testDocuments: SubmissionDocument[] = [ { s3URL: 's3://foo/bar/test-1', name: 'supporting docs test 1', @@ -233,7 +235,7 @@ describe('UploadedDocumentsTable', () => { ], }, ] - const dateLookupTable = { + const dateLookupTable: DocumentDateLookupTableType = { 's3://foo/bar/test-1': 'Fri Mar 25 2022 16:13:20 GMT-0500 (Central Daylight Time)', 's3://foo/bar/test-2': diff --git a/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.tsx b/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.tsx index 586873b313..a6de7ba48e 100644 --- a/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.tsx +++ b/services/app-web/src/components/SubmissionSummarySection/UploadedDocumentsTable/UploadedDocumentsTable.tsx @@ -93,11 +93,12 @@ export const UploadedDocumentsTable = ({ // this is util needed to guard against passing in null or undefined to dayjs - we would get back today's date const canDisplayDateAddedForDocument = (doc: DocumentWithS3Data) => { - const documentKey = getDocumentKey(doc) - return documentKey && documentDateLookupTable[documentKey] + const documentLookupKey = getDocumentKey(doc) + return documentLookupKey && documentDateLookupTable[documentLookupKey] } const shouldHaveNewTag = (doc: DocumentWithS3Data) => { + const documentLookupKey = getDocumentKey(doc) if (!isCMSUser) { return false // design requirement, don't show new tag to state users on review submit } @@ -105,7 +106,7 @@ export const UploadedDocumentsTable = ({ if (!documentDateLookupTable || !doc || !doc.s3Key) { return false // this is a document with bad s3 data } - const documentDate = documentDateLookupTable?.[doc.s3Key] + const documentDate = documentDateLookupTable?.[documentLookupKey] const previousSubmissionDate = documentDateLookupTable.previousSubmissionDate @@ -227,9 +228,7 @@ export const UploadedDocumentsTable = ({ !isEditing ? dayjs( documentDateLookupTable[ - // can disable non-null here because we check in canDisplayDateAddedForDocument - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - doc.s3Key! + getDocumentKey(doc) ] ).format('M/D/YY') : ''} diff --git a/services/app-web/src/documentHelpers/makeDocumentDateLookupTable.ts b/services/app-web/src/documentHelpers/makeDocumentDateLookupTable.ts index a9673b959c..d40dd1c7f6 100644 --- a/services/app-web/src/documentHelpers/makeDocumentDateLookupTable.ts +++ b/services/app-web/src/documentHelpers/makeDocumentDateLookupTable.ts @@ -5,8 +5,8 @@ import { import { getAllDocuments } from './getAllDocuments' import { getDocumentKey } from './getDocumentKey' -// DocumentDateLookupTableType - { document key string : date string for "date added" } -// see logic in getDocumentKey for how document key string is calculated +// DocumentDateLookupTableType - { document lookup key string : date string for "date added" } +// see logic in getDocumentKey for how document lookup key string is calculated. This can be simplified once we have doc.sha everywhere type DocumentDateLookupTableType = { previousSubmissionDate: string | null [key: string]: string | null diff --git a/services/app-web/src/pages/SubmissionRevisionSummary/SubmissionRevisionSummary.test.tsx b/services/app-web/src/pages/SubmissionRevisionSummary/SubmissionRevisionSummary.test.tsx index 056fa36ce7..cf1cb7607c 100644 --- a/services/app-web/src/pages/SubmissionRevisionSummary/SubmissionRevisionSummary.test.tsx +++ b/services/app-web/src/pages/SubmissionRevisionSummary/SubmissionRevisionSummary.test.tsx @@ -84,7 +84,12 @@ describe('SubmissionRevisionSummary', () => { expect(rows).toHaveLength(2) expect(within(rows[0]).getByText('Date added')).toBeInTheDocument() expect( - within(rows[1]).getByText(dayjs(new Date()).format('M/D/YY')) + within(rows[1]).getByText( + dayjs( + mockSubmittedHealthPlanPackageWithRevisions() + .revisions[2]?.node?.submitInfo?.updatedAt + ).format('M/D/YY') + ) ).toBeInTheDocument() }) }) diff --git a/services/app-web/src/pages/SubmissionSummary/SubmissionSummary.test.tsx b/services/app-web/src/pages/SubmissionSummary/SubmissionSummary.test.tsx index 8b4cdfa5fb..a12b16471e 100644 --- a/services/app-web/src/pages/SubmissionSummary/SubmissionSummary.test.tsx +++ b/services/app-web/src/pages/SubmissionSummary/SubmissionSummary.test.tsx @@ -367,13 +367,13 @@ describe('SubmissionSummary', () => { it('extracts the correct dates from the submission and displays them in tables', async () => { const submission = mockSubmittedHealthPlanPackageWithRevision({ - currentSubmissionData: { + currentSubmitInfo: { updatedAt: new Date('2022-05-12T21:13:20.420Z'), }, - previousSubmissionData: { + previousSubmitInfo: { updatedAt: new Date('2022-04-12T21:13:20.420Z'), }, - initialSubmissionData: { + initialSubmitInfo: { updatedAt: new Date('2022-03-12T21:13:20.420Z'), }, }) @@ -408,7 +408,7 @@ describe('SubmissionSummary', () => { ) await waitFor(() => { const rows = screen.getAllByRole('row') - expect(rows).toHaveLength(10) + expect(rows).toHaveLength(8) expect( within(rows[0]).getByText('Date added') ).toBeInTheDocument() @@ -523,7 +523,7 @@ describe('SubmissionSummary', () => { 'src/common-code/proto/healthPlanFormDataProto/testData/' ) .filter((f) => f.endsWith('.proto')) - /* as much as we'd like to loop over all the proto files here, looping and async tests, + /* as much as we'd like to loop over all the proto files here, looping and async tests, which this one is (document loading) produces inconsistent results. We have to copy/paste the test for each proto file. */ it('loads outdated health plan packages with old protos as expected - 0', async () => { @@ -582,10 +582,10 @@ describe('SubmissionSummary', () => { expect(rows[0]).toHaveTextContent('Document name') expect(rows[0]).toHaveTextContent('Document category') expect(rows[1]).toHaveTextContent('contract doc') - expect(rows[1]).toHaveTextContent('8/19/22') + expect(rows[1]).toHaveTextContent('1/2/21') expect(rows[1]).toHaveTextContent('Contract-supporting') expect(rows[3]).toHaveTextContent('rates cert 1') - expect(rows[3]).toHaveTextContent('8/19/22') + expect(rows[3]).toHaveTextContent('11/2/21') expect(rows[3]).toHaveTextContent('Rate certification') expect(rows[4]).toHaveTextContent('rates cert 2') expect(document.body).toHaveTextContent(/Submission type/) @@ -714,9 +714,7 @@ describe('SubmissionSummary', () => { ) ).toBeInTheDocument() expect( - screen.getByText( - /Risk-sharing strategy/ - ) + screen.getByText(/Risk-sharing strategy/) ).toBeInTheDocument() expect( screen.getByText( @@ -742,9 +740,7 @@ describe('SubmissionSummary', () => { screen.getByText('Network adequacy standards') ).toBeInTheDocument() expect( - screen.getByText( - /Non-risk payment arrangements/ - ) + screen.getByText(/Non-risk payment arrangements/) ).toBeInTheDocument() expect( screen.getByRole('definition', { @@ -955,10 +951,10 @@ describe('SubmissionSummary', () => { expect(rows[0]).toHaveTextContent('Document name') expect(rows[0]).toHaveTextContent('Document category') expect(rows[1]).toHaveTextContent('contract doc') - expect(rows[1]).toHaveTextContent('5/13/21') + expect(rows[1]).toHaveTextContent('1/2/21') expect(rows[1]).toHaveTextContent('Contract') expect(rows[3]).toHaveTextContent('contract doc') - expect(rows[3]).toHaveTextContent('5/13/21') + expect(rows[3]).toHaveTextContent('1/2/21') expect(rows[3]).toHaveTextContent('Contract-supporting') expect(rows[4]).toHaveTextContent('Document') expect(document.body).toHaveTextContent(/Submission type/) @@ -1086,9 +1082,7 @@ describe('SubmissionSummary', () => { ) ).toBeInTheDocument() expect( - screen.getByText( - /Risk-sharing strategy/ - ) + screen.getByText(/Risk-sharing strategy/) ).toBeInTheDocument() expect( screen.getByText( @@ -1114,9 +1108,7 @@ describe('SubmissionSummary', () => { screen.getByText('Network adequacy standards') ).toBeInTheDocument() expect( - screen.getByText( - /Non-risk payment arrangements/ - ) + screen.getByText(/Non-risk payment arrangements/) ).toBeInTheDocument() expect( screen.getByRole('definition', { @@ -1322,17 +1314,17 @@ describe('SubmissionSummary', () => { expect(rows[0]).toHaveTextContent('Document name') expect(rows[0]).toHaveTextContent('Document category') expect(rows[1]).toHaveTextContent('contract doc') - expect(rows[1]).toHaveTextContent('5/13/21') + expect(rows[1]).toHaveTextContent('1/2/21') expect(rows[1]).toHaveTextContent('Contract') expect(rows[2]).toHaveTextContent('Document') expect(rows[3]).toHaveTextContent('contract doc') - expect(rows[3]).toHaveTextContent('5/13/21') + expect(rows[3]).toHaveTextContent('1/2/21') expect(rows[3]).toHaveTextContent('Contract-supporting') expect(rows[4]).toHaveTextContent('Document') expect(rows[5]).toHaveTextContent('rates cert 1') - expect(rows[5]).toHaveTextContent('5/13/21') + expect(rows[5]).toHaveTextContent('1/2/21') expect(rows[5]).toHaveTextContent('Rate certification') - expect(rows[6]).toHaveTextContent('5/13/21') + expect(rows[6]).toHaveTextContent('1/2/21') expect(document.body).toHaveTextContent(/Submission type/) expect( screen.getByRole('heading', { @@ -1458,9 +1450,7 @@ describe('SubmissionSummary', () => { ) ).toBeInTheDocument() expect( - screen.getByText( - /Risk-sharing strategy/ - ) + screen.getByText(/Risk-sharing strategy/) ).toBeInTheDocument() expect( screen.getByText( @@ -1486,9 +1476,7 @@ describe('SubmissionSummary', () => { screen.getByText('Network adequacy standards') ).toBeInTheDocument() expect( - screen.getByText( - /Non-risk payment arrangements/ - ) + screen.getByText(/Non-risk payment arrangements/) ).toBeInTheDocument() expect( screen.getByRole('definition', { @@ -1693,17 +1681,17 @@ describe('SubmissionSummary', () => { expect(rows[0]).toHaveTextContent('Document name') expect(rows[0]).toHaveTextContent('Document category') expect(rows[1]).toHaveTextContent('contract doc') - expect(rows[1]).toHaveTextContent('5/13/21') + expect(rows[1]).toHaveTextContent('1/2/21') expect(rows[1]).toHaveTextContent('Contract') expect(rows[2]).toHaveTextContent('Document') expect(rows[3]).toHaveTextContent('contract doc') - expect(rows[3]).toHaveTextContent('5/13/21') + expect(rows[3]).toHaveTextContent('1/2/21') expect(rows[3]).toHaveTextContent('Contract-supporting') expect(rows[4]).toHaveTextContent('Document') expect(rows[5]).toHaveTextContent('rates cert 1') - expect(rows[5]).toHaveTextContent('5/13/21') + expect(rows[5]).toHaveTextContent('1/2/21') expect(rows[5]).toHaveTextContent('Rate certification') - expect(rows[6]).toHaveTextContent('5/13/21') + expect(rows[6]).toHaveTextContent('1/2/21') expect(document.body).toHaveTextContent(/Submission type/) expect( screen.getByRole('heading', { @@ -1829,9 +1817,7 @@ describe('SubmissionSummary', () => { ) ).toBeInTheDocument() expect( - screen.getByText( - /Risk-sharing strategy/ - ) + screen.getByText(/Risk-sharing strategy/) ).toBeInTheDocument() expect( screen.getByText( @@ -1857,9 +1843,7 @@ describe('SubmissionSummary', () => { screen.getByText('Network adequacy standards') ).toBeInTheDocument() expect( - screen.getByText( - /Non-risk payment arrangements/ - ) + screen.getByText(/Non-risk payment arrangements/) ).toBeInTheDocument() expect( screen.getByRole('definition', {