Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,11 @@ const t = ((key: string) => key) as unknown as Parameters<
>[1];

describe('getCapOverrides', () => {
it('returns undefined title/content when not exceeding cap', () => {
it('returns undefined title/content when no approval needed', () => {
const result = getCapOverrides(
{
splitAsr: false,
additionalApproval: false,
exceedsCap: false,
hasBoardCapException: false,
},
t,
Expand All @@ -24,20 +23,18 @@ describe('getCapOverrides', () => {
{
splitAsr: true,
additionalApproval: false,
exceedsCap: false,
hasBoardCapException: false,
},
t,
);
expect(result.title).toMatch(/exceeds your remaining allowable salary/);
});

it('returns Progressive Approvals messaging when exceeds cap without board exception', () => {
it('returns Progressive Approvals messaging when additionalApproval without board exception', () => {
const result = getCapOverrides(
{
splitAsr: false,
additionalApproval: false,
exceedsCap: true,
additionalApproval: true,
hasBoardCapException: false,
},
t,
Expand All @@ -46,12 +43,11 @@ describe('getCapOverrides', () => {
expect(result.content).toMatch(/exceed your Maximum Allowable Salary/);
});

it('returns board-approval messaging when exceeds cap with board exception', () => {
it('returns board-approval messaging when approval required with board exception', () => {
const result = getCapOverrides(
{
splitAsr: false,
additionalApproval: false,
exceedsCap: true,
additionalApproval: true,
hasBoardCapException: true,
},
t,
Expand All @@ -63,27 +59,11 @@ describe('getCapOverrides', () => {
expect(result.content).toMatch(/Additional Salary Request exceeds/);
});

it('board exception takes precedence over additionalApproval branch', () => {
const result = getCapOverrides(
{
splitAsr: false,
additionalApproval: true,
exceedsCap: false,
hasBoardCapException: true,
},
t,
);
expect(result.content).toMatch(
/You have a Board approved Maximum Allowable Salary/,
);
});

it('board exception does not apply when user is not exceeding cap', () => {
it('board exception does not apply when no approval required', () => {
const result = getCapOverrides(
{
splitAsr: false,
additionalApproval: false,
exceedsCap: false,
hasBoardCapException: true,
},
t,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,11 @@ import { TFunction } from 'i18next';
interface CapOverridesOptions {
splitAsr: boolean;
additionalApproval: boolean;
exceedsCap: boolean;
hasBoardCapException: boolean;
}

export const getCapOverrides = (
{
splitAsr,
additionalApproval,
exceedsCap,
hasBoardCapException,
}: CapOverridesOptions,
{ splitAsr, additionalApproval, hasBoardCapException }: CapOverridesOptions,
t: TFunction,
) => {
if (splitAsr) {
Expand All @@ -25,7 +19,7 @@ export const getCapOverrides = (
};
}

if (additionalApproval || exceedsCap) {
if (additionalApproval) {
if (hasBoardCapException) {
return {
title: t(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ describe('RequestPage', () => {
calculations: {
currentSalaryCap: 50,
},
progressiveApprovalTier: { id: 'tier-1' },
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down Expand Up @@ -524,6 +525,7 @@ describe('RequestPage', () => {
currentSalaryCap: 500,
pendingAsrAmount: 600,
},
progressiveApprovalTier: { id: 'tier-1' },
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down Expand Up @@ -727,7 +729,7 @@ describe('RequestPage', () => {
staffAccountBalance: 999999,
pendingAsrAmount: 0,
},
progressiveApprovalTier: null,
progressiveApprovalTier: { id: 'tier-1' },
},
},
};
Expand Down Expand Up @@ -789,6 +791,7 @@ describe('RequestPage', () => {
.calculations,
currentSalaryCap: 100000,
},
progressiveApprovalTier: null,
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,7 @@ const MainContent: React.FC = () => {
const { title: overrideTitle, content: overrideContent } = getCapOverrides(
{
splitAsr: !!splitAsr,
additionalApproval: !!additionalApproval,
exceedsCap,
additionalApproval,
hasBoardCapException,
},
t,
Expand Down Expand Up @@ -143,7 +142,7 @@ const MainContent: React.FC = () => {
spouseName={spouse?.staffInfo.preferredName ?? ''}
/>
)
) : additionalApproval || exceedsCap ? (
) : additionalApproval ? (
<CapSubContent />
) : isEdit ? (
t('Your updated request will be sent to payroll.')
Expand All @@ -164,7 +163,7 @@ const MainContent: React.FC = () => {
isValid={isValid}
actionRequired={isEdit}
isEdit={isEdit}
additionalApproval={additionalApproval || exceedsCap}
additionalApproval={additionalApproval}
splitAsr={splitAsr}
disableSubmit={
(splitAsr && !!errors.additionalInfo) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,10 +394,13 @@ describe('useSalaryCalculations', () => {
});

describe('Married - Staff Member over cap', () => {
const setupOverCap = (spouseCalculations: {
currentSalaryCap: number;
pendingAsrAmount: number;
}) => {
const setupOverCap = (
spouseCalculations: {
currentSalaryCap: number;
pendingAsrAmount: number;
},
progressiveApprovalTier: unknown = null,
) => {
mockUseAdditionalSalaryRequest.mockReturnValue({
traditional403bPercentage: 0.12,
roth403bPercentage: 0.1,
Expand All @@ -409,6 +412,7 @@ describe('useSalaryCalculations', () => {
currentSalaryCap: 60000,
},
spouseCalculations,
progressiveApprovalTier,
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down Expand Up @@ -455,7 +459,10 @@ describe('useSalaryCalculations', () => {
});

it('Staff Member over cap, spouse is over their cap — additionalApproval', () => {
setupOverCap({ currentSalaryCap: 50000, pendingAsrAmount: 15000 });
setupOverCap(
{ currentSalaryCap: 50000, pendingAsrAmount: 15000 },
{ id: 'tier-1' },
);

const values: CompleteFormValues = {
...baseValues,
Expand All @@ -475,7 +482,10 @@ describe('useSalaryCalculations', () => {
});

it('Staff Member over cap, spouse is at their cap — additionalApproval', () => {
setupOverCap({ currentSalaryCap: 40003, pendingAsrAmount: 0 });
setupOverCap(
{ currentSalaryCap: 40003, pendingAsrAmount: 0 },
{ id: 'tier-1' },
);

const values: CompleteFormValues = {
...baseValues,
Expand All @@ -496,7 +506,7 @@ describe('useSalaryCalculations', () => {

it('Staff Member over cap, spouse exactly $5 below cap — treated as at cap', () => {
const currentSalaryCap = 40000 + AT_CAP_TOLERANCE;
setupOverCap({ currentSalaryCap, pendingAsrAmount: 0 });
setupOverCap({ currentSalaryCap, pendingAsrAmount: 0 }, { id: 'tier-1' });

const values: CompleteFormValues = {
...baseValues,
Expand Down Expand Up @@ -539,10 +549,13 @@ describe('useSalaryCalculations', () => {

describe('Married - Staff Member at cap', () => {
// Cases 9-12: Staff Member at cap (not over) — nothing triggers
const setupAtCap = (spouseCalculations: {
currentSalaryCap: number;
pendingAsrAmount: number;
}) => {
const setupAtCap = (
spouseCalculations: {
currentSalaryCap: number;
pendingAsrAmount: number;
},
progressiveApprovalTier: unknown = null,
) => {
mockUseAdditionalSalaryRequest.mockReturnValue({
traditional403bPercentage: 0.12,
roth403bPercentage: 0.1,
Expand All @@ -554,6 +567,7 @@ describe('useSalaryCalculations', () => {
currentSalaryCap: 55000,
},
spouseCalculations,
progressiveApprovalTier,
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down Expand Up @@ -598,7 +612,10 @@ describe('useSalaryCalculations', () => {
});

it('Staff Member at cap, spouse is over their cap', () => {
setupAtCap({ currentSalaryCap: 50000, pendingAsrAmount: 15000 });
setupAtCap(
{ currentSalaryCap: 50000, pendingAsrAmount: 15000 },
{ id: 'tier-1' },
);

const values: CompleteFormValues = {
...baseValues,
Expand Down Expand Up @@ -638,7 +655,10 @@ describe('useSalaryCalculations', () => {
});

describe('Single staff member', () => {
const setupSingle = (cap: number) => {
const setupSingle = (
cap: number,
progressiveApprovalTier: unknown = null,
) => {
mockUseAdditionalSalaryRequest.mockReturnValue({
traditional403bPercentage: 0.12,
roth403bPercentage: 0.1,
Expand All @@ -647,6 +667,7 @@ describe('useSalaryCalculations', () => {
requestData: {
latestAdditionalSalaryRequest: {
calculations: { currentSalaryCap: cap },
progressiveApprovalTier,
},
},
} as unknown as ReturnType<typeof useAdditionalSalaryRequest>);
Expand Down Expand Up @@ -691,7 +712,7 @@ describe('useSalaryCalculations', () => {
});

it('Staff Member over cap — additionalApproval', () => {
setupSingle(60000);
setupSingle(60000, { id: 'tier-1' });

const values: CompleteFormValues = {
...baseValues,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,7 @@
? 'spouse'
: null;
const additionalApproval =
(exceedsCap && (!isMarried || spouseAtCap || spouseExceedsCap)) ||
(userAtCap && isMarried && spouseExceedsCap);
!!requestData?.latestAdditionalSalaryRequest?.progressiveApprovalTier;

Check notice on line 147 in src/components/HrTools/AdditionalSalaryRequest/Shared/useSalaryCalculations.ts

View check run for this annotation

CodeScene Delta Analysis / CodeScene Code Health Review (main)

✅ Getting better: Complex Method

useSalaryCalculations decreases in cyclomatic complexity from 41 to 37, threshold = 15. This function has many conditional statements (e.g. if, for, while), leading to lower code health. Avoid adding more conditionals and code to it without refactoring.

const hasSpouseCap = isMarried && spouseIndividualCap !== null;
const spouseCap = hasSpouseCap
Expand Down
Loading