Skip to content

MPDX-9544 Frontend - Add validation to ensure the Requested Gross Salary for SOSA staff doesn't exceed their cap#1770

Merged
zweatshirt merged 4 commits into
mainfrom
MPDX-9544-frontend
May 12, 2026
Merged

MPDX-9544 Frontend - Add validation to ensure the Requested Gross Salary for SOSA staff doesn't exceed their cap#1770
zweatshirt merged 4 commits into
mainfrom
MPDX-9544-frontend

Conversation

@zweatshirt
Copy link
Copy Markdown
Contributor

@zweatshirt zweatshirt commented May 11, 2026

Description

  • We don't want SOSA staff to be able to continue their form if their gross requested salary exceeds their cap.
  • This needs to be done against their gross requested salary, and not their base requested salary.
    • Because of this, I chose not to do Formik field validation on the user input for their requested salary, as this can easily cause drift between the frontend and backend values and lock the user into an error state.
    • The alternative solution if we want to allow input field validation is doing the calculations in the frontend for validation instead of depending on API state.

Testing

  • Use one of the test data emails that is SOSA and ensure that they cannot continue past step 3 if their gross requested salary exceeds their cap.
  • Determine if the Alert is sufficient in notifying the user.

Checklist:

  • I have given my PR a title with the format "MPDX-(JIRA#) (summary sentence max 80 chars)"
  • I have applied the appropriate labels (Add the label "Preview" to automatically create a preview environment)
  • I have run the Claude Code /pr-review command locally and fixed any relevant suggestions
  • I have requested a review from another person on the project
  • I have tested my changes in preview or in staging
  • I have cleaned up my commit history

@zweatshirt zweatshirt self-assigned this May 11, 2026
@zweatshirt zweatshirt added the Preview Environment Add this label to create an Amplify Preview label May 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Preview branch generated at https://MPDX-9544-frontend.d3dytjb8adxkk5.amplifyapp.com

@github-actions
Copy link
Copy Markdown
Contributor

Bundle sizes [mpdx-react]

Compared against d15e969

No significant changes found

Copy link
Copy Markdown
Contributor Author

@zweatshirt zweatshirt left a comment

Choose a reason for hiding this comment

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

Multi-Agent Code Review — PR #1770 (v2)

Verdict: APPROVED WITH SUGGESTIONS — No blockers. The v2 refactor cleanly addressed the previous round's two medium findings (Alert variant deviation + OverCapPerson field-name mismatch). Remaining items are non-blocking test-coverage gaps and minor stylistic polish.

Risk: 6/10 (MEDIUM) — 5 source files, 74 non-test lines, single-domain scope.

Agents: Architecture, Testing, Standards, UX, Financial Reporting.

Summary

Tier Count
Critical (9.0+) 0
High Priority (8.0–8.9) 0
Important (7.0–7.9) 0
Medium (5.0–6.9) 2
Suggestions (<5.0) 7
Pre-existing 1

Top medium-priority items

  1. Continue-button gating contract untesteduseSosaBlockOnCap's markInvalid('over-cap') side effect (the entire reason the hook exists) is not asserted by any test. Carried over from round 1.
  2. SOSA + spouse branch combinations untested — All new tests use hasSpouse={false}. The invariant blockOnCap = isUserSosa && overUserCap (not && overCapPerson !== null) is the most refactor-fragile line in the diff and has no regression net.

Both are non-blocking (severity 5) but would be quick wins.

What's confirmed good

  • All 5 useCaps consumers verified aligned with the new raw-number interface (Receipt, useSubmitDialogContent use only combinedGross; the 3 over-cap consumers correctly wrap fields in formatCurrency() at the display boundary).
  • Financial checklist: pass on every item (single source of truth = server, formatting at display boundary, USD-only, server-provided aggregations preferred, safe handling of undefined via formatCurrency's ?? 0).
  • <Trans> {{ var: expr }} pattern matches 5+ precedents in the codebase.
  • All four affected test files were observed to pass after the refactor.

}

export const useCaps = (): UseCapsResult => {
const { calculation, hcmUser, hcmSpouse } = useSalaryCalculator();
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Suggestion] **`useCaps` still has no dedicated unit test.** Now that the hook exports a public `OverCapPerson` interface and is consumed by 5 callers, a direct `useCaps.test.ts` would pin down: `combinedGross` math, `overUserCap` truth table, `overCapPerson` precedence (user wins over spouse when both over cap), and the null short-circuit when neither is over cap. Indirect coverage exists through three consumer tests, but the precedence rule isn't directly exercised.

Estimated ~40 lines via renderHook.

Flagged by Testing.

/>,
);

await waitFor(() => expect(queryByRole('alert')).not.toBeInTheDocument());
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

[Suggestion] **Negative-Alert tests assert absence without anchoring to a positive render first.** The `waitFor(() => expect(queryByRole('alert')).not.toBeInTheDocument())` will pass on the first tick before the salary-calculation query resolves. A regression that delays the Alert past the initial render would slip through. Awaiting some other rendered element (e.g., a rowheader cell) before the absence assertion would catch that.

Flagged by Standards.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

AI Review Auto-Approval

Risk Level: MEDIUM (6/10)
Verdict: APPROVED_WITH_SUGGESTIONS (suggestions posted, no blockers)

This PR was auto-approved because:

  • The multi-agent AI review determined it is medium risk
  • No blocking issues were found
  • All suggestions have been posted as review comments for the developer to consider

If you believe this PR needs human review, dismiss this approval and request a review manually.

@zweatshirt zweatshirt marked this pull request as ready for review May 11, 2026 17:26
@zweatshirt zweatshirt force-pushed the MPDX-9544-frontend branch from 4a52603 to e2e01d3 Compare May 11, 2026 17:41
@zweatshirt
Copy link
Copy Markdown
Contributor Author

@canac Waiting for Grace or CD to respond with the proper alert message. I am curious what you think about this in terms of UI design. I didn't choose to go with input field validation (see PR description). Thank you Caleb

Copy link
Copy Markdown
Contributor

@canac canac left a comment

Choose a reason for hiding this comment

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

I have a few suggestions, but the core logic looks good! Do you think we should hide the "Approval Process" card when the error message displays since they can't submit anyway?

Comment thread src/components/HrTools/SalaryCalculator/SalaryCalculation/useCaps.ts Outdated
Comment thread src/components/HrTools/SalaryCalculator/SalaryCalculation/useCaps.ts Outdated
@zweatshirt zweatshirt force-pushed the MPDX-9544-frontend branch from 0800dbe to 27990be Compare May 12, 2026 18:00
@zweatshirt zweatshirt enabled auto-merge May 12, 2026 18:04
@zweatshirt zweatshirt disabled auto-merge May 12, 2026 18:05
@zweatshirt zweatshirt force-pushed the MPDX-9544-frontend branch from 27990be to 98170b4 Compare May 12, 2026 18:51
@zweatshirt zweatshirt enabled auto-merge May 12, 2026 18:55
@zweatshirt zweatshirt merged commit ab6e457 into main May 12, 2026
23 of 24 checks passed
@zweatshirt zweatshirt deleted the MPDX-9544-frontend branch May 12, 2026 18:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Preview Environment Add this label to create an Amplify Preview

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants