diff --git a/app/components/Attachment/AttachmentTableRow.tsx b/app/components/Attachment/AttachmentTableRow.tsx index afd8182118..661e045d0a 100644 --- a/app/components/Attachment/AttachmentTableRow.tsx +++ b/app/components/Attachment/AttachmentTableRow.tsx @@ -13,6 +13,7 @@ interface Props { formChangeRowId: number; hideDelete?: boolean; isFirstRevision: boolean; + operation?: string; } const AttachmentTableRow: React.FC = ({ @@ -21,6 +22,7 @@ const AttachmentTableRow: React.FC = ({ formChangeRowId, hideDelete, isFirstRevision, + operation, }) => { const [ discardProjectAttachmentFormChange, @@ -65,6 +67,12 @@ const AttachmentTableRow: React.FC = ({ return ( <> + {operation && ( + + {operation.charAt(0).toUpperCase() + + operation.slice(1).toLowerCase()} + + )} {fileName} {fileType} {fileSize} diff --git a/app/components/Form/Functions/getMilestoneFilteredSchema.ts b/app/components/Form/Functions/getMilestoneFilteredSchema.ts index ab9c85991b..f4de801d43 100644 --- a/app/components/Form/Functions/getMilestoneFilteredSchema.ts +++ b/app/components/Form/Functions/getMilestoneFilteredSchema.ts @@ -12,7 +12,8 @@ import { JSONSchema7 } from "json-schema"; */ export const getMilestoneFilteredSchema = ( formSchema: JSONSchema7, - formChange + formChange, + latestCommittedFormChange ) => { const properties = formSchema.properties; // schema dependencies @@ -37,7 +38,7 @@ export const getMilestoneFilteredSchema = ( for (const key of Object.keys(filteredSchema.properties)) { const [updatedFormData, prevFormData] = [ formChange?.newFormData?.[key], - formChange?.formChangeByPreviousFormChangeId?.newFormData?.[key], + latestCommittedFormChange?.newFormData?.[key], ]; if ( updatedFormData === prevFormData || diff --git a/app/components/Form/ProjectAnnualReportFormSummary.tsx b/app/components/Form/ProjectAnnualReportFormSummary.tsx index 1ec3967e30..7b84285571 100644 --- a/app/components/Form/ProjectAnnualReportFormSummary.tsx +++ b/app/components/Form/ProjectAnnualReportFormSummary.tsx @@ -46,9 +46,6 @@ const ProjectAnnualReportFormSummary: React.FC = ({ isPristine newFormData operation - formChangeByPreviousFormChangeId { - newFormData - } formByJsonSchemaName { jsonSchema } @@ -93,6 +90,21 @@ const ProjectAnnualReportFormSummary: React.FC = ({ return [filteredReports]; }, [annualReportFormChanges]); + let latestCommittedReports = latestCommittedAnnualReportFormChanges.edges; + const latestCommittedReportMap = useMemo(() => { + const filteredReports = latestCommittedReports.map(({ node }) => node); + + const reportMap = filteredReports.reduce( + (reports, current) => ( + (reports[current.newFormData.reportingRequirementIndex] = current), + reports + ), + {} + ); + + return reportMap; + }, [latestCommittedReports]); + const allFormChangesPristine = useMemo( () => !annualReportFormChanges.some( @@ -103,6 +115,10 @@ const ProjectAnnualReportFormSummary: React.FC = ({ const annualReportsJSX = useMemo(() => { return sortedAnnualReports.map((annualReport, index) => { + const latestCommittedData = + latestCommittedReportMap[ + annualReport.newFormData.reportingRequirementIndex + ]; if (!annualReport) return; // Set the formSchema and formData based on showing the diff or not const { formSchema, formData } = !renderDiff @@ -112,7 +128,8 @@ const ProjectAnnualReportFormSummary: React.FC = ({ } : getFilteredSchema( annualReport.formByJsonSchemaName.jsonSchema.schema as JSONSchema7, - annualReport + annualReport, + latestCommittedData ); if ( @@ -122,13 +139,6 @@ const ProjectAnnualReportFormSummary: React.FC = ({ ) return null; - const latestCommittedData = - latestCommittedAnnualReportFormChanges?.edges?.find( - ({ node }) => - node.newFormData.reportingRequirementIndex === - annualReport.newFormData.reportingRequirementIndex - )?.node?.newFormData; - return (
@@ -162,9 +172,7 @@ const ProjectAnnualReportFormSummary: React.FC = ({ uiSchema={reportingRequirementUiSchema} formContext={{ operation: annualReport.operation, - oldData: - annualReport.formChangeByPreviousFormChangeId?.newFormData, - latestCommittedData, + latestCommittedData: latestCommittedData?.newFormData, isAmendmentsAndOtherRevisionsSpecific: isOnAmendmentsAndOtherRevisionsPage, }} @@ -183,6 +191,7 @@ const ProjectAnnualReportFormSummary: React.FC = ({ isOnAmendmentsAndOtherRevisionsPage, renderDiff, sortedAnnualReports, + latestCommittedReportMap, ]); // Update the hasDiff state in the CollapsibleFormWidget to define if the form has diffs to show diff --git a/app/components/Form/ProjectAttachmentsFormSummary.tsx b/app/components/Form/ProjectAttachmentsFormSummary.tsx index 42fbbf8daf..35c0b9cec7 100644 --- a/app/components/Form/ProjectAttachmentsFormSummary.tsx +++ b/app/components/Form/ProjectAttachmentsFormSummary.tsx @@ -7,6 +7,7 @@ import { FormNotAddedOrUpdated } from "./SummaryFormCommonComponents"; import { useEffect, useMemo } from "react"; const tableFilters = [ + new TextFilter("Operation", "operation"), new TextFilter("File Name", "fileName"), new TextFilter("Type", "type"), new TextFilter("Size", "size"), @@ -36,7 +37,6 @@ const ProjectAttachmentsFormSummary: React.FC = ({ summaryProjectAttachmentFormChanges: formChangesFor( first: 500 formDataTableName: "project_attachment" - filter: { operation: { notEqualTo: ARCHIVE } } ) @connection(key: "connection_summaryProjectAttachmentFormChanges") { __id totalCount @@ -115,6 +115,7 @@ const ProjectAttachmentsFormSummary: React.FC = ({ ({ node }) => ( = ({ ...ContactDetails_contact } } - formChangeByPreviousFormChangeId { - newFormData - asProjectContact { - contactByContactId { - fullName - } - } - } formByJsonSchemaName { jsonSchema } @@ -181,11 +173,6 @@ const ProjectContactFormSummary: React.FC = ({ formData={node.newFormData} formContext={{ operation: node.operation, - oldData: node.formChangeByPreviousFormChangeId?.newFormData, - oldUiSchema: createProjectContactUiSchema( - node?.formChangeByPreviousFormChangeId?.asProjectContact - ?.contactByContactId?.fullName - ), latestCommittedData: latestCommittedContactNode?.node?.newFormData, latestCommittedUiSchema, @@ -205,7 +192,7 @@ const ProjectContactFormSummary: React.FC = ({ secondaryContacts, renderDiff, isOnAmendmentsAndOtherRevisionsPage, - summaryContactFormChanges, + lastCommittedSecondaryContacts, ]); // Update the hasDiff state in the CollapsibleFormWidget to define if the form has diffs to show @@ -260,13 +247,6 @@ const ProjectContactFormSummary: React.FC = ({ formData={primaryContact ? primaryContact.node.newFormData : null} formContext={{ operation: primaryContact?.node.operation, - oldData: - primaryContact?.node.formChangeByPreviousFormChangeId - ?.newFormData, - oldUiSchema: createProjectContactUiSchema( - primaryContact?.node?.formChangeByPreviousFormChangeId - ?.asProjectContact?.contactByContactId?.fullName - ), latestCommittedData: lastCommittedPrimaryContact?.node?.newFormData, latestCommittedUiSchema: createProjectContactUiSchema( diff --git a/app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx b/app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx index 86ea14749e..b5b88e6594 100644 --- a/app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx +++ b/app/components/Form/ProjectEmissionIntensityReportFormSummary.tsx @@ -51,18 +51,12 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC = ({ formByJsonSchemaName { jsonSchema } - formChangeByPreviousFormChangeId { - newFormData - calculatedEiPerformance - paymentPercentage - maximumPerformanceMilestoneAmount - actualPerformanceMilestoneAmount - } } } } latestCommittedEmissionIntensityReportFormChange: latestCommittedFormChangesFor( - formDataTableName: "emission_intensity_report" + formDataTableName: "reporting_requirement" + reportType: "TEIMP" ) { edges { node { @@ -97,24 +91,6 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC = ({ summaryReportingRequirement?.actualPerformanceMilestoneAmount, }; - const oldData = { - ...summaryReportingRequirement?.formChangeByPreviousFormChangeId - ?.newFormData, - //calculated values - calculatedEiPerformance: - summaryReportingRequirement?.formChangeByPreviousFormChangeId - ?.calculatedEiPerformance, - paymentPercentage: - summaryReportingRequirement?.formChangeByPreviousFormChangeId - ?.paymentPercentage, - maximumPerformanceMilestoneAmount: - summaryReportingRequirement?.formChangeByPreviousFormChangeId - ?.maximumPerformanceMilestoneAmount, - actualPerformanceMilestoneAmount: - summaryReportingRequirement?.formChangeByPreviousFormChangeId - ?.actualPerformanceMilestoneAmount, - }; - const latestCommittedData = { ...latestCommittedEmissionIntensityReportFormChange?.edges[0]?.node ?.newFormData, @@ -147,7 +123,7 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC = ({ const filteredSchema = getSchemaAndDataIncludingCalculatedValues( emissionIntensityFormBySlug.jsonSchema.schema as JSONSchema7, newData, - oldData, + latestCommittedData, { // This is only to add the (Adjusted) to the title of the field to differentiate it from the calculated field adjustedEmissionsIntensityPerformance: { @@ -265,7 +241,6 @@ const ProjectEmissionsIntensityReportFormSummary: React.FC = ({ actualPerformanceMilestoneAmount: summaryReportingRequirement?.actualPerformanceMilestoneAmount, operation: summaryReportingRequirement?.operation, - oldData, latestCommittedData, isAmendmentsAndOtherRevisionsSpecific: isOnAmendmentsAndOtherRevisionsPage, diff --git a/app/components/Form/ProjectFormSummary.tsx b/app/components/Form/ProjectFormSummary.tsx index 5a0868bf57..2a8f40f925 100644 --- a/app/components/Form/ProjectFormSummary.tsx +++ b/app/components/Form/ProjectFormSummary.tsx @@ -52,25 +52,6 @@ const ProjectFormSummary: React.FC = ({ name } } - formChangeByPreviousFormChangeId { - rank - newFormData - asProject { - operatorByOperatorId { - legalName - bcRegistryId - } - fundingStreamRfpByFundingStreamRfpId { - year - fundingStreamByFundingStreamId { - description - } - } - projectStatusByProjectStatusId { - name - } - } - } } latestCommittedProjectFormChanges: latestCommittedFormChangesFor( formDataTableName: "project" @@ -110,30 +91,16 @@ const ProjectFormSummary: React.FC = ({ // Show diff if it is not the first revision and not view only (rendered from the overview page) const renderDiff = !isFirstRevision && !viewOnly; - const oldData = { - ...projectFormChange.formChangeByPreviousFormChangeId?.newFormData, - rank: projectFormChange.formChangeByPreviousFormChangeId?.rank, - }; - const newDataAsProject = projectFormChange.asProject; - const previousDataAsProject = - projectFormChange.formChangeByPreviousFormChangeId?.asProject; - - const oldUiSchema = previousDataAsProject - ? createProjectUiSchema( - previousDataAsProject.operatorByOperatorId.legalName, - `${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${previousDataAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`, - previousDataAsProject.operatorByOperatorId.bcRegistryId, - previousDataAsProject.projectStatusByProjectStatusId.name - ) - : null; - const latestCommittedUiSchema = latestCommittedData?.asProject + const latestCommittedAsProject = + latestCommittedProjectFormChanges?.edges[0]?.node?.asProject; + const latestCommittedUiSchema = latestCommittedAsProject ? createProjectUiSchema( - latestCommittedData.asProject.operatorByOperatorId.legalName, - `${latestCommittedData.asProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${latestCommittedData.asProject?.fundingStreamRfpByFundingStreamRfpId?.year}`, - latestCommittedData.asProject.operatorByOperatorId.bcRegistryId, - latestCommittedData.asProject.projectStatusByProjectStatusId.name + latestCommittedAsProject.operatorByOperatorId.legalName, + `${latestCommittedAsProject?.fundingStreamRfpByFundingStreamRfpId?.fundingStreamByFundingStreamId.description} - ${latestCommittedAsProject?.fundingStreamRfpByFundingStreamRfpId?.year}`, + latestCommittedAsProject.operatorByOperatorId.bcRegistryId, + latestCommittedAsProject.projectStatusByProjectStatusId.name ) : null; @@ -148,7 +115,7 @@ const ProjectFormSummary: React.FC = ({ projectSchema as JSONSchema7, { ...projectFormChange?.newFormData, rank: projectFormChange.rank }, - oldData, + latestCommittedData, { rank: { type: "number", @@ -199,8 +166,6 @@ const ProjectFormSummary: React.FC = ({ formData={formData} formContext={{ calculatedRank: projectFormChange.rank, - oldData, - oldUiSchema, latestCommittedData, latestCommittedUiSchema, operation: projectFormChange.operation, diff --git a/app/components/Form/ProjectFundingAgreementFormSummary.tsx b/app/components/Form/ProjectFundingAgreementFormSummary.tsx index a0adaec4f6..12e3ea405b 100644 --- a/app/components/Form/ProjectFundingAgreementFormSummary.tsx +++ b/app/components/Form/ProjectFundingAgreementFormSummary.tsx @@ -71,25 +71,6 @@ const ProjectFundingAgreementFormSummary: React.FC = ({ } } operation - formChangeByPreviousFormChangeId { - newFormData - eligibleExpensesToDate - holdbackAmountToDate - netPaymentsToDate - grossPaymentsToDate - calculatedTotalPaymentAmountToDate - proponentsSharePercentage - totalProjectValue - anticipatedFundingAmountPerFiscalYear { - edges { - # eslint-disable-next-line relay/unused-fields - node { - anticipatedFundingAmount - fiscalYear - } - } - } - } } } } @@ -169,25 +150,6 @@ const ProjectFundingAgreementFormSummary: React.FC = ({ ), }; - const oldFundingFormChanges = - revision.summaryProjectFundingAgreementFormChanges.edges[0]?.node - .formChangeByPreviousFormChangeId; - - const oldData = { - ...oldFundingFormChanges?.newFormData, - eligibleExpensesToDate: oldFundingFormChanges?.eligibleExpensesToDate, - holdbackAmountToDate: oldFundingFormChanges?.holdbackAmountToDate, - netPaymentsToDate: oldFundingFormChanges?.netPaymentsToDate, - grossPaymentsToDate: oldFundingFormChanges?.grossPaymentsToDate, - totalPaymentAmountToDate: - oldFundingFormChanges?.calculatedTotalPaymentAmountToDate, - proponentsSharePercentage: oldFundingFormChanges?.proponentsSharePercentage, - totalProjectValue: oldFundingFormChanges?.totalProjectValue, - anticipatedFundingAmountPerFiscalYear: cleanupNestedNodes( - oldFundingFormChanges?.anticipatedFundingAmountPerFiscalYear.edges - ), - }; - const fundingStream = revision.projectFormChange.asProject.fundingStreamRfpByFundingStreamRfpId .fundingStreamByFundingStreamId.name; @@ -223,7 +185,7 @@ const ProjectFundingAgreementFormSummary: React.FC = ({ const filteredSchema = getSchemaAndDataIncludingCalculatedValues( schema as JSONSchema7, newData, - oldData + latestCommittedData ); // Set the formSchema and formData based on showing the diff or not @@ -342,7 +304,6 @@ const ProjectFundingAgreementFormSummary: React.FC = ({ fundingAgreementSummary?.totalProjectValue, calculatedProponentsSharePercentage: fundingAgreementSummary?.proponentsSharePercentage, - oldData, latestCommittedData, isAmendmentsAndOtherRevisionsSpecific: isOnAmendmentsAndOtherRevisionsPage, diff --git a/app/components/Form/ProjectManagerFormSummary.tsx b/app/components/Form/ProjectManagerFormSummary.tsx index 9ba457a8a1..0ce9c978de 100644 --- a/app/components/Form/ProjectManagerFormSummary.tsx +++ b/app/components/Form/ProjectManagerFormSummary.tsx @@ -42,14 +42,6 @@ const ProjectManagerFormSummary: React.FC = ({ fullName } } - formChangeByPreviousFormChangeId { - newFormData - asProjectManager { - cifUserByCifUserId { - fullName - } - } - } formByJsonSchemaName { jsonSchema } @@ -146,12 +138,6 @@ const ProjectManagerFormSummary: React.FC = ({ formData={node.formChange.newFormData} formContext={{ operation: node.formChange?.operation, - oldData: - node.formChange?.formChangeByPreviousFormChangeId?.newFormData, - oldUiSchema: createProjectManagerUiSchema( - node.formChange?.formChangeByPreviousFormChangeId - ?.asProjectManager?.cifUserByCifUserId?.fullName - ), latestCommittedData: latestCommittedManagerNode?.node?.newFormData, latestCommittedUiSchema, isAmendmentsAndOtherRevisionsSpecific: diff --git a/app/components/Form/ProjectMilestoneReportFormSummary.tsx b/app/components/Form/ProjectMilestoneReportFormSummary.tsx index 327e81d397..decfaa1ca5 100644 --- a/app/components/Form/ProjectMilestoneReportFormSummary.tsx +++ b/app/components/Form/ProjectMilestoneReportFormSummary.tsx @@ -50,9 +50,6 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ isPristine newFormData operation - formChangeByPreviousFormChangeId { - newFormData - } formByJsonSchemaName { jsonSchema } @@ -86,6 +83,21 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ ({ node }) => node.operation !== "ARCHIVE" ); + let latestCommittedReports = latestCommittedMilestoneFormChanges.edges; + const latestCommittedReportMap = useMemo(() => { + const filteredReports = latestCommittedReports.map(({ node }) => node); + + const reportMap = filteredReports.reduce( + (reports, current) => ( + (reports[current.newFormData.reportingRequirementIndex] = current), + reports + ), + {} + ); + + return reportMap; + }, [latestCommittedReports]); + // Sort consolidated milestone form change records const [sortedMilestoneReports] = useMemo(() => { return getSortedReports(milestoneReportFormChanges, true); @@ -142,7 +154,10 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ }, { ...milestoneReport, - } + }, + latestCommittedReportMap[ + milestoneReport.newFormData.reportingRequirementIndex + ] ) : { formSchema: milestoneReport.formByJsonSchemaName.jsonSchema.schema, @@ -243,8 +258,6 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ calculatedNetAmount: milestoneReport?.newFormData?.calculatedNetAmount, operation: milestoneReport.operation, - oldData: - milestoneReport.formChangeByPreviousFormChangeId?.newFormData, latestCommittedData, isAmendmentsAndOtherRevisionsSpecific: isOnAmendmentsAndOtherRevisionsPage, @@ -268,6 +281,7 @@ const ProjectMilestoneReportFormSummary: React.FC = ({ latestCommittedMilestoneFormChanges?.edges, renderDiff, sortedMilestoneReports, + latestCommittedReportMap, ]); const milestoneReportsNotUpdated = useMemo( diff --git a/app/components/Form/ProjectQuarterlyReportFormSummary.tsx b/app/components/Form/ProjectQuarterlyReportFormSummary.tsx index fe2e9d27ae..05108a6fbc 100644 --- a/app/components/Form/ProjectQuarterlyReportFormSummary.tsx +++ b/app/components/Form/ProjectQuarterlyReportFormSummary.tsx @@ -47,9 +47,6 @@ const ProjectQuarterlyReportFormSummary: React.FC = ({ isPristine newFormData operation - formChangeByPreviousFormChangeId { - newFormData - } formByJsonSchemaName { jsonSchema } @@ -97,6 +94,22 @@ const ProjectQuarterlyReportFormSummary: React.FC = ({ return [filteredReports]; }, [quarterlyReportFormChanges]); + let latestCommittedReports = + latestCommittedProjectQuarterlyReportFormChanges.edges; + const latestCommittedReportMap = useMemo(() => { + const filteredReports = latestCommittedReports.map(({ node }) => node); + + const reportMap = filteredReports.reduce( + (reports, current) => ( + (reports[current.newFormData.reportingRequirementIndex] = current), + reports + ), + {} + ); + + return reportMap; + }, [latestCommittedReports]); + // Defines if all quarterly reports are pristine const allFormChangesPristine = useMemo( () => @@ -119,7 +132,10 @@ const ProjectQuarterlyReportFormSummary: React.FC = ({ : getFilteredSchema( quarterlyReport.formByJsonSchemaName.jsonSchema .schema as JSONSchema7, - quarterlyReport + quarterlyReport, + latestCommittedReportMap[ + quarterlyReport.newFormData.reportingRequirementIndex + ] ); if ( @@ -169,8 +185,6 @@ const ProjectQuarterlyReportFormSummary: React.FC = ({ formData={formData} formContext={{ operation: quarterlyReport.operation, - oldData: - quarterlyReport.formChangeByPreviousFormChangeId?.newFormData, latestCommittedData, isAmendmentsAndOtherRevisionsSpecific: isOnAmendmentsAndOtherRevisionsPage, diff --git a/app/components/Form/ProjectSummaryReportFormSummary.tsx b/app/components/Form/ProjectSummaryReportFormSummary.tsx index 31cbc5139a..63868e5496 100644 --- a/app/components/Form/ProjectSummaryReportFormSummary.tsx +++ b/app/components/Form/ProjectSummaryReportFormSummary.tsx @@ -56,9 +56,6 @@ const ProjectSummaryReportFormSummary: React.FC = ({ node { newFormData operation - formChangeByPreviousFormChangeId { - newFormData - } } } } @@ -91,7 +88,8 @@ const ProjectSummaryReportFormSummary: React.FC = ({ const filteredSchema = getFilteredSchema( projectSummaryReportFormBySlug.jsonSchema.schema as JSONSchema7, - projectSummaryReport || {} + projectSummaryReport || {}, + latestCommittedProjectSummaryFormChanges?.edges[0]?.node ); const allFormChangesPristine = useMemo( @@ -153,8 +151,6 @@ const ProjectSummaryReportFormSummary: React.FC = ({ uiSchema={projectSummaryReportUiSchema} formContext={{ operation: projectSummaryReport.operation, - oldData: - projectSummaryReport.formChangeByPreviousFormChangeId?.newFormData, latestCommittedData: latestCommittedProjectSummaryFormChanges?.edges[0]?.node ?.newFormData, diff --git a/app/lib/theme/CustomDiffFields.tsx b/app/lib/theme/CustomDiffFields.tsx index 41234491f5..06fb3e2ed1 100644 --- a/app/lib/theme/CustomDiffFields.tsx +++ b/app/lib/theme/CustomDiffFields.tsx @@ -60,7 +60,6 @@ const renderArrow = () => { }; const renderDiffData = ({ - oldData, newData, latestCommittedData, id, @@ -72,31 +71,10 @@ const renderDiffData = ({ contentSuffix, }) => { let components = []; - if (oldData !== null && oldData !== undefined) { - components.push( - - ); - if (contentSuffix) { - components.push( - contentSuffixElement(`${id}-${diffOldClsName}`, contentSuffix) - ); - } - if (newData !== null && newData !== undefined) { - components.push(renderArrow()); - } - } if ( latestCommittedData !== null && latestCommittedData !== undefined && - latestCommittedData !== oldData && latestCommittedData !== newData ) { components.push( @@ -120,8 +98,8 @@ const renderDiffData = ({ if ( newData !== null && newData !== undefined && - oldData !== null && - oldData !== undefined + latestCommittedData !== null && + latestCommittedData !== undefined ) { components.push( { let components = []; - if (oldData !== null && oldData !== undefined) { - components.push( - - ); - if (contentSuffix) { - components.push( - contentSuffixElement(`${id}-${diffOldClsName}`, contentSuffix) - ); - } - if ( - (newData !== null && newData !== undefined) || - (latestCommittedData !== null && latestCommittedData !== undefined) - ) { - components.push(renderArrow()); - } - } if ( latestCommittedData !== null && latestCommittedData !== undefined && - latestCommittedData !== oldData && latestCommittedData !== newData ) { components.push( @@ -223,8 +179,8 @@ const renderDiffString = ({ if ( newData !== null && newData !== undefined && - oldData !== null && - oldData !== undefined + latestCommittedData !== null && + latestCommittedData !== undefined ) { components.push( { const { idSchema, formData, formContext, uiSchema } = props; const id = idSchema?.$id; - const oldData = formContext?.oldData?.[props.name]; const latestCommittedData = formContext?.latestCommittedData?.[props.name]; const isDate = uiSchema["ui:widget"] === "DateWidget"; const contentSuffix = uiSchema?.["ui:options"]?.contentSuffix; - return renderDiffString({ - oldData, newData: formData, latestCommittedData, id, @@ -280,7 +233,6 @@ const CUSTOM_DIFF_FIELDS = { NumberField: (props) => { const { idSchema, formData, formContext, uiSchema } = props; const id = idSchema?.$id; - const oldData = formContext?.oldData?.[props.name]; const latestCommittedData = formContext?.latestCommittedData?.[props.name]; const isMoney = uiSchema?.isMoney; const isPercentage = uiSchema?.isPercentage; @@ -289,8 +241,6 @@ const CUSTOM_DIFF_FIELDS = { // Handle text data mapping for certain number values let textData = uiSchema?.["ui:options"]?.text as string; - let oldTextData = - formContext?.oldUiSchema?.[props.name]?.["ui:options"]?.text; let latestCommittedTextData = formContext?.latestCommittedUiSchema?.[props.name]?.["ui:options"]?.text; @@ -298,7 +248,6 @@ const CUSTOM_DIFF_FIELDS = { // Switch to string rendering for archive textData = undefined; return renderDiffString({ - oldData: oldTextData, newData: textData, latestCommittedData: latestCommittedTextData, id, @@ -309,9 +258,8 @@ const CUSTOM_DIFF_FIELDS = { }); } - if (oldTextData || textData || latestCommittedTextData) { + if (textData || latestCommittedTextData) { return renderDiffString({ - oldData: oldTextData, newData: textData, latestCommittedData: latestCommittedTextData, id, @@ -322,7 +270,6 @@ const CUSTOM_DIFF_FIELDS = { }); } else { return renderDiffData({ - oldData, newData: formData, latestCommittedData, id, diff --git a/app/lib/theme/schemaFilteringHelpers.ts b/app/lib/theme/schemaFilteringHelpers.ts index 5c3c8b4002..d11ce87b6e 100644 --- a/app/lib/theme/schemaFilteringHelpers.ts +++ b/app/lib/theme/schemaFilteringHelpers.ts @@ -46,18 +46,21 @@ export const getSchemaAndDataIncludingCalculatedValues = ( }; // `getFilteredSchema` can only be used when all form values are found in `newFormData` (most of the time, calculated values are queried outside of `newFormData`, so in forms with calculated values, use `getSchemaAndDataIncludingCalculatedValues` instead) -export const getFilteredSchema = (formSchema: JSONSchema7, formChange) => { +export const getFilteredSchema = ( + formSchema: JSONSchema7, + formChange, + latestCommittedFormChange +) => { const filteredSchema = JSON.parse(JSON.stringify(formSchema)); const newDataObject = {}; for (const key of Object.keys(filteredSchema.properties)) { if ( formChange?.newFormData?.[key] === - formChange?.formChangeByPreviousFormChangeId?.newFormData?.[key] + latestCommittedFormChange?.newFormData?.[key] ) delete filteredSchema.properties[key]; else newDataObject[key] = formChange.newFormData?.[key]; } - return { formSchema: filteredSchema, formData: newDataObject }; }; diff --git a/app/tests/unit/components/Form/ProjectAnnualReportFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectAnnualReportFormSummary.test.tsx index 4ff6adadad..981c6e0c59 100644 --- a/app/tests/unit/components/Form/ProjectAnnualReportFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectAnnualReportFormSummary.test.tsx @@ -41,18 +41,6 @@ const mockQueryPayload = { }, operation: "UPDATE", changeStatus: "committed", - formChangeByPreviousFormChangeId: { - changeStatus: "committed", - newFormData: { - status: "on_track", - comments: "I am the old comment on Annual Report #1", - projectId: 1, - reportType: "Annual", - reportDueDate: "2025-06-18T23:59:59.999-07:00", - submittedDate: "2025-07-01T23:59:59.999-07:00", - reportingRequirementIndex: 1, - }, - }, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -76,20 +64,6 @@ const mockQueryPayload = { }, operation: "UPDATE", changeStatus: "committed", - formChangeByPreviousFormChangeId: { - changeStatus: "committed", - newFormData: { - status: "on_track", - comments: "I am an unchanged comment on Annual Report #2", - projectId: 1, - reportType: "Annual", - reportDueDate: - "I am an unchanged due date on Annual Report #2", - submittedDate: - "I am an unchanged received date on Annual Report #2", - reportingRequirementIndex: 2, - }, - }, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -111,7 +85,6 @@ const mockQueryPayload = { }, operation: "UPDATE", changeStatus: "committed", - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -133,7 +106,6 @@ const mockQueryPayload = { }, operation: "ARCHIVE", changeStatus: "committed", - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -141,6 +113,51 @@ const mockQueryPayload = { }, ], }, + latestCommittedAnnualReportFormChanges: { + edges: [ + { + node: { + newFormData: { + status: "on_track", + comments: "I am the old comment on Annual Report #1", + projectId: 1, + reportType: "Annual", + reportDueDate: "2025-06-18T23:59:59.999-07:00", + submittedDate: "2025-07-01T23:59:59.999-07:00", + reportingRequirementIndex: 1, + }, + }, + }, + { + node: { + newFormData: { + status: "on_track", + comments: "I am an unchanged comment on Annual Report #2", + projectId: 1, + reportType: "Annual", + reportDueDate: + "I am an unchanged due date on Annual Report #2", + submittedDate: + "I am an unchanged received date on Annual Report #2", + reportingRequirementIndex: 2, + }, + }, + }, + { + node: { + newFormData: { + status: "on_track", + comments: "I have been deleted", + projectId: 1, + reportType: "Annual", + reportDueDate: "2022-06-03T23:59:59.999-07:00", + submittedDate: "2022-06-24T23:59:59.999-07:00", + reportingRequirementIndex: 4, + }, + }, + }, + ], + }, }; return result; }, diff --git a/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx index 9c8f3f6b81..61e515451e 100644 --- a/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectAttachmentsFormSummary.test.tsx @@ -34,6 +34,7 @@ const defaultQueryResolver = { node: { id: "test-attachment-form-change-id-1", rowId: 1, + operation: "CREATE", asProjectAttachment: { attachmentByAttachmentId: { id: "test-attachment-id-1", @@ -52,6 +53,7 @@ const defaultQueryResolver = { node: { id: "test-attachment-form-change-id-2", rowId: 2, + operation: "CREATE", asProjectAttachment: { attachmentByAttachmentId: { id: "test-attachment-id-2", @@ -66,6 +68,25 @@ const defaultQueryResolver = { }, }, }, + { + node: { + id: "test-attachment-form-change-id-3", + rowId: 3, + operation: "ARCHIVE", + asProjectAttachment: { + attachmentByAttachmentId: { + id: "test-attachment-id-3", + fileName: "test-attachment-3.jpg", + fileType: "image/jpeg", + fileSize: 123456, + createdAt: "2021-01-03T00:00:00.000Z", + cifUserByCreatedBy: { + fullName: "Test User 2", + }, + }, + }, + }, + }, ], }, }, @@ -111,11 +132,20 @@ describe("The project's attachment page", () => { ).not.toBeInTheDocument(); }); - it("Displays all attachments", () => { + it("Displays all attachments that were created in this revision", () => { componentTestingHelper.loadQuery(); componentTestingHelper.renderComponent(); + expect(screen.getAllByText(/Create/i)).toHaveLength(2); expect(screen.getByText(/test-attachment-1.jpg/i)).toBeInTheDocument(); expect(screen.getByText(/test-attachment-2.jpg/i)).toBeInTheDocument(); }); + + it("Displays all attachments that were archived in this revision", () => { + componentTestingHelper.loadQuery(); + componentTestingHelper.renderComponent(); + + expect(screen.getAllByText(/Archive/i)).toHaveLength(1); + expect(screen.getByText(/test-attachment-3.jpg/i)).toBeInTheDocument(); + }); }); diff --git a/app/tests/unit/components/Form/ProjectContactFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectContactFormSummary.test.tsx index 4d2760c6e7..a66bee449e 100644 --- a/app/tests/unit/components/Form/ProjectContactFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectContactFormSummary.test.tsx @@ -39,18 +39,6 @@ const mockQueryPayload = { fullName: "Test Full Name primary", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - contactIndex: 1, - contactId: 1, - projectId: 1, - }, - asProjectContact: { - contactByContactId: { - fullName: "Test Full Name primary PREVIOUS", - }, - }, - }, formByJsonSchemaName: { jsonSchema: projectContactProdSchema, }, @@ -70,18 +58,6 @@ const mockQueryPayload = { fullName: "I did not change", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - contactIndex: 1, - contactId: 2, - projectId: 1, - }, - asProjectContact: { - contactByContactId: { - fullName: "I did not change", - }, - }, - }, formByJsonSchemaName: { jsonSchema: projectContactProdSchema, }, @@ -101,7 +77,6 @@ const mockQueryPayload = { fullName: "I was added", }, }, - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: projectContactProdSchema, }, @@ -122,20 +97,54 @@ const mockQueryPayload = { }, }, operation: "ARCHIVE", - formChangeByPreviousFormChangeId: { - newFormData: { - contactIndex: 4, - contactId: 4, - projectId: 1, + formByJsonSchemaName: { + jsonSchema: projectContactProdSchema, + }, + }, + }, + ], + }, + latestCommittedProjectContactFormChanges: { + edges: [ + { + node: { + newFormData: { + contactIndex: 1, + contactId: 1, + projectId: 1, + }, + asProjectContact: { + contactByContactId: { + fullName: "Test Full Name primary PREVIOUS", }, - asProjectContact: { - contactByContactId: { - fullName: "I was removed", - }, + }, + }, + }, + { + node: { + newFormData: { + contactIndex: 1, + contactId: 2, + projectId: 1, + }, + asProjectContact: { + contactByContactId: { + fullName: "I did not change", }, }, - formByJsonSchemaName: { - jsonSchema: projectContactProdSchema, + }, + }, + { + node: { + newFormData: { + contactIndex: 4, + contactId: 4, + projectId: 1, + }, + asProjectContact: { + contactByContactId: { + fullName: "I was removed", + }, }, }, }, diff --git a/app/tests/unit/components/Form/ProjectEmissionIntensityReportFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectEmissionIntensityReportFormSummary.test.tsx index 62fae357e4..c55d9fb7b6 100644 --- a/app/tests/unit/components/Form/ProjectEmissionIntensityReportFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectEmissionIntensityReportFormSummary.test.tsx @@ -42,21 +42,27 @@ const defaultMockResolver = { baselineEmissionIntensity: 0.87654321, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - comments: "squirtle", - reportType: "TEIMP", - projectId: 1, - reportingRequirementIndex: 1, - reportingRequirementId: 1, - baselineEmissionIntensity: 0.985145, - }, - }, formDataRecordId: 1, }, }, ], }, + latestCommittedEmissionIntensityReportFormChange: { + edges: [ + { + node: { + newFormData: { + comments: "squirtle", + reportType: "TEIMP", + projectId: 1, + reportingRequirementIndex: 1, + reportingRequirementId: 1, + baselineEmissionIntensity: 0.985145, + }, + }, + }, + ], + }, }; }, }; @@ -195,13 +201,19 @@ describe("the emission intensity report form component", () => { targetEmissionIntensity: 0, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - baselineEmissionIntensity: 0, - targetEmissionIntensity: 0.12345678, - postProjectEmissionIntensity: 654, - totalLifetimeEmissionReduction: 456, - }, + }, + }, + ], + }, + latestCommittedEmissionIntensityReportFormChange: { + edges: [ + { + node: { + newFormData: { + baselineEmissionIntensity: 0, + targetEmissionIntensity: 0.12345678, + postProjectEmissionIntensity: 654, + totalLifetimeEmissionReduction: 456, }, }, }, @@ -235,6 +247,7 @@ describe("the emission intensity report form component", () => { expect(screen.getByText("654.00000000")).toHaveClass("diffOld"); expect(screen.getByText("456.00000000")).toHaveClass("diffOld"); }); + it("displays calculated values diff", () => { const customPayload = { Form() { @@ -257,12 +270,6 @@ describe("the emission intensity report form component", () => { maximumPerformanceMilestoneAmount: 123, actualPerformanceMilestoneAmount: null, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - calculatedEiPerformance: 20, - paymentPercentage: 44, - maximumPerformanceMilestoneAmount: 321, - actualPerformanceMilestoneAmount: 789, - }, }, }, ], @@ -273,10 +280,10 @@ describe("the emission intensity report form component", () => { node: { isPristine: false, operation: "UPDATE", - calculatedEiPerformance: 22, - paymentPercentage: 13, - maximumPerformanceMilestoneAmount: 741, - actualPerformanceMilestoneAmount: 357, + calculatedEiPerformance: 20, + paymentPercentage: 44, + maximumPerformanceMilestoneAmount: 321, + actualPerformanceMilestoneAmount: 789, }, }, ], @@ -289,31 +296,27 @@ describe("the emission intensity report form component", () => { expect( screen.getByText(/ghg emission intensity performance/i) ).toBeInTheDocument(); - expect(screen.getByText(/20\.00 %/i)).toBeInTheDocument(); //old calculatedEiPerformance + expect(screen.getByText(/20\.00 %/i)).toBeInTheDocument(); //latest committed calculatedEiPerformance expect(screen.getByText(/10\.00 %/i)).toBeInTheDocument(); //new calculatedEiPerformance - expect(screen.getByText(/22\.00 %/i)).toBeInTheDocument(); //latest committed calculatedEiPerformance expect( screen.getByText( /payment percentage of performance milestone amount \(%\)/i ) ).toBeInTheDocument(); - expect(screen.getByText(/44\.00 %/i)).toBeInTheDocument(); //old paymentPercentage + expect(screen.getByText(/44\.00 %/i)).toBeInTheDocument(); //latest committed paymentPercentage expect(screen.getByText(/40\.00 %/i)).toBeInTheDocument(); //new paymentPercentage - expect(screen.getByText(/13\.00 %/i)).toBeInTheDocument(); //latest committed paymentPercentage expect( screen.getByText(/maximum performance milestone amount/i) ).toBeInTheDocument(); - expect(screen.getByText(/\$321\.00/i)).toBeInTheDocument(); //old maximumPerformanceMilestoneAmount + expect(screen.getByText(/\$321\.00/i)).toBeInTheDocument(); //latest committed maximumPerformanceMilestoneAmount expect(screen.getByText(/\$123\.00/i)).toBeInTheDocument(); //new maximumPerformanceMilestoneAmount - expect(screen.getByText(/\$741\.00/i)).toBeInTheDocument(); //latest committed maximumPerformanceMilestoneAmount expect( screen.getByText(/actual performance milestone amount/i) ).toBeInTheDocument(); - expect(screen.getByText(/\$789\.00/i)).toBeInTheDocument(); //old actualPerformanceMilestoneAmount - expect(screen.getByText(/\$357\.00/i)).toBeInTheDocument(); //latest committed actualPerformanceMilestoneAmount + expect(screen.getByText(/\$789\.00/i)).toBeInTheDocument(); //latest committed actualPerformanceMilestoneAmount }); it("renders the help tooltips", () => { diff --git a/app/tests/unit/components/Form/ProjectFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectFormSummary.test.tsx index d52ebd3325..a263ecf181 100644 --- a/app/tests/unit/components/Form/ProjectFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectFormSummary.test.tsx @@ -51,35 +51,41 @@ const mockQueryPayload = { name: "Test Project Status Name", }, }, - formChangeByPreviousFormChangeId: { - rank: 987654321, - newFormData: { - proposalReference: "Test Proposal Reference PREVIOUS", - operatorId: 1, - fundingStreamRfpId: 1, - projectStatusId: 1, - summary: "Test Summary", - projectName: "Test Project Name", - totalFundingRequest: 100.0, - score: 1, - projectType: "test project type PREVIOUS", - }, - asProject: { - operatorByOperatorId: { - legalName: "Test Legal Name PREVIOUS", - bcRegistryId: "Test BC Registry ID", - }, - fundingStreamRfpByFundingStreamRfpId: { - year: 2020, - fundingStreamByFundingStreamId: { - description: "Test Funding Stream Description", + }, + latestCommittedProjectFormChanges: { + edges: [ + { + node: { + rank: 987654321, + newFormData: { + proposalReference: "Test Proposal Reference PREVIOUS", + operatorId: 1, + fundingStreamRfpId: 1, + projectStatusId: 1, + summary: "Test Summary", + projectName: "Test Project Name", + totalFundingRequest: 100.0, + score: 1, + projectType: "test project type PREVIOUS", + }, + asProject: { + operatorByOperatorId: { + legalName: "Test Legal Name PREVIOUS", + bcRegistryId: "Test BC Registry ID", + }, + fundingStreamRfpByFundingStreamRfpId: { + year: 2020, + fundingStreamByFundingStreamId: { + description: "Test Funding Stream Description", + }, + }, + projectStatusByProjectStatusId: { + name: "Test Project Status Name", + }, }, - }, - projectStatusByProjectStatusId: { - name: "Test Project Status Name", }, }, - }, + ], }, }; return result; diff --git a/app/tests/unit/components/Form/ProjectFundingAgreementFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectFundingAgreementFormSummary.test.tsx index 17f09244eb..040de13d18 100644 --- a/app/tests/unit/components/Form/ProjectFundingAgreementFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectFundingAgreementFormSummary.test.tsx @@ -38,8 +38,8 @@ const mockQueryPayloadEP = { edges: [ { node: { - proponentsSharePercentage: 5, // will trigger three diffs - totalProjectValue: 6, // will trigger three diffs + proponentsSharePercentage: 5, // will trigger diffs + totalProjectValue: 6, // will trigger diffs newFormData: { projectId: "Test Project ID", maxFundingAmount: 200, @@ -63,27 +63,6 @@ const mockQueryPayloadEP = { grossPaymentsToDate: "1.00", isPristine: false, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - proponentsSharePercentage: 10, // will trigger three diffs - totalProjectValue: 12, // will trigger three diffs - newFormData: { - projectId: "Test Project ID", - maxFundingAmount: 200, - provinceSharePercentage: 50, - holdbackPercentage: 10.23, - anticipatedFundingAmount: 300, - proponentCost: 100, - contractStartDate: "2021-01-01T23:59:59.999-07:00", - projectAssetsLifeEndDate: "2021-12-31T23:59:59.999-07:00", - additionalFundingSources: [ - { - source: "Test Source Name", - amount: 1000, - status: "Awaiting Approval", - }, - ], - }, - }, }, }, ], @@ -92,17 +71,25 @@ const mockQueryPayloadEP = { edges: [ { node: { - proponentsSharePercentage: 15, // will trigger three diffs - totalProjectValue: 18, // will trigger three diffs + proponentsSharePercentage: 10, // will trigger diffs + totalProjectValue: 12, // will trigger diffs newFormData: { - // add data as required + projectId: "Test Project ID", + maxFundingAmount: 200, + provinceSharePercentage: 50, + holdbackPercentage: 10.23, + anticipatedFundingAmount: 300, + proponentCost: 100, + contractStartDate: "2021-01-01T23:59:59.999-07:00", + projectAssetsLifeEndDate: "2021-12-31T23:59:59.999-07:00", + additionalFundingSources: [ + { + source: "Test Source Name", + amount: 1000, + status: "Awaiting Approval", + }, + ], }, - eligibleExpensesToDate: "1.00", - holdbackAmountToDate: "0.00", - netPaymentsToDate: "1.00", - grossPaymentsToDate: "1.00", - isPristine: false, - operation: "UPDATE", }, }, ], @@ -140,8 +127,8 @@ const mockQueryPayloadIA = { edges: [ { node: { - proponentsSharePercentage: 7, // will trigger three diffs - totalProjectValue: 8, // will trigger three diffs + proponentsSharePercentage: 7, // will trigger diffs + totalProjectValue: 8, // will trigger diffs newFormData: { projectId: "Test Project ID", maxFundingAmount: 501, @@ -154,20 +141,6 @@ const mockQueryPayloadIA = { calculatedTotalPaymentAmountToDate: "511.0", isPristine: false, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - proponentsSharePercentage: 14, // will trigger three diffs - totalProjectValue: 16, // will trigger three diffs - newFormData: { - projectId: "Test Project ID", - maxFundingAmount: 500, - provinceSharePercentage: 50, - anticipatedFundingAmount: 200, - proponentCost: 100, - contractStartDate: "2021-01-01T23:59:59.999-07:00", - projectAssetsLifeEndDate: - "2023-03-28T14:41:23.626132-07:00", - }, - }, }, }, ], @@ -176,12 +149,17 @@ const mockQueryPayloadIA = { edges: [ { node: { - proponentsSharePercentage: 21, // will trigger three diffs - totalProjectValue: 24, // will trigger three diffs - newFormData: {}, - calculatedTotalPaymentAmountToDate: "511.0", - isPristine: false, - operation: "UPDATE", + proponentsSharePercentage: 14, // will trigger diffs + totalProjectValue: 16, // will trigger diffs + newFormData: { + projectId: "Test Project ID", + maxFundingAmount: 500, + provinceSharePercentage: 50, + anticipatedFundingAmount: 200, + proponentCost: 100, + contractStartDate: "2021-01-01T23:59:59.999-07:00", + projectAssetsLifeEndDate: "2023-03-28T14:41:23.626132-07:00", + }, }, }, ], @@ -306,18 +284,12 @@ describe("The Project Funding Agreement Form Summary", () => { expect( screen.getByText("10.00 %", { selector: ".diffOld" }) ).toBeInTheDocument(); // old proponentsSharePercentage - expect( - screen.getByText("15.00 %", { selector: ".diffOld" }) - ).toBeInTheDocument(); // latest committed proponentsSharePercentage expect( screen.getByText("$6.00", { selector: ".diffNew" }) ).toBeInTheDocument(); // new totalProjectValue expect( screen.getByText("$12.00", { selector: ".diffOld" }) ).toBeInTheDocument(); // old totalProjectValue - expect( - screen.getByText("$18.00", { selector: ".diffOld" }) - ).toBeInTheDocument(); // latest committed totalProjectValue }); it("Displays diffs of the the data fields that have changed for an IA form", () => { @@ -340,9 +312,6 @@ describe("The Project Funding Agreement Form Summary", () => { expect( screen.getByText("14.00 %", { selector: ".diffOld" }) ).toBeInTheDocument(); - expect( - screen.getByText("21.00 %", { selector: ".diffOld" }) - ).toBeInTheDocument(); expect( screen.getByText("$8.00", { selector: ".diffNew" }) @@ -350,9 +319,6 @@ describe("The Project Funding Agreement Form Summary", () => { expect( screen.getByText("$16.00", { selector: ".diffOld" }) ).toBeInTheDocument(); - expect( - screen.getByText("$24.00", { selector: ".diffOld" }) - ).toBeInTheDocument(); }); it("Displays all data for an EP project when isFirstRevision is true (Project Creation)", () => { diff --git a/app/tests/unit/components/Form/ProjectManagerFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectManagerFormSummary.test.tsx index 18f8d09dab..d28fb44a34 100644 --- a/app/tests/unit/components/Form/ProjectManagerFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectManagerFormSummary.test.tsx @@ -42,18 +42,6 @@ const mockQueryPayload = { fullName: "Test Full Name Update", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - projectId: 1, - cifUserId: 1, - projectManagerLabelId: 1, - }, - asProjectManager: { - cifUserByCifUserId: { - fullName: "Test Full Name Update PREVIOUS", - }, - }, - }, }, projectManagerLabel: { label: "Test First Label", @@ -75,18 +63,6 @@ const mockQueryPayload = { fullName: "Test Full Name Archive", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - projectId: 1, - cifUserId: 1, - projectManagerLabelId: 1, - }, - asProjectManager: { - cifUserByCifUserId: { - fullName: "Test Full Name Archive PREVIOUS", - }, - }, - }, }, projectManagerLabel: { label: "Test Second Label", @@ -108,7 +84,6 @@ const mockQueryPayload = { fullName: "Test Full Name Create", }, }, - formChangeByPreviousFormChangeId: null, }, projectManagerLabel: { label: "Test Third Label", @@ -130,18 +105,6 @@ const mockQueryPayload = { fullName: "Test Full Name No Change", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - projectId: 1, - cifUserId: 4, - projectManagerLabelId: 4, - }, - asProjectManager: { - cifUserByCifUserId: { - fullName: "Test Full Name No Change", - }, - }, - }, }, projectManagerLabel: { label: "Test Fourth Label", @@ -150,6 +113,52 @@ const mockQueryPayload = { }, ], }, + latestCommittedProjectManagerFormChanges: { + edges: [ + { + node: { + newFormData: { + projectId: 1, + cifUserId: 1, + projectManagerLabelId: 1, + }, + asProjectManager: { + cifUserByCifUserId: { + fullName: "Test Full Name Update PREVIOUS", + }, + }, + }, + }, + { + node: { + newFormData: { + projectId: 1, + cifUserId: 1, + projectManagerLabelId: 1, + }, + asProjectManager: { + cifUserByCifUserId: { + fullName: "Test Full Name Archive PREVIOUS", + }, + }, + }, + }, + { + node: { + newFormData: { + projectId: 1, + cifUserId: 4, + projectManagerLabelId: 4, + }, + asProjectManager: { + cifUserByCifUserId: { + fullName: "Test Full Name No Change", + }, + }, + }, + }, + ], + }, }, }; }, diff --git a/app/tests/unit/components/Form/ProjectMilestoneReportFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectMilestoneReportFormSummary.test.tsx index c8f95cb561..60a96d8e7f 100644 --- a/app/tests/unit/components/Form/ProjectMilestoneReportFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectMilestoneReportFormSummary.test.tsx @@ -50,17 +50,6 @@ const mockQueryPayload = { adjustedHoldbackAmount: 88, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - description: "bulbasaur", - projectId: 1, - reportingRequirementIndex: 1, - reportDueDate: "2020-01-01T13:59:59.999-07:00", - reportType: "Advanced", - reportingRequirementId: 1, - hasExpenses: true, - }, - }, formDataRecordId: 1, }, }, @@ -72,24 +61,43 @@ const mockQueryPayload = { description: "Removed comment", projectId: 1, reportDueDate: "2020-01-07T23:59:59.999-07:00", - reportingRequirementIndex: 1, + reportingRequirementIndex: 2, reportingRequirementId: 2, }, operation: "ARCHIVE", - formChangeByPreviousFormChangeId: { - newFormData: { - description: "Removed comment", - projectId: 1, - reportDueDate: "2020-01-05T23:59:59.999-07:00", - reportingRequirementIndex: 1, - reportingRequirementId: 2, - }, - }, formDataRecordId: 2, }, }, ], }, + latestCommittedMilestoneFormChanges: { + edges: [ + { + node: { + newFormData: { + description: "bulbasaur", + projectId: 1, + reportingRequirementIndex: 1, + reportDueDate: "2020-01-01T13:59:59.999-07:00", + reportType: "Advanced", + reportingRequirementId: 1, + hasExpenses: true, + }, + }, + }, + { + node: { + newFormData: { + description: "Removed comment", + projectId: 1, + reportDueDate: "2020-01-05T23:59:59.999-07:00", + reportingRequirementIndex: 2, + reportingRequirementId: 2, + }, + }, + }, + ], + }, }; return result; }, @@ -125,7 +133,7 @@ describe("The Project Milestone Report Form Summary", () => { componentTestingHelper.renderComponent(); // changed fields - expect(screen.getByText("Milestone Description")).toBeInTheDocument(); + expect(screen.getByText(/Milestone Description/i)).toBeInTheDocument(); expect(screen.getByText("Milestone Type")).toBeInTheDocument(); // Archive milestone report @@ -220,97 +228,6 @@ describe("The Project Milestone Report Form Summary", () => { expect(screen.getByText(/\$88\.00/i)).toBeInTheDocument(); }); - it("Displays diffs of the data fields that were updated and shows latest committed values", () => { - const latestCommittedData = { - latestCommittedMilestoneFormChanges: { - edges: [ - { - node: { - newFormData: { - totalEligibleExpenses: 1000, - description: "charmander", - projectId: 1, - reportingRequirementIndex: 1, - reportType: "General", - reportDueDate: "2020-01-10T23:59:59.999-07:00", - reportingRequirementId: 1, - hasExpenses: true, - calculatedGrossAmount: 567, - calculatedNetAmount: 789, - calculatedHoldbackAmount: 891, - adjustedNetAmount: 89, - adjustedGrossAmount: 67, - adjustedHoldbackAmount: 91, - }, - }, - }, - ], - }, - }; - - const mockQueryPayloadLatestCommitted = { - ...mockQueryPayload, - ProjectRevision() { - const originalProjectRevision = mockQueryPayload.ProjectRevision(); - const modifiedProjectRevision = { - ...originalProjectRevision, - latestCommittedMilestoneFormChanges: { - edges: [ - { - node: { - newFormData: - latestCommittedData.latestCommittedMilestoneFormChanges - .edges[0].node.newFormData, - }, - }, - ], - }, - }; - return modifiedProjectRevision; - }, - }; - - componentTestingHelper.defaultQueryResolver = - mockQueryPayloadLatestCommitted; - componentTestingHelper.loadQuery(mockQueryPayloadLatestCommitted); - componentTestingHelper.renderComponent(); - - // calculated values - expect( - screen.getByText("Gross Payment Amount This Milestone") - ).toBeInTheDocument(); - expect(screen.getByText(/\$567\.00/i)).toBeInTheDocument(); - expect(screen.getByText(/\$999\.00/i)).toBeInTheDocument(); - expect( - screen.getByText("Net Payment Amount This Milestone") - ).toBeInTheDocument(); - expect(screen.getByText(/\$789\.00/i)).toBeInTheDocument(); - expect(screen.getByText(/\$888\.00/i)).toBeInTheDocument(); - expect( - screen.getByText("Holdback Amount This Milestone") - ).toBeInTheDocument(); - expect(screen.getByText(/\$891\.00/i)).toBeInTheDocument(); - expect(screen.getByText(/\$111\.00/i)).toBeInTheDocument(); - - // adjusted values - expect( - screen.getByText("Gross Payment Amount This Milestone (Adjusted)") - ).toBeInTheDocument(); - expect(screen.getByText(/\$99\.00/i)).toBeInTheDocument(); - - expect(screen.getByText(/\$89\.00/i)).toBeInTheDocument(); - expect( - screen.getByText("Net Payment Amount This Milestone (Adjusted)") - ).toBeInTheDocument(); - expect(screen.getByText(/\$11\.00/i)).toBeInTheDocument(); - expect(screen.getByText(/\$67\.00/i)).toBeInTheDocument(); - expect( - screen.getByText("Holdback Amount This Milestone (Adjusted)") - ).toBeInTheDocument(); - expect(screen.getByText(/\$88\.00/i)).toBeInTheDocument(); - expect(screen.getByText(/\$91\.00/i)).toBeInTheDocument(); - }); - it("Displays diffs of the data fields that were updated and the old values", () => { const mockQueryPayloadWithDiffs = { Form() { @@ -344,28 +261,34 @@ describe("The Project Milestone Report Form Summary", () => { adjustedHoldbackAmount: 23, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - description: "bulbasaur", - projectId: 1, - reportingRequirementIndex: 1, - reportDueDate: "2020-01-01T13:59:59.999-07:00", - reportType: "Advanced", - reportingRequirementId: 1, - hasExpenses: true, - calculatedNetAmount: 111, - calculatedGrossAmount: 112, - calculatedHoldbackAmount: 113, - adjustedNetAmount: 11, - adjustedGrossAmount: 12, - adjustedHoldbackAmount: 13, - }, - }, formDataRecordId: 1, }, }, ], }, + latestCommittedMilestoneFormChanges: { + edges: [ + { + node: { + newFormData: { + description: "bulbasaur", + projectId: 1, + reportingRequirementIndex: 1, + reportDueDate: "2020-01-01T13:59:59.999-07:00", + reportType: "Advanced", + reportingRequirementId: 1, + hasExpenses: true, + calculatedNetAmount: 111, + calculatedGrossAmount: 112, + calculatedHoldbackAmount: 113, + adjustedNetAmount: 11, + adjustedGrossAmount: 12, + adjustedHoldbackAmount: 13, + }, + }, + }, + ], + }, }; return result; }, @@ -425,7 +348,6 @@ describe("The Project Milestone Report Form Summary", () => { node: { id: "Tooltip Test 1", isPristine: null, - formChangeByPreviousFormChangeId: null, newFormData: { calculatedGrossAmount: 123, calculatedHoldbackAmount: 456, diff --git a/app/tests/unit/components/Form/ProjectQuarterlyReportForm.test.tsx b/app/tests/unit/components/Form/ProjectQuarterlyReportForm.test.tsx index 6a33c6160f..3d9aed9ddb 100644 --- a/app/tests/unit/components/Form/ProjectQuarterlyReportForm.test.tsx +++ b/app/tests/unit/components/Form/ProjectQuarterlyReportForm.test.tsx @@ -48,7 +48,6 @@ const defaultMockResolver = { }, operation: "CREATE", changeStatus: "pending", - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -68,7 +67,6 @@ const defaultMockResolver = { }, operation: "CREATE", changeStatus: "pending", - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, diff --git a/app/tests/unit/components/Form/ProjectQuarterlyReportFormSummary.test.tsx b/app/tests/unit/components/Form/ProjectQuarterlyReportFormSummary.test.tsx index 307faaa95b..c0d9eadf5d 100644 --- a/app/tests/unit/components/Form/ProjectQuarterlyReportFormSummary.test.tsx +++ b/app/tests/unit/components/Form/ProjectQuarterlyReportFormSummary.test.tsx @@ -36,14 +36,6 @@ const mockQueryPayload = { reportingRequirementIndex: 1, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - comments: "Test comment", - projectId: 1, - reportDueDate: "2020-01-01T23:59:59.999-07:00", - reportingRequirementIndex: 1, - }, - }, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -57,17 +49,25 @@ const mockQueryPayload = { comments: "Not updated comment", projectId: 1, reportDueDate: "2020-01-03T23:59:59.999-07:00", - reportingRequirementIndex: 1, + reportingRequirementIndex: 2, }, operation: "UPDATE", - formChangeByPreviousFormChangeId: { - newFormData: { - comments: "Not updated comment", - projectId: 1, - reportDueDate: "2020-01-03T23:59:59.999-07:00", - reportingRequirementIndex: 1, - }, + formByJsonSchemaName: { + jsonSchema: reportingRequirementProdSchema, + }, + }, + }, + { + node: { + id: "Test ID - 4", + isPristine: false, + newFormData: { + comments: "Removed comment", + projectId: 1, + reportDueDate: "2020-01-05T23:59:59.999-07:00", + reportingRequirementIndex: 3, }, + operation: "ARCHIVE", formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, @@ -81,36 +81,48 @@ const mockQueryPayload = { comments: "Added comment", projectId: 1, reportDueDate: "2020-01-04T23:59:59.999-07:00", - reportingRequirementIndex: 1, + reportingRequirementIndex: 4, }, operation: "CREATE", - formChangeByPreviousFormChangeId: null, formByJsonSchemaName: { jsonSchema: reportingRequirementProdSchema, }, }, }, + ], + }, + latestCommittedProjectQuarterlyReportFormChanges: { + edges: [ { node: { - id: "Test ID - 4", - isPristine: false, + id: "Test ID 5", newFormData: { - comments: "Removed comment", + comments: "Test comment", projectId: 1, - reportDueDate: "2020-01-05T23:59:59.999-07:00", + reportDueDate: "2020-01-01T23:59:59.999-07:00", reportingRequirementIndex: 1, }, - operation: "ARCHIVE", - formChangeByPreviousFormChangeId: { - newFormData: { - comments: "Removed comment", - projectId: 1, - reportDueDate: "2020-01-05T23:59:59.999-07:00", - reportingRequirementIndex: 1, - }, + }, + }, + { + node: { + id: "Test ID 6", + newFormData: { + comments: "Not updated comment", + projectId: 1, + reportDueDate: "2020-01-03T23:59:59.999-07:00", + reportingRequirementIndex: 2, }, - formByJsonSchemaName: { - jsonSchema: reportingRequirementProdSchema, + }, + }, + { + node: { + id: "Test ID 7", + newFormData: { + comments: "Removed comment", + projectId: 1, + reportDueDate: "2020-01-05T23:59:59.999-07:00", + reportingRequirementIndex: 3, }, }, }, diff --git a/app/tests/unit/components/ProjectRevision/CollapsibleFormWidget.test.tsx b/app/tests/unit/components/ProjectRevision/CollapsibleFormWidget.test.tsx index 67c1735067..111aa8a6f0 100644 --- a/app/tests/unit/components/ProjectRevision/CollapsibleFormWidget.test.tsx +++ b/app/tests/unit/components/ProjectRevision/CollapsibleFormWidget.test.tsx @@ -50,34 +50,40 @@ const mockQueryPayload = { name: "Test Project Status Name", }, }, - formChangeByPreviousFormChangeId: { - newFormData: { - proposalReference: "Test Proposal Reference PREVIOUS", - operatorId: 1, - fundingStreamRfpId: 1, - projectStatusId: 1, - summary: "Test Summary", - projectName: "Test Project Name", - totalFundingRequest: 100.0, - score: 1, - projectType: "test project type PREVIOUS", - }, - asProject: { - operatorByOperatorId: { - legalName: "Test Legal Name PREVIOUS", - bcRegistryId: "Test BC Registry ID", - }, - fundingStreamRfpByFundingStreamRfpId: { - year: 2020, - fundingStreamByFundingStreamId: { - description: "Test Funding Stream Description", + }, + latestCommittedProjectFormChanges: { + edges: [ + { + node: { + newFormData: { + proposalReference: "Test Proposal Reference PREVIOUS", + operatorId: 1, + fundingStreamRfpId: 1, + projectStatusId: 1, + summary: "Test Summary", + projectName: "Test Project Name", + totalFundingRequest: 100.0, + score: 1, + projectType: "test project type PREVIOUS", + }, + asProject: { + operatorByOperatorId: { + legalName: "Test Legal Name PREVIOUS", + bcRegistryId: "Test BC Registry ID", + }, + fundingStreamRfpByFundingStreamRfpId: { + year: 2020, + fundingStreamByFundingStreamId: { + description: "Test Funding Stream Description", + }, + }, + projectStatusByProjectStatusId: { + name: "Test Project Status Name", + }, }, - }, - projectStatusByProjectStatusId: { - name: "Test Project Status Name", }, }, - }, + ], }, }; }, diff --git a/app/tests/unit/lib/theme/CustomDiffFields.test.tsx b/app/tests/unit/lib/theme/CustomDiffFields.test.tsx index 36027a32bd..eb2c0997d8 100644 --- a/app/tests/unit/lib/theme/CustomDiffFields.test.tsx +++ b/app/tests/unit/lib/theme/CustomDiffFields.test.tsx @@ -13,6 +13,11 @@ const testSchema = { title: "Proposal Reference", }, numberTest: { + type: "number", + title: "Score", + default: undefined, + }, + moneyTest: { type: "number", title: "Total Funding Request", default: undefined, @@ -27,12 +32,18 @@ const testSchema = { }; const uiTestSchema = { - "ui:order": ["stringTest", "numberTest", "numericIdTest"], + "ui:order": ["stringTest", "numberTest", "moneyTest", "numericIdTest"], stringTest: { "bcgov:size": "small", "ui:help": (e.g. 2020-RFP-1-ABCD-123), }, numberTest: { + "ui:widget": "NumberWidget", + isMoney: false, + "ui:col-md": 12, + "bcgov:size": "small", + }, + moneyTest: { "ui:widget": "NumberWidget", isMoney: true, "ui:col-md": 12, @@ -52,33 +63,24 @@ const uiTestSchema = { const formData = { stringTest: "stringTest NEW", numberTest: 100, + moneyTest: 10, numericIdTest: 1, }; -const oldFormData = { - stringTest: "stringTest OLD", - numberTest: 200, - numericIdTest: 2, +const latestCommittedData = { + stringTest: "stringTest LAST COMMITTED", + numberTest: 300, + moneyTest: 30, + numericIdTest: 3, }; -const oldUiTestSchema = JSON.parse(JSON.stringify(uiTestSchema)); - -oldUiTestSchema.numericIdTest["ui:options"].text = "I replaced the OLD ID"; - const latestCommittedUiTestSchema = JSON.parse(JSON.stringify(uiTestSchema)); latestCommittedUiTestSchema.numericIdTest["ui:options"].text = "I am the last committed value"; -const latestCommittedData = { - stringTest: "stringTest LAST COMMITTED", - numberTest: 300, - numericIdTest: 3, -}; - describe("The Object Field Template", () => { - // 111 - it("shows diffs when there is an old, new, and latest committed value, and old !== latest committed", () => { + it("shows diffs when the latest committed value exists and has been changed in the new data", () => { const componentUnderTest = render( { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - latestCommittedData, - oldUiSchema: oldUiTestSchema, + latestCommittedData: latestCommittedData, latestCommittedUiSchema: latestCommittedUiTestSchema, operation: "UPDATE", }} @@ -97,62 +97,25 @@ describe("The Object Field Template", () => { ); expect(componentUnderTest.getByText("stringTest NEW")).toBeInTheDocument(); - expect(componentUnderTest.getByText("stringTest OLD")).toBeInTheDocument(); - expect( - componentUnderTest.getByText(/^(.*?)stringTest LAST COMMITTED/) - ).toBeInTheDocument(); - expect(componentUnderTest.getByText("$100.00")).toBeInTheDocument(); - expect(componentUnderTest.getByText("$200.00")).toBeInTheDocument(); - expect(componentUnderTest.getByText("$300.00")).toBeInTheDocument(); - expect( - componentUnderTest.getByText("I replaced the ID") - ).toBeInTheDocument(); - expect( - componentUnderTest.getByText("I replaced the OLD ID") - ).toBeInTheDocument(); expect( - componentUnderTest.getByText(/I am the last committed value/i) + componentUnderTest.getByText("stringTest LAST COMMITTED") ).toBeInTheDocument(); - }); - it("shows diffs when there is an old, new, and latest committed value and old === latest committed", () => { - const componentUnderTest = render( - - ); + expect(componentUnderTest.getByText("100")).toBeInTheDocument(); + expect(componentUnderTest.getByText("300")).toBeInTheDocument(); + + expect(componentUnderTest.getByText("$10.00")).toBeInTheDocument(); + expect(componentUnderTest.getByText("$30.00")).toBeInTheDocument(); - expect(componentUnderTest.getByText("stringTest NEW")).toBeInTheDocument(); - expect(componentUnderTest.getByText("stringTest OLD")).toBeInTheDocument(); - expect( - componentUnderTest.queryByText(/^(.*?)LAST COMMITTED/) - ).not.toBeInTheDocument(); - expect(componentUnderTest.getByText("$100.00")).toBeInTheDocument(); - expect(componentUnderTest.getByText("$200.00")).toBeInTheDocument(); - expect(componentUnderTest.queryByText("$300.00")).not.toBeInTheDocument(); expect( - componentUnderTest.getByText("I replaced the ID") + componentUnderTest.getByText(/I am the last committed value/i) ).toBeInTheDocument(); expect( - componentUnderTest.getByText("I replaced the OLD ID") + componentUnderTest.getByText("I replaced the ID") ).toBeInTheDocument(); - expect( - componentUnderTest.queryByText(/I am the last committed value/i) - ).not.toBeInTheDocument(); }); - // 101 - it("shows data has been removed when there is old data and latest committed data but no new data", () => { + + it("shows data has been removed when there is latest committed data but no new data", () => { const componentUnderTest = render( { uiSchema={uiTestSchema} formData={null} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, operation: "CREATE", latestCommittedData, + latestCommittedUiSchema: latestCommittedUiTestSchema, }} /> ); - expect(componentUnderTest.getByText("stringTest OLD")).toHaveClass( - "diffOld" - ); - expect(componentUnderTest.getByText("$200.00")).toHaveClass("diffOld"); - expect(componentUnderTest.getByText("I replaced the OLD ID")).toHaveClass( - "diffOld" - ); + expect( + componentUnderTest.getByText("stringTest LAST COMMITTED") + ).toHaveClass("diffOld"); + expect(componentUnderTest.getByText("$30.00")).toHaveClass("diffOld"); + expect( + componentUnderTest.getByText("I am the last committed value") + ).toHaveClass("diffOld"); }); - // 010 - it("shows data has been added when there is newData, and there is no old data or no latest committed", () => { + it("shows data has been added when there is newData, and there is no latest committed", () => { const componentUnderTest = render( { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: null, - oldUiSchema: oldUiTestSchema, + latestCommittedUiSchema: latestCommittedUiTestSchema, operation: "CREATE", }} /> @@ -197,13 +157,13 @@ describe("The Object Field Template", () => { expect(componentUnderTest.getByText("stringTest NEW")).toHaveClass( "diffNew" ); - expect(componentUnderTest.getByText("$100.00")).toHaveClass("diffNew"); + expect(componentUnderTest.getByText("$10.00")).toHaveClass("diffNew"); expect(componentUnderTest.getByText("I replaced the ID")).toHaveClass( "diffNew" ); }); // 011 - it("shows data has been added when there is newData, latest and there is no old data", () => { + it("shows data has been added when there is newData, and latest committed data", () => { const componentUnderTest = render( { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: null, - oldUiSchema: oldUiTestSchema, operation: "CREATE", - latestCommittedData: latestCommittedData, + latestCommittedData, }} /> ); @@ -226,8 +184,8 @@ describe("The Object Field Template", () => { expect( componentUnderTest.getByText("stringTest LAST COMMITTED") ).toHaveClass("diffOld"); - expect(componentUnderTest.getByText("$100.00")).toHaveClass("diffNew"); - expect(componentUnderTest.getByText("$300.00")).toHaveClass("diffOld"); + expect(componentUnderTest.getByText("100")).toHaveClass("diffNew"); + expect(componentUnderTest.getByText("300")).toHaveClass("diffOld"); }); // numericId test @@ -240,8 +198,8 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, + latestCommittedData, + latestCommittedUiSchema: latestCommittedUiTestSchema, operation: "UPDATE", }} /> @@ -262,18 +220,15 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, + latestCommittedData: latestCommittedData, operation: "UPDATE", }} /> ); - expect(componentUnderTest.getByText("$100.00")).toBeInTheDocument(); + expect(componentUnderTest.getByText("$10.00")).toBeInTheDocument(); }); it("shows the number without a preceding $ when uiSchema.isMoney is false in a NumberField's uiSchema", () => { - delete uiTestSchema.numberTest.isMoney; - const componentUnderTest = render( { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, + latestCommittedData, + latestCommittedUiSchema: latestCommittedUiTestSchema, operation: "UPDATE", }} /> @@ -303,8 +258,6 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={null} formContext={{ - oldData: null, - oldUiSchema: null, operation: "CREATE", }} /> @@ -323,8 +276,8 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, + latestCommittedData, + latestCommittedUiSchema: latestCommittedUiTestSchema, operation: "UPDATE", isAmendmentsAndOtherRevisionsSpecific: true, }} @@ -334,10 +287,11 @@ describe("The Object Field Template", () => { expect(componentUnderTest.getByText("stringTest NEW")).toHaveClass( "diffNew" ); - expect(componentUnderTest.getByText("stringTest OLD")).toHaveClass( - "diffOld" - ); + expect( + componentUnderTest.getByText("stringTest LAST COMMITTED") + ).toHaveClass("diffOld"); }); + it("handles 0 when latest committed data is 0", () => { const latestCommittedDataWithZero = { stringTest: "stringTest LAST COMMITTED", @@ -352,8 +306,6 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={formData} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, operation: "UPDATE", isAmendmentsAndOtherRevisionsSpecific: true, latestCommittedData: latestCommittedDataWithZero, @@ -377,134 +329,12 @@ describe("The Object Field Template", () => { uiSchema={uiTestSchema} formData={formDataWithZero} formContext={{ - oldData: oldFormData, - oldUiSchema: oldUiTestSchema, - operation: "UPDATE", - isAmendmentsAndOtherRevisionsSpecific: true, - latestCommittedData, - }} - /> - ); - expect(componentUnderTest.getByText("0")).toHaveClass("diffNew"); - }); - it("handles 0 when latestCommittedData and oldData are 0, (the same), and newFormData exists", () => { - const latestCommittedDataWithZero = { - stringTest: "stringTest LAST COMMITTED", - numberTest: 0, - }; - - const oldDataWithZero = { - stringTest: "stringTest FORM DATA", - numberTest: 0, - }; - - const componentUnderTest = render( - - ); - expect(componentUnderTest.getAllByText("0")[0]).toHaveClass("diffOld"); - expect(componentUnderTest.getAllByText("0")).toHaveLength(1); - expect(componentUnderTest.getByText("100")).toHaveClass("diffNew"); - }); - it("handles 0 when oldData is 0", () => { - const oldDataWithZero = { - stringTest: "", - numberTest: 0, - numericIdTest: 0, - }; - const componentUnderTest = render( - ); - - expect(componentUnderTest.getAllByText("0")[0]).toHaveClass("diffOld"); - expect(componentUnderTest.getAllByText("0")).toHaveLength(1); - }); - - it("handles 0 when oldData and latest data is 0", () => { - const oldDataWithZero = { - stringTest: "", - numberTest: 0, - numericIdTest: 0, - }; - const latestCommittedDataWithZero = { - stringTest: "", - numberTest: 0, - numericIdTest: 0, - }; - const componentUnderTest = render( - - ); - - expect(componentUnderTest.getAllByText("0")[0]).toHaveClass("diffOld"); - expect(componentUnderTest.getAllByText("0")).toHaveLength(1); - }); - it("handles 0 when newData and latest data is 0", () => { - const formDataWithZero = { - stringTest: "", - numberTest: 0, - numericIdTest: 0, - }; - const latestCommittedDataWithZero = { - stringTest: "", - numberTest: 0, - numericIdTest: 0, - }; - const componentUnderTest = render( - - ); - - expect(componentUnderTest.getByText("200")).toHaveClass("diffOld"); expect(componentUnderTest.getByText("0")).toHaveClass("diffNew"); }); });