diff --git a/services/ui-src/src/measures/2021/globalValidations/index.ts b/services/ui-src/src/measures/2021/globalValidations/index.ts index da16c2bb40..35ba909962 100644 --- a/services/ui-src/src/measures/2021/globalValidations/index.ts +++ b/services/ui-src/src/measures/2021/globalValidations/index.ts @@ -3,7 +3,7 @@ export * from "./omsValidator"; export * as Types from "./types"; export * from "shared/globalValidations/validateAtLeastOneDataSource"; -export * from "./validateAtLeastOneDeviationFieldFilled"; +export * from "shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "./validateDualPopInformation"; diff --git a/services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts b/services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts deleted file mode 100644 index 6d347ef1da..0000000000 --- a/services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts +++ /dev/null @@ -1,135 +0,0 @@ -import * as DC from "dataConstants"; -import { test_setup } from "../testHelpers/_helper"; -import { testFormData } from "../testHelpers/_testFormData"; -import { getDeviationNDRArray } from "measures/2021/globalValidations"; -import { validateAtLeastOneDeviationFieldFilled } from "."; - -describe("validateAtLeastOneNDRInDeviationOfMeasureSpec", () => { - let formData: any = {}; - let errorArray: FormError[]; - - const _run_validation = ( - data: any, - noPM?: boolean, - errorMessage?: string - ): FormError[] => { - const { ageGroups, performanceMeasureArray } = test_setup(data); - const deviationArray = getDeviationNDRArray( - data.DeviationOptions, - data.Deviations, - true - ); - const didCalculationsDeviate = data[DC.DID_CALCS_DEVIATE] === DC.YES; - return [ - ...validateAtLeastOneDeviationFieldFilled( - noPM ? [[]] : performanceMeasureArray, - ageGroups, - deviationArray, - didCalculationsDeviate, - errorMessage - ), - ]; - }; - - const _check_errors = (data: any, numErrors: number, noPM?: boolean) => { - errorArray = _run_validation(data, noPM); - expect(errorArray.length).toBe(numErrors); - }; - - beforeEach(() => { - formData = JSON.parse(JSON.stringify(testFormData)); // reset data - errorArray = []; - }); - - it("Default Form Data", () => { - _check_errors(formData, 0); - }); - - it("Calculations deviated, but somehow no performance measure data", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - _check_errors(formData, 0, true); - }); - - it("Calculations deviated, but no answer given", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - _check_errors(formData, 1); - }); - - it("Calculations deviated, but partial answer given", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATIONS] = { - Test: { - [DC.RATE_DEVIATIONS_SELECTED]: ["numerator"], - }, - }; - _check_errors(formData, 1); - }); - - it("Calculations deviated, only numerator filled", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATIONS] = { - Test: { - [DC.RATE_DEVIATIONS_SELECTED]: ["numerator"], - numerator: "testString", - }, - }; - _check_errors(formData, 0); - }); - - it("Calculations deviated, only denominator filled", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATIONS] = { - Test: { - [DC.RATE_DEVIATIONS_SELECTED]: ["denominator"], - denominator: "testString", - }, - }; - _check_errors(formData, 0); - }); - - it("Calculations deviated, only other filled", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATIONS] = { - Test: { - [DC.RATE_DEVIATIONS_SELECTED]: ["Other"], - other: "testString", - }, - }; - _check_errors(formData, 0); - }); - - it("Calculations deviated all fields filled", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATIONS] = { - Test: { - [DC.RATE_DEVIATIONS_SELECTED]: ["numerator", "denominator", "Other"], - numerator: "testString", - denominator: "testString", - other: "testString", - }, - }; - _check_errors(formData, 0); - }); - - it("Error message text should match default errorMessage", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - errorArray = _run_validation(formData); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe( - "At least one item must be selected and completed (Numerator, Denominator, or Other)" - ); - }); - - it("Error message text should match provided errorMessage", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - const errorMessage = "Another one bites the dust."; - errorArray = _run_validation(formData, undefined, errorMessage); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe(errorMessage); - }); -}); diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/index.ts b/services/ui-src/src/measures/2022/shared/globalValidations/index.ts index da16c2bb40..35ba909962 100644 --- a/services/ui-src/src/measures/2022/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2022/shared/globalValidations/index.ts @@ -3,7 +3,7 @@ export * from "./omsValidator"; export * as Types from "./types"; export * from "shared/globalValidations/validateAtLeastOneDataSource"; -export * from "./validateAtLeastOneDeviationFieldFilled"; +export * from "shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "./validateDualPopInformation"; diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts b/services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts deleted file mode 100644 index a5c7299fdd..0000000000 --- a/services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts +++ /dev/null @@ -1,81 +0,0 @@ -import * as Types from "shared/types"; -import { FormRateField } from "../types"; -import { LabelData } from "utils"; - -// When a user inputs data in multiple NDR sets in a performance measure -// Then the user must complete at least one NDR set in the Deviation of measure specification. -export const validateAtLeastOneDeviationFieldFilled = ( - performanceMeasureArray: FormRateField[][], - ageGroups: LabelData[], - deviationArray: Types.DeviationFields[] | any, - didCalculationsDeviate: boolean, - errorMessage?: string -) => { - let errorArray: FormError[] = []; - let ndrCount = 0; - let atLeastOneDevNDR: boolean = false; - let isCCWAD: boolean = false; - - if (didCalculationsDeviate) { - ageGroups.forEach((_ageGroup, i) => { - performanceMeasureArray?.forEach((_performanceObj, index) => { - if ( - performanceMeasureArray[index] && - performanceMeasureArray[index][i] && - performanceMeasureArray[index][i].denominator && - performanceMeasureArray[index][i].numerator && - performanceMeasureArray[index][i].rate - ) { - // CCW-AD - if ( - performanceMeasureArray[index][i].label === - "All Women Ages 21 to 44" - ) { - isCCWAD = true; - } - ndrCount++; - } - }); - }); - - if (ndrCount > 0) { - deviationArray.forEach((deviationNDR: any) => { - // CCW-AD validation - let selectedOptions; - if (isCCWAD) { - selectedOptions = deviationNDR.SelectedOptions[0]; - if ( - deviationNDR[selectedOptions].denominator || - deviationNDR[selectedOptions].numerator || - deviationNDR[selectedOptions].other - ) { - atLeastOneDevNDR = true; - } else { - atLeastOneDevNDR = false; - } - } else { - if ( - deviationNDR?.denominator || - deviationNDR?.numerator || - deviationNDR?.other - ) { - atLeastOneDevNDR = true; - } else { - atLeastOneDevNDR = false; - } - } - return atLeastOneDevNDR; - }); - - if (!atLeastOneDevNDR) { - errorArray.push({ - errorLocation: "Deviations from Measure Specifications", - errorMessage: - errorMessage ?? - "At least one item must be selected and completed (Numerator, Denominator, or Other)", - }); - } - } - } - return errorArray; -}; diff --git a/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx index ce6b071d9f..220bd0e6d3 100644 --- a/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2022/shared/util/validationsMock.tsx @@ -1,5 +1,5 @@ import * as validateAtLeastOneDataSource from "shared/globalValidations/validateAtLeastOneDataSource"; -import * as validateAtLeastOneDeviationFieldFilled from "measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; +import * as validateAtLeastOneDeviationFieldFilled from "shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2022/shared/globalValidations/validateDualPopInformation"; diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/index.ts b/services/ui-src/src/measures/2023/shared/globalValidations/index.ts index 3381a22ba8..e1ce5a0779 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2023/shared/globalValidations/index.ts @@ -6,7 +6,7 @@ export * from "shared/globalValidations/validateAtLeastOneDataSource"; export * from "shared/globalValidations/validateAtLeastOneDefinitionOfPopulation"; export * from "./validateAtLeastOneDataSourceType"; export * from "shared/globalValidations/validateAtLeastOneDeliverySystem"; -export * from "./validateAtLeastOneDeviationFieldFilled"; +export * from "shared/globalValidations/validateDeviationTextFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "shared/globalValidations/validateDateRangeRadioButtonCompletion"; diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts b/services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts deleted file mode 100644 index 45e75228e1..0000000000 --- a/services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// When a user indicates that there is a deviation, they must add an explanation in the textarea. -export const validateAtLeastOneDeviationFieldFilled = ( - didCalculationsDeviate: boolean, - deviationReason: string, - errorMessage?: string -) => { - let errorArray: FormError[] = []; - let reasonGiven: boolean = false; - - if (didCalculationsDeviate) { - if (!!deviationReason) { - reasonGiven = true; - } - - if (!reasonGiven) { - errorArray.push({ - errorLocation: "Deviations from Measure Specifications", - errorMessage: errorMessage ?? "Deviation(s) must be explained", - }); - } - } - return errorArray; -}; diff --git a/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx index b96fbd0309..97c974bf11 100644 --- a/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2023/shared/util/validationsMock.tsx @@ -2,7 +2,7 @@ import * as validateAtLeastOneDataSource from "shared/globalValidations/validate import * as validateAtLeastOneDefinitionOfPopulation from "shared/globalValidations/validateAtLeastOneDefinitionOfPopulation"; import * as validateAtLeastOneDataSourceType from "measures/2023/shared/globalValidations/validateAtLeastOneDataSourceType"; import * as validateAtLeastOneDeliverySystem from "shared/globalValidations/validateAtLeastOneDeliverySystem"; -import * as validateAtLeastOneDeviationFieldFilled from "measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; +import * as validateAtLeastOneDeviationFieldFilled from "shared/globalValidations/validateDeviationTextFieldFilled"; import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2023/shared/globalValidations/validateDualPopInformation"; diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/index.ts b/services/ui-src/src/measures/2024/shared/globalValidations/index.ts index 9ebc576fec..b9b2b0d0c1 100644 --- a/services/ui-src/src/measures/2024/shared/globalValidations/index.ts +++ b/services/ui-src/src/measures/2024/shared/globalValidations/index.ts @@ -7,7 +7,7 @@ export * from "shared/globalValidations/validateAtLeastOneDefinitionOfPopulation export * from "shared/globalValidations/validateHybridMeasurePopulation"; export * from "./validateAtLeastOneDataSourceType"; export * from "shared/globalValidations/validateAtLeastOneDeliverySystem"; -export * from "./validateAtLeastOneDeviationFieldFilled"; +export * from "shared/globalValidations/validateDeviationTextFieldFilled"; export * from "shared/globalValidations/validateAtLeastOneRateComplete"; export * from "shared/globalValidations/validateBothDatesInRange"; export * from "shared/globalValidations/validateDateRangeRadioButtonCompletion"; diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts b/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts deleted file mode 100644 index d45e607aee..0000000000 --- a/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts +++ /dev/null @@ -1,61 +0,0 @@ -import * as DC from "dataConstants"; -import { testFormData } from "../testHelpers/_testFormData"; -import { validateAtLeastOneDeviationFieldFilled } from "."; - -describe("validateAtLeastOneNDRInDeviationOfMeasureSpec", () => { - let formData: any = {}; - let errorArray: FormError[]; - - const _run_validation = (data: any, errorMessage?: string): FormError[] => { - const didCalculationsDeviate = data[DC.DID_CALCS_DEVIATE] === DC.YES; - const deviationReason = data[DC.DEVIATION_REASON]; - return [ - ...validateAtLeastOneDeviationFieldFilled( - didCalculationsDeviate, - deviationReason, - errorMessage - ), - ]; - }; - - const _check_errors = (data: any, numErrors: number) => { - errorArray = _run_validation(data); - expect(errorArray.length).toBe(numErrors); - }; - - beforeEach(() => { - formData = JSON.parse(JSON.stringify(testFormData)); // reset data - errorArray = []; - }); - - it("Default Form Data", () => { - _check_errors(formData, 0); - }); - - it("Calculations deviated, but no answer given", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - _check_errors(formData, 1); - }); - - it("Calculations deviated, reason given", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - formData[DC.DEVIATION_OPTIONS] = ["Test"]; - formData[DC.DEVIATION_REASON] = "Deviation Reason Here"; - _check_errors(formData, 0); - }); - - it("Error message text should match default errorMessage", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - errorArray = _run_validation(formData); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe("Deviation(s) must be explained"); - }); - - it("Error message text should match provided errorMessage", () => { - formData[DC.DID_CALCS_DEVIATE] = DC.YES; - const errorMessage = "Another one bites the dust."; - errorArray = _run_validation(formData, errorMessage); - expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe(errorMessage); - }); -}); diff --git a/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts b/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts deleted file mode 100644 index 45e75228e1..0000000000 --- a/services/ui-src/src/measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -// When a user indicates that there is a deviation, they must add an explanation in the textarea. -export const validateAtLeastOneDeviationFieldFilled = ( - didCalculationsDeviate: boolean, - deviationReason: string, - errorMessage?: string -) => { - let errorArray: FormError[] = []; - let reasonGiven: boolean = false; - - if (didCalculationsDeviate) { - if (!!deviationReason) { - reasonGiven = true; - } - - if (!reasonGiven) { - errorArray.push({ - errorLocation: "Deviations from Measure Specifications", - errorMessage: errorMessage ?? "Deviation(s) must be explained", - }); - } - } - return errorArray; -}; diff --git a/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx b/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx index eb4ebce901..718f6bbfc4 100644 --- a/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx +++ b/services/ui-src/src/measures/2024/shared/util/validationsMock.tsx @@ -2,7 +2,7 @@ import * as validateAtLeastOneDataSource from "shared/globalValidations/validate import * as validateAtLeastOneDefinitionOfPopulation from "shared/globalValidations/validateAtLeastOneDefinitionOfPopulation"; import * as validateAtLeastOneDataSourceType from "measures/2024/shared/globalValidations/validateAtLeastOneDataSourceType"; import * as validateAtLeastOneDeliverySystem from "shared/globalValidations/validateAtLeastOneDeliverySystem"; -import * as validateAtLeastOneDeviationFieldFilled from "measures/2024/shared/globalValidations/validateAtLeastOneDeviationFieldFilled"; +import * as validateAtLeastOneDeviationFieldFilled from "shared/globalValidations/validateDeviationTextFieldFilled"; import * as validateAtLeastOneRateComplete from "shared/globalValidations/validateAtLeastOneRateComplete"; import * as validateBothDatesInRange from "shared/globalValidations/validateBothDatesInRange"; import * as validateDualPopInformation from "measures/2024/shared/globalValidations/validateDualPopInformation"; diff --git a/services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts b/services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts similarity index 95% rename from services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts rename to services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts index 20b9f8a65f..abf26a43da 100644 --- a/services/ui-src/src/measures/2022/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts +++ b/services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts @@ -1,6 +1,6 @@ import * as DC from "dataConstants"; -import { test_setup } from "../testHelpers/_helper"; -import { testFormData } from "../testHelpers/_testFormData"; +import { test_setup } from "measures/2022/shared/globalValidations/testHelpers/_helper"; +import { testFormData } from "measures/2022/shared/globalValidations/testHelpers/_testFormData"; import { getDeviationNDRArray } from "measures/2022/shared/globalValidations"; import { validateAtLeastOneDeviationFieldFilled } from "."; diff --git a/services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts b/services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts similarity index 97% rename from services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts rename to services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts index a5c7299fdd..08955f582d 100644 --- a/services/ui-src/src/measures/2021/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts +++ b/services/ui-src/src/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.ts @@ -1,5 +1,5 @@ import * as Types from "shared/types"; -import { FormRateField } from "../types"; +import { FormRateField } from "shared/types/TypeValidations"; import { LabelData } from "utils"; // When a user inputs data in multiple NDR sets in a performance measure diff --git a/services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts b/services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.test.ts similarity index 92% rename from services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts rename to services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.test.ts index d45e607aee..de43e51e58 100644 --- a/services/ui-src/src/measures/2023/shared/globalValidations/validateAtLeastOneDeviationFieldFilled/index.test.ts +++ b/services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.test.ts @@ -1,5 +1,5 @@ import * as DC from "dataConstants"; -import { testFormData } from "../testHelpers/_testFormData"; +import { testFormData } from "measures/2024/shared/globalValidations/testHelpers/_testFormData"; import { validateAtLeastOneDeviationFieldFilled } from "."; describe("validateAtLeastOneNDRInDeviationOfMeasureSpec", () => { @@ -48,7 +48,7 @@ describe("validateAtLeastOneNDRInDeviationOfMeasureSpec", () => { formData[DC.DID_CALCS_DEVIATE] = DC.YES; errorArray = _run_validation(formData); expect(errorArray.length).toBe(1); - expect(errorArray[0].errorMessage).toBe("Deviation(s) must be explained"); + expect(errorArray[0].errorMessage).toBe("Variation(s) must be explained"); }); it("Error message text should match provided errorMessage", () => { diff --git a/services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.ts b/services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.ts new file mode 100644 index 0000000000..71e7285461 --- /dev/null +++ b/services/ui-src/src/shared/globalValidations/validateDeviationTextFieldFilled/index.ts @@ -0,0 +1,45 @@ +import { getMeasureYear } from "utils/getMeasureYear"; + +// When a user indicates that there is a deviation, they must add an explanation in the textarea. +const getLabels = (year: number) => { + switch (year) { + case 2021: + case 2022: + case 2023: + return { + location: "Deviations from Measure Specifications", + message: "Deviation(s) must be explained", + }; + default: + return { + location: "Variations from Measure Specifications", + message: "Variation(s) must be explained", + }; + } +}; + +export const validateAtLeastOneDeviationFieldFilled = ( + didCalculationsDeviate: boolean, + deviationReason: string, + errorMessage?: string +) => { + let errorArray: FormError[] = []; + let reasonGiven: boolean = false; + + const year = getMeasureYear(); + const labels = getLabels(year); + + if (didCalculationsDeviate) { + if (!!deviationReason) { + reasonGiven = true; + } + + if (!reasonGiven) { + errorArray.push({ + errorLocation: labels.location, + errorMessage: errorMessage ?? labels.message, + }); + } + } + return errorArray; +};