diff --git a/src/components/plans/ChargeAccordion.tsx b/src/components/plans/ChargeAccordion.tsx index a9e58604f..8f316dc87 100644 --- a/src/components/plans/ChargeAccordion.tsx +++ b/src/components/plans/ChargeAccordion.tsx @@ -41,6 +41,7 @@ import { VolumeRangesFragmentDoc, } from '~/generated/graphql' import { useInternationalization } from '~/hooks/core/useInternationalization' +import { useChargeForm } from '~/hooks/plans/useChargeForm' import { useCurrentUser } from '~/hooks/useCurrentUser' import { NAV_HEIGHT, theme } from '~/styles' @@ -186,21 +187,64 @@ export const ChargeAccordion = memo( const { translate } = useInternationalization() const { isPremium } = useCurrentUser() const { type: actionType } = useDuplicatePlanVar() + const { + getChargeModelComboboxData, + getIsPayInAdvanceOptionDisabled, + getIsProRatedOptionDisabled, + } = useChargeForm() const chargeErrors = formikProps?.errors?.charges - const { localCharge, initialLocalCharge, hasDefaultPropertiesErrors, hasErrorInCharges } = - useMemo(() => { - return { - localCharge: formikProps.values.charges[index], - initialLocalCharge: formikProps.initialValues.charges[index], - hasDefaultPropertiesErrors: - typeof chargeErrors === 'object' && - typeof chargeErrors[index] === 'object' && - // @ts-ignore - typeof chargeErrors[index].properties === 'object', - hasErrorInCharges: Boolean(chargeErrors && chargeErrors[index]), - } - }, [chargeErrors, formikProps.initialValues.charges, formikProps.values.charges, index]) + const { + chargeModelComboboxData, + hasDefaultPropertiesErrors, + hasErrorInCharges, + initialLocalCharge, + isPayInAdvanceOptionDisabled, + isProratedOptionDisabled, + // isAbleToSwitchToProRated, + localCharge, + } = useMemo(() => { + const formikCharge = formikProps.values.charges[index] + const localChargeModelComboboxData = getChargeModelComboboxData({ + isPremium, + aggregationType: formikCharge.billableMetric.aggregationType, + }) + const localIsPayInAdvanceOptionDisabled = getIsPayInAdvanceOptionDisabled({ + aggregationType: formikCharge.billableMetric.aggregationType, + chargeModel: formikCharge.chargeModel, + isPayInAdvance: formikCharge.payInAdvance || false, + isProrated: formikCharge.prorated || false, + isRecurring: formikCharge.billableMetric.recurring, + }) + const localIsProratedOptionDisabled = getIsProRatedOptionDisabled({ + isPayInAdvance: formikCharge.payInAdvance || false, + aggregationType: formikCharge.billableMetric.aggregationType, + chargeModel: formikCharge.chargeModel, + }) + + return { + chargeModelComboboxData: localChargeModelComboboxData, + hasDefaultPropertiesErrors: + typeof chargeErrors === 'object' && + typeof chargeErrors[index] === 'object' && + // @ts-ignore + typeof chargeErrors[index].properties === 'object', + hasErrorInCharges: Boolean(chargeErrors && chargeErrors[index]), + initialLocalCharge: formikProps.initialValues.charges[index], + isPayInAdvanceOptionDisabled: localIsPayInAdvanceOptionDisabled, + isProratedOptionDisabled: localIsProratedOptionDisabled, + localCharge: formikCharge, + } + }, [ + chargeErrors, + formikProps.initialValues.charges, + formikProps.values.charges, + getChargeModelComboboxData, + getIsPayInAdvanceOptionDisabled, + getIsProRatedOptionDisabled, + index, + isPremium, + ]) const [showSpendingMinimum, setShowSpendingMinimum] = useState( !!initialLocalCharge?.minAmountCents && Number(initialLocalCharge?.minAmountCents) > 0, @@ -217,71 +261,43 @@ export const ChargeAccordion = memo( ) }, [initialLocalCharge?.minAmountCents]) - useEffect( - () => { - const payInAdvance = localCharge.payInAdvance + const handleUpdate = useCallback( + (name: string, value: unknown) => { + // IMPORTANT: This check should stay first in this function + // If user is not premium and try to switch to graduated percentage pricing + // We should show the premium modal and prevent any formik value change + if (name === 'chargeModel' && !isPremium && value === ChargeModelEnum.GraduatedPercentage) { + premiumWarningDialogRef?.current?.openDialog() + return + } - if (payInAdvance === true) { - formikProps.setFieldValue(`charges.${index}.minAmountCents`, undefined) + // NOTE: We prevent going further if the change is about the charge model and the value remain the same + // It prevents fixing the properties to be wrongly reset to default on 2nd select. + if (name === 'chargeModel' && value === localCharge.chargeModel) return - if (localCharge.chargeModel === ChargeModelEnum.Graduated) { - formikProps.setFieldValue(`charges.${index}.prorated`, false) - } - } else { - // Pay in arrears - formikProps.setFieldValue(`charges.${index}.invoiceable`, true) + let currentChargeValues: LocalChargeInput = { + ...localCharge, + [name]: value, } - }, - // eslint-disable-next-line react-hooks/exhaustive-deps - [index, localCharge.chargeModel, localCharge.payInAdvance], - ) - const handleUpdate = useCallback( - (name: string, value: unknown) => { if (name === 'chargeModel') { - // IMPORTANT: This check should stay first in this function - // If user is not premium and try to switch to graduated percentage pricing - // We should show the premium modal and prevent any formik value change - if (!isPremium && value === ChargeModelEnum.GraduatedPercentage) { - premiumWarningDialogRef?.current?.openDialog() - return - } - - // Reset pay in advance when switching charge model - if ( - (value === ChargeModelEnum.Graduated && localCharge.payInAdvance) || - value === ChargeModelEnum.Volume || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.MaxAgg || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.LatestAgg || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.WeightedSumAgg - ) { - formikProps.setFieldValue(`charges.${index}.payInAdvance`, false) - } - - // Reset prorated when switching charge model - if ( - (localCharge.billableMetric.recurring && value === ChargeModelEnum.Graduated) || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.WeightedSumAgg || - value === ChargeModelEnum.GraduatedPercentage || - value === ChargeModelEnum.Package || - value === ChargeModelEnum.Percentage - ) { - formikProps.setFieldValue(`charges.${index}.prorated`, false) + // Reset charge data to default when switching charge model + currentChargeValues = { + ...currentChargeValues, + payInAdvance: false, + prorated: false, + invoiceable: true, + properties: getPropertyShape({}), + filters: [], + taxes: [], } } - formikProps.setFieldValue(`charges.${index}.${name}`, value) + formikProps.setFieldValue(`charges.${index}`, currentChargeValues) }, - [ - formikProps, - index, - isPremium, - localCharge.billableMetric.aggregationType, - localCharge.billableMetric.recurring, - localCharge.payInAdvance, - premiumWarningDialogRef, - ], + // eslint-disable-next-line react-hooks/exhaustive-deps + [index, isPremium, localCharge, premiumWarningDialogRef], ) const taxValueForBadgeDisplay = useMemo((): string | undefined => { @@ -323,27 +339,6 @@ export const ChargeAccordion = memo( }) }, [localCharge.taxes, taxesCollection]) - const isProratedOptionDisabled = useMemo(() => { - return ( - (localCharge.payInAdvance && localCharge.chargeModel === ChargeModelEnum.Graduated) || - localCharge.chargeModel === ChargeModelEnum.GraduatedPercentage || - localCharge.chargeModel === ChargeModelEnum.Package || - localCharge.chargeModel === ChargeModelEnum.Percentage || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.WeightedSumAgg - ) - }, [ - localCharge.billableMetric.aggregationType, - localCharge.chargeModel, - localCharge.payInAdvance, - ]) - - const proratedOptionHelperText = useMemo(() => { - if (isProratedOptionDisabled) - return translate('text_649c54823c9089006247625a', { chargeModel: localCharge.chargeModel }) - - return translate('text_649c54823c90890062476259') - }, [isProratedOptionDisabled, translate, localCharge.chargeModel]) - const chargePayInAdvanceDescription = useMemo(() => { if (localCharge.chargeModel === ChargeModelEnum.Volume) { return translate('text_6669b493fae79a0095e639bc') @@ -468,77 +463,10 @@ export const ChargeAccordion = memo( )} - - {translate('text_65201b8216455901fe273dd5')} - - - } - data={[ - { - label: translate('text_62793bbb599f1c01522e919f'), - value: ChargeModelEnum.Graduated, - }, - ...(!localCharge.billableMetric.recurring - ? [ - ...(localCharge.billableMetric.aggregationType !== - AggregationTypeEnum.LatestAgg - ? [ - { - labelNode: ( - - - - {translate('text_64de472463e2da6b31737db0')} - - - {!isPremium && } - - ), - label: translate('text_64de472463e2da6b31737db0'), - value: ChargeModelEnum.GraduatedPercentage, - }, - ] - : []), - { - label: translate('text_6282085b4f283b0102655868'), - value: ChargeModelEnum.Package, - }, - - ...(localCharge.billableMetric.aggregationType !== - AggregationTypeEnum.LatestAgg - ? [ - { - label: translate('text_62a0b7107afa2700a65ef6e2'), - value: ChargeModelEnum.Percentage, - }, - ] - : []), - ] - : []), - { - label: translate('text_624aa732d6af4e0103d40e6f'), - value: ChargeModelEnum.Standard, - }, - { - label: translate('text_6304e74aab6dbc18d615f386'), - value: ChargeModelEnum.Volume, - }, - ...(localCharge.billableMetric.aggregationType === AggregationTypeEnum.CustomAgg - ? [ - { - label: translate('text_663dea5702b60301d8d064fa'), - value: ChargeModelEnum.Custom, - }, - ] - : []), - ] - // Sort the combobox values by label - .sort((a, b) => translate(a.label).localeCompare(translate(b.label)))} + label={translate('text_65201b8216455901fe273dd5')} + data={chargeModelComboboxData} value={localCharge.chargeModel} helperText={translate( localCharge.chargeModel === ChargeModelEnum.Percentage @@ -855,12 +783,7 @@ export const ChargeAccordion = memo( { label: translate('text_6669b493fae79a0095e63988'), value: true, - disabled: - localCharge.chargeModel === ChargeModelEnum.Volume || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.MaxAgg || - localCharge.billableMetric.aggregationType === AggregationTypeEnum.LatestAgg || - localCharge.billableMetric.aggregationType === - AggregationTypeEnum.WeightedSumAgg, + disabled: isPayInAdvanceOptionDisabled, }, ]} /> @@ -870,7 +793,13 @@ export const ChargeAccordion = memo( name={`charge-${localCharge.id}-prorated`} label={translate('text_649c54823c90890062476255')} disabled={isInSubscriptionForm || disabled || isProratedOptionDisabled} - subLabel={proratedOptionHelperText} + subLabel={ + isProratedOptionDisabled + ? translate('text_649c54823c9089006247625a', { + chargeModel: localCharge.chargeModel, + }) + : translate('text_649c54823c90890062476259') + } checked={!!localCharge.prorated} onChange={(value) => handleUpdate('prorated', Boolean(value))} /> @@ -1128,18 +1057,6 @@ const InlineTaxesWrapper = styled.div` flex-wrap: wrap; ` -const InlineComboboxLabelForPremiumWrapper = styled.div` - display: flex; - align-items: center; - justify-content: space-between; -` - -const InlineComboboxLabel = styled.div` - display: flex; - align-items: center; - gap: ${theme.spacing(2)}; -` - const Summary = styled.div` width: 100%; display: flex; diff --git a/src/components/plans/types.ts b/src/components/plans/types.ts index 877af3cb3..020ff2bc6 100644 --- a/src/components/plans/types.ts +++ b/src/components/plans/types.ts @@ -24,7 +24,7 @@ export type LocalChargeFilterInput = Omit & { +export type LocalChargeInput = Omit & { billableMetric: BillableMetricForPlanFragment id?: string properties?: LocalPropertiesInput diff --git a/src/hooks/plans/__tests__/fixture.ts b/src/hooks/plans/__tests__/fixture.ts new file mode 100644 index 000000000..61fcf8f5d --- /dev/null +++ b/src/hooks/plans/__tests__/fixture.ts @@ -0,0 +1,1708 @@ +import { AggregationTypeEnum, ChargeModelEnum } from '~/generated/graphql' + +const allCombobxOptionsWithoutCustom = [ + ChargeModelEnum.Graduated, + ChargeModelEnum.GraduatedPercentage, + ChargeModelEnum.Package, + ChargeModelEnum.Percentage, + ChargeModelEnum.Standard, + ChargeModelEnum.Volume, +] + +export const ComboboxTestMatrice = [ + { + aggregationType: AggregationTypeEnum.CountAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + expectedChargesModels: [ChargeModelEnum.Custom, ...allCombobxOptionsWithoutCustom], + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom.filter( + (option) => + option !== ChargeModelEnum.GraduatedPercentage && option !== ChargeModelEnum.Percentage, + ), + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + expectedChargesModels: allCombobxOptionsWithoutCustom, + }, +] + +export const PayinAdvanceOptionDisabledTestMatrice = [ + // ************************ + // ****** COUNT_AGG ******* + // ************************ + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + // Graduated + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + // Package + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + // Standard + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + // Volume + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // ************************ + // *** UNIQUE_COUNT_AGG *** + // ************************ + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + // Graduated + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + // Standard + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + // Volume + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // ************************ + // ****** LATEST_AGG ****** + // ************************ + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Graduated + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Package + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Standard + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Volume + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.LatestAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // ************************ + // ****** MAX_AGG ****** + // ************************ + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Graduated + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Package + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Standard + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // Volume + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.MaxAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + // *********************** + // ******* SUM_AGG ******* + // *********************** + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + // Graduated + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, // Value should be true but it's hanled by parent disabled method + }, + // Standard + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + // Volume + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // ********************** + // ** WEIGHTED_SUM_AGG ** + // ********************** + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, // Value should be true but it's hanled by parent disabled method + }, + // Graduated + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, // Value should be true but it's hanled by parent disabled method + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, // Value should be true but it's hanled by parent disabled method + }, + // Standard + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Volume + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // ********************** + // ***** CUSTOM_AGG ***** + // ********************** + // GraduatedPercentage + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Graduated + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Percentage + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Standard + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: false, + }, + // Volume + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + // Custom + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: false, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: true, + isRecurring: false, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: false, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: true, + isRecurring: true, + isProrated: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: false, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: true, + isRecurring: true, + isProrated: true, + expectedDisabledValue: true, + }, +] + +export const ProratedOptionDisabledTestMatrice = [ + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.UniqueCountAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.SumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.WeightedSumAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: true, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: true, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.GraduatedPercentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Graduated, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Package, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Percentage, + isPayInAdvance: false, + expectedDisabledValue: true, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Standard, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Volume, + isPayInAdvance: false, + expectedDisabledValue: false, + }, + { + aggregationType: AggregationTypeEnum.CustomAgg, + chargeModel: ChargeModelEnum.Custom, + isPayInAdvance: false, + expectedDisabledValue: true, + }, +] diff --git a/src/hooks/plans/__tests__/useChargeForm.test.tsx b/src/hooks/plans/__tests__/useChargeForm.test.tsx new file mode 100644 index 000000000..7e2e1b1da --- /dev/null +++ b/src/hooks/plans/__tests__/useChargeForm.test.tsx @@ -0,0 +1,109 @@ +import { renderHook } from '@testing-library/react' + +import { + ComboboxTestMatrice, + PayinAdvanceOptionDisabledTestMatrice, + ProratedOptionDisabledTestMatrice, +} from './fixture' + +import { + TGetChargeModelComboboxDataProps, + TGetIsPayInAdvanceOptionDisabledProps, + useChargeForm, +} from '../useChargeForm' + +const prepareComboboxTest = async ({ + aggregationType, + isPremium = true, +}: TGetChargeModelComboboxDataProps) => { + const { result } = renderHook(useChargeForm) + + return { + getChargeModelComboboxData: result.current.getChargeModelComboboxData({ + aggregationType, + isPremium, + }), + } +} + +const preparePayinAdvanceOptionDisabledTest = async ({ + aggregationType, + chargeModel, + isPayInAdvance, + isProrated, + isRecurring, +}: TGetIsPayInAdvanceOptionDisabledProps) => { + const { result } = renderHook(useChargeForm) + + return { + getIsPayInAdvanceOptionDisabled: result.current.getIsPayInAdvanceOptionDisabled({ + aggregationType, + chargeModel, + isPayInAdvance, + isProrated, + isRecurring, + }), + } +} + +describe('useChargeForm()', () => { + describe('getChargeModelComboboxData()', () => { + test.each(Array.from(ComboboxTestMatrice))( + 'should return the correct charge models for $aggregationType', + async (testSetup) => { + const { aggregationType, expectedChargesModels } = testSetup + + const { getChargeModelComboboxData } = await prepareComboboxTest({ + aggregationType, + isPremium: true, + }) + + expect(getChargeModelComboboxData.map(({ value }) => value)).toEqual(expectedChargesModels) + }, + ) + }) + + describe('preparePayinAdvanceOptionDisabledTest()', () => { + test.each(Array.from(PayinAdvanceOptionDisabledTestMatrice))( + 'should return the correct value for aggregationType: $aggregationType, chargeModel: $chargeModel, isPayInAdvance: $isPayInAdvance, isProrated: $isProrated, isRecurring: $isRecurring', + async (testSetup) => { + const { + aggregationType, + chargeModel, + isPayInAdvance, + isProrated, + isRecurring, + expectedDisabledValue, + } = testSetup + + const { getIsPayInAdvanceOptionDisabled } = await preparePayinAdvanceOptionDisabledTest({ + aggregationType, + chargeModel, + isPayInAdvance, + isProrated, + isRecurring, + }) + + expect(getIsPayInAdvanceOptionDisabled).toEqual(expectedDisabledValue) + }, + ) + }) + + describe('getIsProratedOptionDisabled()', () => { + test.each(Array.from(ProratedOptionDisabledTestMatrice))( + 'should return the correct value for aggregationType: $aggregationType, chargeModel: $chargeModel', + async (testSetup) => { + const { aggregationType, chargeModel, isPayInAdvance, expectedDisabledValue } = testSetup + + const { result } = renderHook(useChargeForm) + const getIsProRatedOptionDisabled = result.current.getIsProRatedOptionDisabled({ + aggregationType, + chargeModel, + isPayInAdvance, + }) + + expect(getIsProRatedOptionDisabled).toEqual(expectedDisabledValue) + }, + ) + }) +}) diff --git a/src/hooks/plans/useChargeForm.tsx b/src/hooks/plans/useChargeForm.tsx new file mode 100644 index 000000000..f9358f8b5 --- /dev/null +++ b/src/hooks/plans/useChargeForm.tsx @@ -0,0 +1,215 @@ +import styled from 'styled-components' + +import { Icon, Typography } from '~/components/designSystem' +import { BasicComboBoxData } from '~/components/form' +import { AggregationTypeEnum, ChargeModelEnum } from '~/generated/graphql' +import { theme } from '~/styles' + +import { useInternationalization } from '../core/useInternationalization' + +export type TGetChargeModelComboboxDataProps = { + isPremium: boolean + aggregationType: AggregationTypeEnum +} + +export type TGetIsPayInAdvanceOptionDisabledProps = { + aggregationType: AggregationTypeEnum + chargeModel: ChargeModelEnum + isPayInAdvance: boolean + isProrated: boolean + isRecurring: boolean +} + +export type TGetIsProRatedOptionDisabledProps = { + aggregationType: AggregationTypeEnum + chargeModel: ChargeModelEnum + isPayInAdvance: boolean +} + +export type TGetIsAbleToSwitchToProRatedProps = { + aggregationType: AggregationTypeEnum + chargeModel: ChargeModelEnum + isPayInAdvance: boolean +} + +type TUseChargeFormReturn = { + getChargeModelComboboxData: (data: TGetChargeModelComboboxDataProps) => BasicComboBoxData[] + getIsPayInAdvanceOptionDisabled: (data: TGetIsPayInAdvanceOptionDisabledProps) => boolean + getIsProRatedOptionDisabled: (data: TGetIsProRatedOptionDisabledProps) => boolean +} + +export const useChargeForm: () => TUseChargeFormReturn = () => { + const { translate } = useInternationalization() + + const getChargeModelComboboxData = ({ + isPremium, + aggregationType, + }: TGetChargeModelComboboxDataProps): BasicComboBoxData[] => { + const chargeModelComboboxData: BasicComboBoxData[] = [ + { + label: translate('text_62793bbb599f1c01522e919f'), + value: ChargeModelEnum.Graduated, + }, + { + label: translate('text_6282085b4f283b0102655868'), + value: ChargeModelEnum.Package, + }, + { + label: translate('text_624aa732d6af4e0103d40e6f'), + value: ChargeModelEnum.Standard, + }, + { + label: translate('text_6304e74aab6dbc18d615f386'), + value: ChargeModelEnum.Volume, + }, + ] + + if (aggregationType !== AggregationTypeEnum.LatestAgg) { + chargeModelComboboxData.push( + { + labelNode: ( + + + + {translate('text_64de472463e2da6b31737db0')} + + + {!isPremium && } + + ), + label: translate('text_64de472463e2da6b31737db0'), + value: ChargeModelEnum.GraduatedPercentage, + }, + { + label: translate('text_62a0b7107afa2700a65ef6e2'), + value: ChargeModelEnum.Percentage, + }, + ) + } + + if (aggregationType === AggregationTypeEnum.CustomAgg) { + chargeModelComboboxData.push({ + label: translate('text_663dea5702b60301d8d064fa'), + value: ChargeModelEnum.Custom, + }) + } + + return chargeModelComboboxData.sort((a, b) => { + return a.label && b.label ? a.label.localeCompare(b.label) : a.value.localeCompare(b.value) + }) + } + + const getIsPayInAdvanceOptionDisabled = ({ + aggregationType, + chargeModel, + // NOTE: keeping isPayInAdvance for future use + // eslint-disable-next-line @typescript-eslint/no-unused-vars + isPayInAdvance, + isProrated, + isRecurring, + }: TGetIsPayInAdvanceOptionDisabledProps): boolean => { + if ( + aggregationType === AggregationTypeEnum.CountAgg && + chargeModel === ChargeModelEnum.Volume + ) { + return true + } else if (aggregationType === AggregationTypeEnum.UniqueCountAgg) { + if ( + chargeModel === ChargeModelEnum.Volume || + (chargeModel === ChargeModelEnum.Graduated && isProrated) + ) { + return true + } + } else if (aggregationType === AggregationTypeEnum.LatestAgg) { + return true + } else if (aggregationType === AggregationTypeEnum.MaxAgg) { + return true + } else if (aggregationType === AggregationTypeEnum.SumAgg) { + if (chargeModel === ChargeModelEnum.Volume) { + return true + } else if (chargeModel === ChargeModelEnum.Graduated && isRecurring && isProrated) { + return true + } + } else if (aggregationType === AggregationTypeEnum.WeightedSumAgg) { + return true + } else if (aggregationType === AggregationTypeEnum.CustomAgg) { + if (chargeModel !== ChargeModelEnum.Standard && isRecurring && isProrated) { + return true + } + } + + // Enabled by default + return false + } + + const getIsProRatedOptionDisabled = ({ + aggregationType, + chargeModel, + isPayInAdvance, + }: TGetIsProRatedOptionDisabledProps): boolean => { + if (aggregationType === AggregationTypeEnum.UniqueCountAgg) { + if ( + chargeModel === ChargeModelEnum.GraduatedPercentage || + chargeModel === ChargeModelEnum.Package || + chargeModel === ChargeModelEnum.Percentage + ) { + return true + } + + if (isPayInAdvance && chargeModel === ChargeModelEnum.Graduated) { + return true + } + } else if (aggregationType === AggregationTypeEnum.SumAgg) { + if ( + chargeModel === ChargeModelEnum.GraduatedPercentage || + chargeModel === ChargeModelEnum.Package || + chargeModel === ChargeModelEnum.Percentage + ) { + return true + } + + if (isPayInAdvance && chargeModel === ChargeModelEnum.Graduated) { + return true + } + } else if (aggregationType === AggregationTypeEnum.WeightedSumAgg) { + return true + } else if (aggregationType === AggregationTypeEnum.CustomAgg) { + if ( + chargeModel === ChargeModelEnum.GraduatedPercentage || + chargeModel === ChargeModelEnum.Package || + chargeModel === ChargeModelEnum.Percentage || + chargeModel === ChargeModelEnum.Custom + ) { + return true + } + + if ( + isPayInAdvance && + (chargeModel === ChargeModelEnum.Graduated || chargeModel === ChargeModelEnum.Volume) + ) { + return true + } + } + + // Enabled by default + return false + } + + return { + getChargeModelComboboxData, + getIsPayInAdvanceOptionDisabled, + getIsProRatedOptionDisabled, + } +} + +const InlineComboboxLabelForPremiumWrapper = styled.div` + display: flex; + align-items: center; + justify-content: space-between; +` + +const InlineComboboxLabel = styled.div` + display: flex; + align-items: center; + gap: ${theme.spacing(2)}; +`