Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: MCR-3988 document dates working again #2369

Merged
merged 9 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export const ContractDetailsSummarySection = ({
? new Date(
documentDateLookupTable.previousSubmissionDate
)
: undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why we had to switch from undefined to nulls here. Totally fine but I'm curious. in general I only expect to see nulls when dealing directly with Apollo GQL data

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this choice for React reasons, not GQL. Because this was previously an optional prop, the component is used in about 6 places, and the bug was that the date was present in some expected places and not in others it was very for me difficult to tell if data was coming back unexpected as undefined OR if it was just a case where the prop wasn't passed in at all intentionally.

I changed to a required prop. That means places using this component have to be clear when there is no previousSubmissionDate using explicit null

: null
}
caption="Contract"
documentCategory="Contract"
Expand All @@ -325,7 +325,7 @@ export const ContractDetailsSummarySection = ({
? new Date(
documentDateLookupTable.previousSubmissionDate
)
: undefined
: null
}
caption="Contract supporting documents"
documentCategory="Contract-supporting"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ export const RateDetailsSummarySection = ({
? new Date(
documentDateLookupTable.previousSubmissionDate
)
: undefined
: null
}
multipleDocumentsAllowed={false}
caption="Rate certification"
Expand All @@ -388,7 +388,7 @@ export const RateDetailsSummarySection = ({
? new Date(
documentDateLookupTable.previousSubmissionDate
)
: undefined
: null
}
caption="Rate supporting documents"
isSupportingDocuments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export const SingleRateSummarySection = ({
const navigate = useNavigate()
const rateRevision = rate.revisions[0]
const formData: RateFormData = rateRevision?.formData
const lastSubmittedDate = rate.revisions[0]?.submitInfo?.updatedAt
const lastSubmittedDate = rate.revisions[0]?.submitInfo?.updatedAt ?? null
const isRateAmendment = formData.rateType === 'AMENDMENT'
const isUnlocked = rate.status === 'UNLOCKED'
const explainMissingData =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('UploadedDocumentsTable', () => {

renderWithProviders(
<UploadedDocumentsTable
previousSubmissionDate={null}
documents={testDocuments}
caption="Contract supporting"
documentCategory="Contract-supporting"
Expand Down Expand Up @@ -217,6 +218,7 @@ describe('UploadedDocumentsTable', () => {
renderWithProviders(
<UploadedDocumentsTable
documents={testDocuments}
previousSubmissionDate={null}
caption="Contract supporting"
documentCategory="Contract-supporting"
isSupportingDocuments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ export const convertFromSubmissionDocumentsToGenericDocuments = (
export type UploadedDocumentsTableProps = {
documents: GenericDocument[]
caption: string | null
previousSubmissionDate: Date | null // used to calculate NEW tag based on doc dateAdded
packagesWithSharedRateCerts?: SharedRateCertDisplay[] // deprecated - could be deleted after we resolve all historical data linked rates
previousSubmissionDate?: Date // used to calculate NEW tag based on doc dateAdded
isSupportingDocuments?: boolean // used to calculate empty state and styles around the secondary supporting docs tables - would be nice to remove this in favor of more domain agnostic prop such as 'emptyStateText'
multipleDocumentsAllowed?: boolean // used to determined if we display validations based on doc list length
documentCategory?: string // used to determine if we display document category column
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ function makeDocumentDateTable(
revisionsLookup: RevisionsLookupType
): DocumentDateLookupTableType {
const lookupTable: DocumentDateLookupTableType = {
previousSubmissionDate: null,
previousSubmissionDate: null, // the last time there was a submission on this package
}
Object.keys(revisionsLookup).forEach(
(revisionId: string, index: number) => {
const listOfRevisionLookups = Object.keys(revisionsLookup)
listOfRevisionLookups.forEach(
(revisionId: string, index) => {
const revision = revisionsLookup[revisionId]
if (index === 1) {
// second most recent revision
const previousSubmission = getDateAdded(revision) // used in UploadedDocumentsTable to determine if we should show NEW tag
if (previousSubmission)
lookupTable['previousSubmissionDate'] = previousSubmission
}

const submitDate = revision.submitInfo?.updatedAt
if (submitDate && (listOfRevisionLookups.length === 1 || index === 1)) { // if we have a package with only one submitted revision, use that - otherwise use whatever in is the 1 index because thats the last submitted
lookupTable['previousSubmissionDate'] = submitDate
}

const allDocuments = getAllDocuments(revision.formData)
allDocuments.forEach((doc) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const LinkedRateSummary = ({
caption="Rate certification"
documentCategory="Rate certification"
isEditing={false}
previousSubmissionDate={null}
/>
</SectionCard>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
StatutoryRegulatoryAttestation,
StatutoryRegulatoryAttestationQuestion,
} from '../../../../../constants/statutoryRegulatoryAttestation'
import { mockContractFormData } from '../../../../../testHelpers/apolloMocks/contractPackageDataMock'

describe('ContractDetailsSummarySection', () => {
const defaultApolloMocks = {
Expand Down Expand Up @@ -314,7 +315,20 @@ describe('ContractDetailsSummarySection', () => {
it('does not render supporting contract documents table when no documents exist', () => {
renderWithProviders(
<ContractDetailsSummarySection
contract={mockContractPackageDraft()}
contract={mockContractPackageDraft({
draftRevision: {
__typename: 'ContractRevision',
submitInfo: undefined,
unlockInfo: undefined,
id: '123',
createdAt: new Date(),
updatedAt: new Date(),
contractName: 'MCR-0005-alvhalfhdsalf',
formData: mockContractFormData({
supportingDocuments: [],
}),
},
})}
submissionName="MN-PMAP-0001"
/>,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const ContractDetailsSummarySectionV2 = ({
isPreviousSubmission,
])
const lastSubmittedDate =
getLastContractSubmission(contract)?.submitInfo.updatedAt
getLastContractSubmission(contract)?.submitInfo.updatedAt ?? null
return (
<SectionCard
id="contractDetailsSection"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export const RateDetailsSummarySectionV2 = ({
? contract.draftRates
: getLastContractSubmission(contract)?.rateRevisions
const lastSubmittedDate =
getLastContractSubmission(contract)?.submitInfo.updatedAt
getLastContractSubmission(contract)?.submitInfo.updatedAt ?? null

const { getKey, getBulkDlURL } = useS3()
const [zippedFilesURL, setZippedFilesURL] = useState<
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { screen, waitFor } from '@testing-library/react'
import { screen, waitFor, within } from '@testing-library/react'
import { renderWithProviders } from '../../../../../testHelpers/jestHelpers'
import { ReviewSubmitV2 } from './ReviewSubmitV2'
import {
fetchCurrentUserMock,
fetchContractMockSuccess,
mockContractPackageUnlocked,
} from '../../../../../testHelpers/apolloMocks'
import { Route, Routes } from 'react-router-dom'
import { RoutesRecord } from '../../../../../constants'
Expand Down Expand Up @@ -174,6 +175,60 @@ describe('ReviewSubmit', () => {
})
})

it('extracts the correct dates from unlocked submission and displays them in tables', async () => {
const contractMock = fetchContractMockSuccess({
contract: mockContractPackageUnlocked(),
})

renderWithProviders(
<Routes>
<Route
path={RoutesRecord.SUBMISSIONS_REVIEW_SUBMIT}
element={<ReviewSubmitV2 />}
/>
</Routes>,
{
apolloProvider: {
mocks: [
fetchCurrentUserMock({ statusCode: 200 }),
contractMock,
],
},
routerProvider: {
route: '/submissions/test-abc-123/edit/review-and-submit',
},
featureFlags: {
'link-rates': true,
},
}
)

await waitFor(() => {
const contractDocRow = screen.getByRole('row', {
name: /contract document/,
})
expect(
within(contractDocRow).getByText('1/1/24')
).toBeInTheDocument()
const contractSupporting1Row = screen.getByRole('row', {
name: /contractSupporting1/,
})
expect(
within(contractSupporting1Row).getByText('1/15/24')
).toBeInTheDocument()
const rateDocRow = screen.getByRole('row', {
name: /rate certification/,
})
expect(within(rateDocRow).getByText('1/13/24')).toBeInTheDocument()
const rateSupporting1Row = screen.getByRole('row', {
name: /rateSupporting1/,
})
expect(
within(rateSupporting1Row).getByText('1/15/24')
).toBeInTheDocument()
})
})

it('displays back, save as draft, and submit buttons', async () => {
renderWithProviders(
<Routes>
Expand Down
Loading
Loading