Skip to content

Commit

Permalink
Web unit tests green
Browse files Browse the repository at this point in the history
  • Loading branch information
haworku committed Jul 20, 2023
1 parent c9c3bcc commit 2be62ef
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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',
Expand All @@ -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':
Expand Down Expand Up @@ -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',
Expand All @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,19 +93,20 @@ 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
}

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

Expand Down Expand Up @@ -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')
: ''}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
},
})
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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/)
Expand Down Expand Up @@ -714,9 +714,7 @@ describe('SubmissionSummary', () => {
)
).toBeInTheDocument()
expect(
screen.getByText(
/Risk-sharing strategy/
)
screen.getByText(/Risk-sharing strategy/)
).toBeInTheDocument()
expect(
screen.getByText(
Expand All @@ -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', {
Expand Down Expand Up @@ -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/)
Expand Down Expand Up @@ -1086,9 +1082,7 @@ describe('SubmissionSummary', () => {
)
).toBeInTheDocument()
expect(
screen.getByText(
/Risk-sharing strategy/
)
screen.getByText(/Risk-sharing strategy/)
).toBeInTheDocument()
expect(
screen.getByText(
Expand All @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -1458,9 +1450,7 @@ describe('SubmissionSummary', () => {
)
).toBeInTheDocument()
expect(
screen.getByText(
/Risk-sharing strategy/
)
screen.getByText(/Risk-sharing strategy/)
).toBeInTheDocument()
expect(
screen.getByText(
Expand All @@ -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', {
Expand Down Expand Up @@ -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', {
Expand Down Expand Up @@ -1829,9 +1817,7 @@ describe('SubmissionSummary', () => {
)
).toBeInTheDocument()
expect(
screen.getByText(
/Risk-sharing strategy/
)
screen.getByText(/Risk-sharing strategy/)
).toBeInTheDocument()
expect(
screen.getByText(
Expand All @@ -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', {
Expand Down

0 comments on commit 2be62ef

Please sign in to comment.