Skip to content

Commit 9054794

Browse files
Merge 334b078 into staging
2 parents 05561f9 + 334b078 commit 9054794

11 files changed

Lines changed: 120 additions & 49 deletions

File tree

src/components/HrTools/SavingsFundTransfer/DownloadTable/downloadTable.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const mockHeaders = [
1818
'Schedule',
1919
'Status',
2020
'Transfer Date',
21-
'Stop Date',
21+
'End Date',
2222
'Note',
2323
];
2424

src/components/HrTools/SavingsFundTransfer/DownloadTable/downloadTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ export const downloadCSV = (
7373
t('Schedule'),
7474
t('Status'),
7575
t('Transfer Date'),
76-
t('Stop Date'),
76+
t('End Date'),
7777
t('Note'),
7878
];
7979

src/components/HrTools/SavingsFundTransfer/IntroPage/IntroPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,14 +99,14 @@ export const SavingsFundTransfer: React.FC<SavingsFundTransferProps> = ({
9999
<StyledListItem>
100100
<ListItemText
101101
primary={t(
102-
'Want your monthly transfer to end at a certain point? You can set a stop date—super handy! Just a heads-up: once it’s there, it can’t be removed, but you can change it to a different date if needed.',
102+
'Want your monthly transfer to end at a certain point? You can set an end date—super handy! Just a heads-up: once it’s there, it can’t be removed, but you can change it to a different date if needed.',
103103
)}
104104
/>
105105
</StyledListItem>
106106
<StyledListItem>
107107
<ListItemText
108108
primary={t(
109-
"Need to update the amount you're transferring each month? No problem! Just set a stop date for the end of the current month on your existing transfer. After that, go ahead and set up a brand-new monthly transfer with the updated amount.",
109+
"Need to update the amount you're transferring each month? No problem! Just set an end date for the end of the current month on your existing transfer. After that, go ahead and set up a brand-new monthly transfer with the updated amount.",
110110
)}
111111
/>
112112
</StyledListItem>

src/components/HrTools/SavingsFundTransfer/Table/PrintTable.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ describe('PrintTable', () => {
7272
).toBeInTheDocument();
7373
expect(getByRole('cell', { name: 'Jan 1, 2023' })).toBeInTheDocument();
7474
expect(
75-
await findByRole('columnheader', { name: 'Stop Date' }),
75+
await findByRole('columnheader', { name: 'End Date' }),
7676
).toBeInTheDocument();
7777
expect(getByRole('cell', { name: '' })).toBeInTheDocument();
7878
expect(

src/components/HrTools/SavingsFundTransfer/Table/PrintTable.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export const PrintTable: React.FC<PrintTableProps> = ({ transfers, type }) => {
4040
<TableCell>{t('Schedule')}</TableCell>
4141
<TableCell>{t('Status')}</TableCell>
4242
<TableCell>{t('Transfer Date')}</TableCell>
43-
<TableCell>{t('Stop Date')}</TableCell>
43+
<TableCell>{t('End Date')}</TableCell>
4444
<TableCell>{t('Note')}</TableCell>
4545
</TableRow>
4646
</TableHead>

src/components/HrTools/SavingsFundTransfer/Table/Row/createTableRow.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export function populateTransferRows(options: Options) {
230230
) : row.endDate ? (
231231
<>
232232
<IconButton
233-
title={t('Edit Stop Date')}
233+
title={t('Edit End Date')}
234234
onClick={(event) => {
235235
event.stopPropagation();
236236
handleCalendarOpen(row);
@@ -259,7 +259,7 @@ export function populateTransferRows(options: Options) {
259259
) : (
260260
<>
261261
<IconButton
262-
title={t('Add Stop Date')}
262+
title={t('Add End Date')}
263263
onClick={(event) => {
264264
event.stopPropagation();
265265
handleCalendarOpen(row);

src/components/HrTools/SavingsFundTransfer/Table/TransfersTable.test.tsx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ describe('TransferHistoryTable', () => {
8080
'Schedule',
8181
'Status',
8282
'Transfer Date',
83-
'Stop Date',
83+
'End Date',
8484
'Note',
8585
'Actions',
8686
]),
@@ -119,7 +119,7 @@ describe('TransferHistoryTable', () => {
119119
).toBeInTheDocument();
120120

121121
expect(
122-
within(actionCell).getByRole('button', { name: 'Add Stop Date' }),
122+
within(actionCell).getByRole('button', { name: 'Add End Date' }),
123123
).toBeInTheDocument();
124124
expect(
125125
within(actionCell).getByRole('img', { name: 'Stop Transfer' }),
@@ -178,7 +178,7 @@ describe('TransferHistoryTable', () => {
178178
});
179179

180180
describe('Calendar', () => {
181-
it('opens the calendar when Add Stop Date is clicked', async () => {
181+
it('opens the calendar when Add End Date is clicked', async () => {
182182
const { getByRole, findByRole } = render(<TestComponent />);
183183

184184
const iconRow = getByRole('row', {
@@ -187,7 +187,7 @@ describe('TransferHistoryTable', () => {
187187
const cells = within(iconRow).getAllByRole('gridcell');
188188
const actionCell = cells[7];
189189
const icon = within(actionCell).getByRole('button', {
190-
name: 'Add Stop Date',
190+
name: 'Add End Date',
191191
});
192192

193193
userEvent.click(icon);
@@ -205,7 +205,7 @@ describe('TransferHistoryTable', () => {
205205
const cells = within(iconRow).getAllByRole('gridcell');
206206
const actionCell = cells[7];
207207
const icon = within(actionCell).getByRole('button', {
208-
name: 'Add Stop Date',
208+
name: 'Add End Date',
209209
});
210210

211211
userEvent.click(icon);
@@ -231,7 +231,7 @@ describe('TransferHistoryTable', () => {
231231
const cells = within(iconRow).getAllByRole('gridcell');
232232
const actionCell = cells[7];
233233
const icon = within(actionCell).getByRole('button', {
234-
name: 'Edit Stop Date',
234+
name: 'Edit End Date',
235235
});
236236

237237
userEvent.click(icon);
@@ -245,7 +245,7 @@ describe('TransferHistoryTable', () => {
245245
userEvent.click(getByRole('button', { name: 'Yes' }));
246246

247247
await waitFor(() => expect(mutationSpy).toHaveBeenCalled());
248-
expect(mockEnqueue).toHaveBeenCalledWith('Stop date updated successfully', {
248+
expect(mockEnqueue).toHaveBeenCalledWith('End date updated successfully', {
249249
variant: 'success',
250250
});
251251

@@ -261,7 +261,7 @@ describe('TransferHistoryTable', () => {
261261
const cells = within(iconRow).getAllByRole('gridcell');
262262
const actionCell = cells[7];
263263
const icon = within(actionCell).getByRole('button', {
264-
name: 'Edit Stop Date',
264+
name: 'Edit End Date',
265265
});
266266

267267
userEvent.click(icon);
@@ -286,7 +286,7 @@ describe('TransferHistoryTable', () => {
286286
userEvent.click(acceptButton);
287287

288288
await waitFor(() => expect(mutationSpy).toHaveBeenCalled());
289-
expect(mockEnqueue).toHaveBeenCalledWith('Stop date updated successfully', {
289+
expect(mockEnqueue).toHaveBeenCalledWith('End date updated successfully', {
290290
variant: 'success',
291291
});
292292
});

src/components/HrTools/SavingsFundTransfer/Table/TransfersTable.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,12 @@ export const TransfersTable: React.FC<TransfersTableProps> = ({
142142
) => {
143143
const successMessage =
144144
actionType === ActionTypeEnum.Edit
145-
? t('Stop date updated successfully')
146-
: t('Stop date added successfully');
145+
? t('End date updated successfully')
146+
: t('End date added successfully');
147147
const errorMessage =
148148
actionType === ActionTypeEnum.Edit
149-
? t('Failed to update stop date')
150-
: t('Failed to add stop date');
149+
? t('Failed to update end date')
150+
: t('Failed to add end date');
151151
try {
152152
if (calendarRow) {
153153
const recurringEnd: string | null = date ? date.toISO() : null;
@@ -228,7 +228,7 @@ export const TransfersTable: React.FC<TransfersTableProps> = ({
228228
},
229229
{
230230
field: 'endDate',
231-
headerName: t('Stop Date'),
231+
headerName: t('End Date'),
232232
width: 145,
233233
renderCell: endDate,
234234
},

src/components/Reports/MPGAIncomeExpensesReport/CustomExport/CustomExport.test.tsx

Lines changed: 71 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import { ReportTypeEnum } from '../Helper/MPGAReportEnum';
2-
import { mockData, months } from '../mockData';
2+
import { DataFields, mockData, months } from '../mockData';
33
import { createTable, exportToCsv } from './CustomExport';
44

5+
const locale = 'en-US';
6+
57
const mockSetAttribute = jest.fn();
68
const mockClick = jest.fn();
79

@@ -51,7 +53,12 @@ describe('CustomExport', () => {
5153
jest.spyOn(link, 'setAttribute').mockImplementation(mockSetAttribute);
5254
jest.spyOn(link, 'click').mockImplementation(mockClick);
5355

54-
const data = exportToCsv(mockData.income, ReportTypeEnum.Income, months);
56+
const data = exportToCsv(
57+
mockData.income,
58+
ReportTypeEnum.Income,
59+
months,
60+
locale,
61+
);
5562

5663
expect(mockSetAttribute).toHaveBeenCalledWith(
5764
'href',
@@ -69,36 +76,79 @@ describe('CustomExport', () => {
6976
});
7077

7178
it('should contain correct data', () => {
72-
const csvData = createTable(mockHeaders, mockData.income);
79+
const csvData = createTable(mockHeaders, mockData.income, locale);
7380

7481
expect(csvData).toContain(mockHeaders);
7582
expect(csvData[1]).toEqual([
7683
'Contributions',
77-
6770,
78-
6090,
79-
5770,
80-
7355,
81-
8035,
82-
6575,
83-
7556,
84-
8239,
85-
9799,
86-
9729,
87-
13020,
88-
19215,
89-
9013,
90-
108156,
84+
'6770',
85+
'6090',
86+
'5770',
87+
'7355',
88+
'8035',
89+
'6575',
90+
'7556',
91+
'8239',
92+
'9799',
93+
'9729',
94+
'13020',
95+
'19215',
96+
'9013',
97+
'108156',
98+
]);
99+
});
100+
101+
it('should round values to two decimal places', () => {
102+
const decimalData: DataFields[] = [
103+
{
104+
id: 'rounding-test',
105+
description: 'Rounding',
106+
monthly: [10.234, 10.236, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
107+
average: 9012.567,
108+
total: 108155.555,
109+
},
110+
];
111+
112+
const csvData = createTable(mockHeaders, decimalData, locale);
113+
114+
expect(csvData[1]).toEqual([
115+
'Rounding',
116+
'10.23',
117+
'10.24',
118+
'-',
119+
'-',
120+
'-',
121+
'-',
122+
'-',
123+
'-',
124+
'-',
125+
'-',
126+
'-',
127+
'-',
128+
'9012.57',
129+
'108155.56',
91130
]);
92131
});
93132

94133
it('should display correct totals', () => {
95-
const csvData = createTable(mockHeaders, dataWithTotal);
134+
const csvData = createTable(mockHeaders, dataWithTotal, locale);
96135

97136
expect(csvData[csvData.length - 1]).toEqual([
98137
'Overall Total',
99-
...monthlyTotals,
100-
overallAverage,
101-
overallTotal,
138+
'6870',
139+
'6190',
140+
'5870',
141+
'7455',
142+
'8135',
143+
'6675',
144+
'7656',
145+
'8239',
146+
'9799',
147+
'9729',
148+
'13020',
149+
'19215',
150+
'9071',
151+
'108856',
102152
]);
103153
});
104154
});

src/components/Reports/MPGAIncomeExpensesReport/CustomExport/CustomExport.tsx

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@ import { buildURI } from 'react-csv/lib/core';
22
import { ReportTypeEnum } from '../Helper/MPGAReportEnum';
33
import { DataFields } from '../mockData';
44

5-
export const createTable = (csvHeader: string[], data: DataFields[]) => {
5+
const round = (value: number, locale: string) =>
6+
new Intl.NumberFormat(locale, {
7+
style: 'decimal',
8+
minimumFractionDigits: 2,
9+
maximumFractionDigits: 2,
10+
trailingZeroDisplay: 'stripIfInteger',
11+
useGrouping: false,
12+
}).format(value);
13+
14+
export const createTable = (
15+
csvHeader: string[],
16+
data: DataFields[],
17+
locale: string,
18+
) => {
619
const csvData = data.map((item) => {
7-
const monthlyData = item.monthly.map((month) =>
8-
month === 0 ? '-' : month,
20+
const monthlyData = item.monthly.map((monthlyAmount) =>
21+
monthlyAmount === 0 ? '-' : round(monthlyAmount, locale),
922
);
10-
return [item.description, ...monthlyData, item.average, item.total];
23+
return [
24+
item.description,
25+
...monthlyData,
26+
round(item.average, locale),
27+
round(item.total, locale),
28+
];
1129
});
1230

1331
return [csvHeader, ...csvData];
@@ -17,6 +35,7 @@ export const exportToCsv = (
1735
data: DataFields[],
1836
reportType: ReportTypeEnum,
1937
months: string[],
38+
locale: string,
2039
) => {
2140
const title =
2241
reportType === ReportTypeEnum.Income
@@ -46,7 +65,7 @@ export const exportToCsv = (
4665
];
4766

4867
const csvHeader = ['Description', ...last12Months, 'Average', 'Total'];
49-
const csvData = createTable(csvHeader, dataWithTotal);
68+
const csvData = createTable(csvHeader, dataWithTotal, locale);
5069

5170
const csvBlob = buildURI(csvData, true);
5271

0 commit comments

Comments
 (0)