-
Notifications
You must be signed in to change notification settings - Fork 1
MPDX-9904 - Include 403b values and special needs left in NS Goal admin preview #1989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f9b3b86
Return previewed 403(b) and special-needs figures from the preview
zweatshirt cc3566a
Expose previewed worksheet figures through the preview context
zweatshirt 5665bb6
Show previewed 403(b) and Left to Raise amounts in the form
zweatshirt 07534ca
Reject a 100% 403(b) election to match server validation
zweatshirt 1d0e330
Test the preview context and add a preview mock to the wrapper
zweatshirt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
172 changes: 172 additions & 0 deletions
172
src/components/HrTools/NsGoalCalculator/GoalSettings/GoalSettingsPreviewContext.test.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,172 @@ | ||
| import React from 'react'; | ||
| import { render } from '@testing-library/react'; | ||
| import userEvent from '@testing-library/user-event'; | ||
| import { Formik } from 'formik'; | ||
| import { DeepPartial } from 'ts-essentials'; | ||
| import { | ||
| NsGoalCalculatorTestWrapper, | ||
| defaultGoalCalculation, | ||
| } from '../NsGoalCalculatorTestWrapper'; | ||
| import { GoalSettingsPreviewProvider } from './GoalSettingsPreviewContext'; | ||
| import { PreviewNewStaffGoalCalculationMutation } from './NewStaffGoalCalculation.generated'; | ||
| import { FinancialInformationSection } from './Sections/FinancialInformationSection'; | ||
| import { NsoInformationSection } from './Sections/NsoInformationSection'; | ||
| import { calculationToFormValues } from './goalSettingsApiMapping'; | ||
| import { GoalSettingsSectionProps } from './goalSettingsSectionProps'; | ||
|
|
||
| const accountListId = 'account-list-1'; | ||
| const mutationSpy = jest.fn(); | ||
|
|
||
| const savedCalculation = { | ||
| ...defaultGoalCalculation, | ||
| calculations: { | ||
| ...defaultGoalCalculation.calculations, | ||
| contributing403bAmount: 150, | ||
| spouseContributing403bAmount: 200, | ||
| specialNeedsLeft: 900, | ||
| }, | ||
| }; | ||
|
|
||
| const sectionProps: GoalSettingsSectionProps = { | ||
| hasSpouse: true, | ||
| seniorStaff: false, | ||
| calculations: { | ||
| ...savedCalculation.calculations, | ||
| contributing403bAmount: 1, | ||
| spouseContributing403bAmount: 2, | ||
| specialNeedsLeft: 3, | ||
| }, | ||
| primaryName: 'John', | ||
| spouseName: 'Jane', | ||
| visibleHeaders: ['John (Joining)', 'Jane (Joining)'], | ||
| sharedHeader: 'John (Joining) & Jane (Joining)', | ||
| }; | ||
|
|
||
| const previewOf = (calculations: { | ||
| contributing403bAmount?: number; | ||
| spouseContributing403bAmount?: number; | ||
| specialNeedsLeft?: number; | ||
| }): DeepPartial<PreviewNewStaffGoalCalculationMutation> => ({ | ||
| previewNewStaffGoalCalculation: { | ||
| newStaffGoalCalculation: { | ||
| id: savedCalculation.id, | ||
| calculations, | ||
| }, | ||
| }, | ||
| }); | ||
|
|
||
| const preview403b = previewOf({ | ||
| contributing403bAmount: 175, | ||
| spouseContributing403bAmount: 210, | ||
| }); | ||
|
|
||
| const TestComponent: React.FC<{ | ||
| previewMock?: DeepPartial<PreviewNewStaffGoalCalculationMutation>; | ||
| }> = ({ previewMock }) => ( | ||
| <NsGoalCalculatorTestWrapper previewMock={previewMock} onCall={mutationSpy}> | ||
| <Formik | ||
| initialValues={calculationToFormValues(savedCalculation)} | ||
| onSubmit={jest.fn()} | ||
| > | ||
| <GoalSettingsPreviewProvider | ||
| accountListId={accountListId} | ||
| calculation={savedCalculation} | ||
| > | ||
| <FinancialInformationSection {...sectionProps} /> | ||
| <NsoInformationSection {...sectionProps} /> | ||
| </GoalSettingsPreviewProvider> | ||
| </Formik> | ||
| </NsGoalCalculatorTestWrapper> | ||
| ); | ||
|
|
||
| describe('GoalSettingsPreviewContext', () => { | ||
| it('shows the saved worksheet figures while the form is untouched', async () => { | ||
| const { findByText, getByText } = render(<TestComponent />); | ||
|
|
||
| const johnAmount = (await findByText('403(b) Amount — John')).parentElement; | ||
| expect(johnAmount).toHaveTextContent('$150.00'); | ||
| expect(johnAmount).toHaveAttribute('aria-busy', 'false'); | ||
| expect(getByText('403(b) Amount — Jane').parentElement).toHaveTextContent( | ||
| '$200.00', | ||
| ); | ||
| expect(getByText('$900.00')).toBeInTheDocument(); | ||
|
|
||
| expect(mutationSpy).not.toHaveGraphqlOperation( | ||
| 'PreviewNewStaffGoalCalculation', | ||
| ); | ||
| }); | ||
|
|
||
| it('substitutes the previewed 403(b) amounts after an unsaved edit', async () => { | ||
| const { findByText, getByText, getByRole } = render( | ||
| <TestComponent previewMock={preview403b} />, | ||
| ); | ||
|
|
||
| const percentage = getByRole('spinbutton', { | ||
| name: '403(b) Contribution — John', | ||
| }); | ||
| userEvent.clear(percentage); | ||
| userEvent.type(percentage, '10'); | ||
| expect(await findByText('$175.00')).toBeInTheDocument(); | ||
| expect(getByText('403(b) Amount — John').parentElement).toHaveTextContent( | ||
| '$175.00', | ||
| ); | ||
| expect(getByText('403(b) Amount — Jane').parentElement).toHaveTextContent( | ||
| '$210.00', | ||
| ); | ||
| expect(mutationSpy).toHaveGraphqlOperation( | ||
| 'PreviewNewStaffGoalCalculation', | ||
| { | ||
| input: { | ||
| accountListId, | ||
| id: savedCalculation.id, | ||
| attributes: { contribution403bPercentage: 10 }, | ||
| }, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('substitutes the previewed special-needs remainder after an unsaved edit', async () => { | ||
| const { findByText, getByRole } = render( | ||
| <TestComponent previewMock={previewOf({ specialNeedsLeft: 450 })} />, | ||
| ); | ||
|
|
||
| const supportRaised = getByRole('spinbutton', { | ||
| name: 'Support Raised for NSO', | ||
| }); | ||
| userEvent.clear(supportRaised); | ||
| userEvent.type(supportRaised, '50'); | ||
|
|
||
| expect(await findByText('$450.00')).toBeInTheDocument(); | ||
| expect(mutationSpy).toHaveGraphqlOperation( | ||
| 'PreviewNewStaffGoalCalculation', | ||
| { | ||
| input: { | ||
| accountListId, | ||
| id: savedCalculation.id, | ||
| attributes: { nsoSpecialNeedsSupportReceived: 50 }, | ||
| }, | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| it('holds the previewed amount while a further edit is still in flight', async () => { | ||
| const { findByText, getByText, queryByText, getByRole } = render( | ||
| <TestComponent previewMock={preview403b} />, | ||
| ); | ||
|
|
||
| const percentage = getByRole('spinbutton', { | ||
| name: '403(b) Contribution — John', | ||
| }); | ||
| userEvent.clear(percentage); | ||
| userEvent.type(percentage, '10'); | ||
| expect(await findByText('$175.00')).toBeInTheDocument(); | ||
|
|
||
| userEvent.clear(percentage); | ||
| userEvent.type(percentage, '12'); | ||
|
|
||
| const johnAmount = getByText('403(b) Amount — John').parentElement; | ||
| expect(johnAmount).toHaveTextContent('$175.00'); | ||
| expect(johnAmount).toHaveAttribute('aria-busy', 'true'); | ||
| expect(queryByText('$150.00')).not.toBeInTheDocument(); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.