Skip to content

Commit 337699b

Browse files
committed
Enhance salary calculation tests and components with effective salary request handling
1 parent 01f7baf commit 337699b

3 files changed

Lines changed: 108 additions & 12 deletions

File tree

src/components/HrTools/SalaryCalculator/SalaryCalculation/RequestedSalaryCard/RequestedSalaryCard.test.tsx

Lines changed: 79 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ import {
88
} from 'src/graphql/types.generated';
99
import { SalaryCalculationQuery } from '../../SalaryCalculatorContext/SalaryCalculation.generated';
1010
import {
11+
EffectiveSalaryRequestMock,
1112
SalaryCalculatorTestWrapper,
1213
SalaryCalculatorTestWrapperProps,
14+
hcmSpouseMock,
15+
hcmUserMock,
1316
} from '../../SalaryCalculatorTestWrapper';
1417
import { RequestedSalaryCard } from './RequestedSalaryCard';
1518

@@ -27,9 +30,19 @@ const defaultSalaryMock: DeepPartial<SalaryCalculationQuery['salaryRequest']> =
2730
},
2831
};
2932

30-
const TestComponent: React.FC<SalaryCalculatorTestWrapperProps> = (props) => (
33+
const approvedSalaryMock: EffectiveSalaryRequestMock = {
34+
personNumber: hcmUserMock.staffInfo.personNumber,
35+
salary: 11111,
36+
spouseSalary: 22222,
37+
};
38+
39+
const TestComponent: React.FC<SalaryCalculatorTestWrapperProps> = ({
40+
effectiveSalaryRequestMock = approvedSalaryMock,
41+
...props
42+
}) => (
3143
<SalaryCalculatorTestWrapper
3244
salaryRequestMock={defaultSalaryMock}
45+
effectiveSalaryRequestMock={effectiveSalaryRequestMock}
3346
hcmUser={{
3447
currentSalary: { grossSalaryAmount: 10001 },
3548
}}
@@ -74,7 +87,7 @@ As you set your salary level, the amount you receive should reflect the amount o
7487
expect(
7588
getAllByRole('rowheader').map((cell) => cell.textContent),
7689
).toEqual([
77-
'Current Salary',
90+
'Current Requested Salary',
7891
'Minimum Salary',
7992
'Maximum Allowable Salary (CAP)',
8093
'Requested Salary',
@@ -86,7 +99,27 @@ As you set your salary level, the amount you receive should reflect the amount o
8699
const { getAllByRole } = render(<TestComponent />);
87100

88101
const expectedCells = [
89-
['$10,001.00', '$20,001.00'],
102+
['$11,111.00', '$22,222.00'],
103+
['$10,003.00', '$20,003.00'],
104+
['$10,004.00', '$20,004.00'],
105+
].flat();
106+
107+
await waitFor(() =>
108+
expect(
109+
getAllByRole('cell')
110+
.slice(0, -2)
111+
.map((cell) => cell.textContent),
112+
).toEqual(expectedCells),
113+
);
114+
});
115+
116+
it('should render a dash when there is no approved salary request', async () => {
117+
const { getAllByRole } = render(
118+
<TestComponent effectiveSalaryRequestMock={null} />,
119+
);
120+
121+
const expectedCells = [
122+
['–', '–'],
90123
['$10,003.00', '$20,003.00'],
91124
['$10,004.00', '$20,004.00'],
92125
].flat();
@@ -101,6 +134,31 @@ As you set your salary level, the amount you receive should reflect the amount o
101134
);
102135
});
103136

137+
it('swaps the requested salary when the spouse created the request', async () => {
138+
const { getAllByRole } = render(
139+
<TestComponent
140+
effectiveSalaryRequestMock={{
141+
...approvedSalaryMock,
142+
personNumber: hcmSpouseMock.staffInfo.personNumber,
143+
}}
144+
/>,
145+
);
146+
147+
await waitFor(() =>
148+
expect(
149+
getAllByRole('cell')
150+
.slice(0, -2)
151+
.map((cell) => cell.textContent),
152+
).toEqual(
153+
[
154+
['$22,222.00', '$11,111.00'],
155+
['$10,003.00', '$20,003.00'],
156+
['$10,004.00', '$20,004.00'],
157+
].flat(),
158+
),
159+
);
160+
});
161+
104162
it('should render the effective paycheck note when payroll dates match', async () => {
105163
const { findByRole } = render(
106164
<TestComponent
@@ -148,7 +206,7 @@ As you set your salary level, the amount you receive should reflect the amount o
148206
expect(
149207
getAllByRole('rowheader').map((cell) => cell.textContent),
150208
).toEqual([
151-
'Current Salary',
209+
'Current Requested Salary',
152210
'Minimum Salary',
153211
'Maximum Allowable Salary (CAP)',
154212
'Requested Salary',
@@ -159,7 +217,23 @@ As you set your salary level, the amount you receive should reflect the amount o
159217
it('should render table cells with formatted currency', async () => {
160218
const { getAllByRole } = render(<TestComponent hasSpouse={false} />);
161219

162-
const expectedCells = ['$10,001.00', '$10,003.00', '$10,004.00'];
220+
const expectedCells = ['$11,111.00', '$10,003.00', '$10,004.00'];
221+
222+
await waitFor(() =>
223+
expect(
224+
getAllByRole('cell')
225+
.slice(0, -1)
226+
.map((cell) => cell.textContent),
227+
).toEqual(expectedCells),
228+
);
229+
});
230+
231+
it('should render a dash when there is no approved salary request', async () => {
232+
const { getAllByRole } = render(
233+
<TestComponent hasSpouse={false} effectiveSalaryRequestMock={null} />,
234+
);
235+
236+
const expectedCells = ['–', '$10,003.00', '$10,004.00'];
163237

164238
await waitFor(() =>
165239
expect(

src/components/HrTools/SalaryCalculator/SalaryCalculation/RequestedSalaryCard/RequestedSalaryCard.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,14 @@ import * as yup from 'yup';
1515
import { useAutosaveForm } from 'src/components/Shared/Autosave/AutosaveForm';
1616
import { amount } from 'src/lib/yupHelpers';
1717
import { AutosaveTextField } from '../../Autosave/AutosaveTextField';
18-
import { CalculationFieldsFragment } from '../../SalaryCalculatorContext/SalaryCalculation.generated';
18+
import {
19+
CalculationFieldsFragment,
20+
useEffectiveSalaryCalculationQuery,
21+
} from '../../SalaryCalculatorContext/SalaryCalculation.generated';
1922
import { useSalaryCalculator } from '../../SalaryCalculatorContext/SalaryCalculatorContext';
2023
import { EffectiveDateNote } from '../../Shared/EffectiveDateNote';
2124
import { StepCard, StepTableHead } from '../../Shared/StepCard';
25+
import { orientSalaryRequest } from '../../Shared/orientSalaryRequest';
2226
import { useFormatters } from '../../Shared/useFormatters';
2327
import { useCaps } from '../useCaps';
2428
import { useSosaBlockOverCap } from '../useSosaBlockOverCap';
@@ -35,6 +39,13 @@ export const RequestedSalaryCard: React.FC = () => {
3539
const { isUserSosa, blockOnCap } = useSosaBlockOverCap();
3640
const { markValid, markInvalid } = useAutosaveForm();
3741

42+
const { data: effectiveData } = useEffectiveSalaryCalculationQuery();
43+
const { salary, spouseSalary } =
44+
orientSalaryRequest(
45+
effectiveData?.salaryRequest,
46+
hcmUser?.staffInfo.personNumber,
47+
) ?? {};
48+
3849
// Disable the Continue button while the saved gross exceeds the SOSA cap.
3950
useEffect(() => {
4051
if (blockOnCap) {
@@ -128,14 +139,12 @@ export const RequestedSalaryCard: React.FC = () => {
128139
<TableBody>
129140
<TableRow>
130141
<TableCell component="th" scope="row">
131-
{t('Current Salary')}
132-
</TableCell>
133-
<TableCell>
134-
{formatCurrency(hcmUser?.currentSalary.grossSalaryAmount)}
142+
{t('Current Requested Salary')}
135143
</TableCell>
144+
<TableCell>{salary ? formatCurrency(salary) : '–'}</TableCell>
136145
{hcmSpouse && (
137146
<TableCell>
138-
{formatCurrency(hcmSpouse.currentSalary.grossSalaryAmount)}
147+
{spouseSalary ? formatCurrency(spouseSalary) : '–'}
139148
</TableCell>
140149
)}
141150
</TableRow>

src/components/HrTools/SalaryCalculator/SalaryCalculatorTestWrapper.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ import {
1818
HcmQueryVariables,
1919
} from '../Shared/HcmData/Hcm.generated';
2020
import { PayrollDatesQuery } from './EffectiveDateStep/PayrollDates.generated';
21-
import { SalaryCalculationQuery } from './SalaryCalculatorContext/SalaryCalculation.generated';
21+
import {
22+
EffectiveSalaryCalculationQuery,
23+
SalaryCalculationQuery,
24+
} from './SalaryCalculatorContext/SalaryCalculation.generated';
2225
import { SalaryCalculatorProvider } from './SalaryCalculatorContext/SalaryCalculatorContext';
2326

2427
const hcmMock = gqlMock<HcmQuery, HcmQueryVariables>(HcmDocument, {
@@ -91,8 +94,13 @@ export type SalaryRequestMock = DeepPartial<
9194
SalaryCalculationQuery['salaryRequest']
9295
>;
9396

97+
export type EffectiveSalaryRequestMock = DeepPartial<
98+
EffectiveSalaryCalculationQuery['salaryRequest']
99+
>;
100+
94101
export interface SalaryCalculatorTestWrapperProps {
95102
salaryRequestMock?: SalaryRequestMock;
103+
effectiveSalaryRequestMock?: EffectiveSalaryRequestMock;
96104
hcmUser?: DeepPartial<HcmQuery['hcm'][number]>;
97105
hcmSpouse?: DeepPartial<HcmQuery['hcm'][number]>;
98106
onCall?: MockLinkCallHandler;
@@ -107,6 +115,7 @@ export const SalaryCalculatorTestWrapper: React.FC<
107115
SalaryCalculatorTestWrapperProps
108116
> = ({
109117
salaryRequestMock,
118+
effectiveSalaryRequestMock = null,
110119
hcmUser,
111120
hcmSpouse,
112121
onCall,
@@ -133,6 +142,7 @@ export const SalaryCalculatorTestWrapper: React.FC<
133142
Hcm: HcmQuery;
134143
PayrollDates: PayrollDatesQuery;
135144
SalaryCalculation: SalaryCalculationQuery;
145+
EffectiveSalaryCalculation: EffectiveSalaryCalculationQuery;
136146
GoalCalculatorConstants: GoalCalculatorConstantsQuery;
137147
StaffAccount: StaffAccountQuery;
138148
GetUser: GetUserQuery;
@@ -152,6 +162,9 @@ export const SalaryCalculatorTestWrapper: React.FC<
152162
PayrollDates: {
153163
payrollDates,
154164
},
165+
EffectiveSalaryCalculation: {
166+
salaryRequest: effectiveSalaryRequestMock,
167+
},
155168
GoalCalculatorConstants: {
156169
constant: {
157170
mpdGoalGeographicConstants: [

0 commit comments

Comments
 (0)