Skip to content

Commit fbca637

Browse files
author
Mario De Fazio
committed
Merge branch 'EBE-563-modify-doc-page' of https://github.com/pagopa/idpay-portal-merchants-frontend into EBE-563-modify-doc-page
2 parents c65c67d + a0510b5 commit fbca637

File tree

12 files changed

+986
-910
lines changed

12 files changed

+986
-910
lines changed

src/api/MerchantsApiClient.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,11 +241,15 @@ export const MerchantApi = {
241241
},
242242

243243
getRewardBatches: async (
244-
initiativeId: string
244+
initiativeId: string,
245+
page: number,
246+
size: number
245247
): Promise<RewardBatchListDTO> => {
246248
try {
247249
const result = await apiClient.getRewardBatches({
248-
initiativeId
250+
initiativeId,
251+
page,
252+
size
249253
});
250254

251255
return extractResponse(result, 200, onRedirectToLogin);

src/components/Drawer/__tests__/DetailDrawer.test.tsx

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ const Wrapper = ({ children }: { children: React.ReactNode }) => (
1010

1111
describe('DetailDrawer', () => {
1212
const defaultProps = {
13-
open: true,
14-
toggleDrawer: mockToggleDrawer,
13+
isOpen: true,
14+
setIsOpen: mockToggleDrawer,
1515
children: <div data-testid="drawer-content">Contenuto di Test</div>,
16+
title: "Titolo"
1617
};
1718

19+
const buttons = [{title: "button", dataTestId: "button-test-id"}]
20+
1821
beforeEach(() => {
1922
jest.clearAllMocks();
2023
});
@@ -29,16 +32,18 @@ describe('DetailDrawer', () => {
2932
const drawer = screen.getByTestId('detail-drawer');
3033
expect(drawer).toBeInTheDocument();
3134
expect(screen.getByText('Contenuto di Test')).toBeInTheDocument();
35+
expect(screen.getByText('Titolo')).toBeInTheDocument();
3236
});
3337

3438
it('should not render the content when open prop is false', () => {
3539
render(
3640
<Wrapper>
37-
<DetailDrawer {...defaultProps} open={false} />
41+
<DetailDrawer {...defaultProps} isOpen={false} />
3842
</Wrapper>
3943
);
4044

4145
expect(screen.queryByText('Contenuto di Test')).not.toBeInTheDocument();
46+
expect(screen.queryByTestId("buttons-box")).not.toBeInTheDocument();
4247
});
4348

4449
it('should call toggleDrawer(false) when the CloseIcon button is clicked', () => {
@@ -48,25 +53,30 @@ describe('DetailDrawer', () => {
4853
</Wrapper>
4954
);
5055

51-
const closeButton = screen.getByTestId('open-detail-button');
56+
const closeButton = screen.getByTestId('close-button');
5257
fireEvent.click(closeButton);
5358

5459
expect(mockToggleDrawer).toHaveBeenCalledTimes(1);
55-
expect(mockToggleDrawer).toHaveBeenCalledWith(false);
5660
});
5761

58-
it('should call toggleDrawer(false) when the drawer is closed via background click (onClose event)', () => {
62+
it('should render buttons', () => {
5963
render(
6064
<Wrapper>
61-
<DetailDrawer {...defaultProps} />
65+
<DetailDrawer {...defaultProps} buttons={buttons} />
6266
</Wrapper>
6367
);
6468

65-
const drawer = screen.getByTestId('detail-drawer');
69+
expect(screen.getByTestId("buttons-box")).toBeInTheDocument();
70+
expect(screen.getByTestId("button-test-id")).toBeInTheDocument();
71+
});
6672

67-
fireEvent.keyDown(drawer, { key: 'Escape' });
73+
it('should not render buttons when is an empty array', () => {
74+
render(
75+
<Wrapper>
76+
<DetailDrawer {...defaultProps} buttons={[]} />
77+
</Wrapper>
78+
);
6879

69-
expect(mockToggleDrawer).toHaveBeenCalledTimes(1);
70-
expect(mockToggleDrawer).toHaveBeenCalledWith(false);
80+
expect(screen.queryByTestId("buttons-box")).not.toBeInTheDocument();
7181
});
7282
});

src/components/Transactions/TransactionDetail.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,8 @@ export default function TransactionDetail({ itemValues, listItem, ...rest }: Pro
7676
text: 'Non è stato possibile scaricare il file',
7777
isOpen: true,
7878
severity: 'error',
79-
containerStyle: {
80-
height: 'fit-content',
81-
position: 'fixed',
82-
bottom: '20px',
83-
right: '20px',
84-
zIndex: '1300',
85-
},
86-
contentStyle: { position: 'unset', bottom: '0', right: '0' },
79+
containerStyle: { height: 'fit-content', position: 'fixed', bottom: '20px', right: '20px', zIndex: '1300' },
80+
contentStyle: { position: 'unset', bottom: '0', right: '0' }
8781
});
8882
setIsLoading(false);
8983
}

src/components/Transactions/__tests__/MerchantTransactions.test.tsx

Lines changed: 58 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@ import MerchantTransactions from '../MerchantTransactions';
77
import { PointOfSaleTransactionProcessedDTO } from '../../../api/generated/merchants/PointOfSaleTransactionProcessedDTO';
88
import getStatus from '../useStatus';
99
import CustomChip from '../../Chip/CustomChip';
10-
import TransactionDataTable from '../TransactionDataTable';
1110

1211
jest.mock('react-i18next', () => ({
1312
useTranslation: () => ({ t: (key: string) => key }),
1413
}));
1514

1615
const mockSetAlert = jest.fn();
17-
1816
jest.mock('../../../hooks/useAlert', () => ({
1917
useAlert: () => ({
2018
alert: { isOpen: false },
@@ -24,6 +22,7 @@ jest.mock('../../../hooks/useAlert', () => ({
2422

2523
jest.mock('../useStatus', () => jest.fn());
2624
jest.mock('../useDetailList', () => () => []);
25+
2726
jest.mock('../../Chip/CustomChip', () => {
2827
return jest.fn((props: any) => (
2928
<div data-testid="custom-chip">{props.label}</div>
@@ -40,61 +39,64 @@ jest.mock('@mui/material', () => ({
4039
}));
4140

4241
jest.mock('../CurrencyColumn', () => (props: any) => <div>{props.value}</div>);
42+
4343
jest.mock('../../../pages/components/EmptyList', () => (props: any) => (
4444
<div data-testid="empty-list">{props.message}</div>
4545
));
46-
jest.mock('../TransactionDetail', () => (props: any) => (
47-
<div data-testid="transaction-detail">{props.title}</div>
48-
));
49-
jest.mock(
50-
'../TransactionDataTable',
51-
() =>
52-
({ handleRowAction, onSortModelChange, onPaginationPageChange, rows }: any) =>
53-
(
54-
<div data-testid="transaction-data-table">
55-
<button onClick={() => handleRowAction(rows[0])}>Row Action</button>
56-
<button onClick={() => onSortModelChange([{ field: 'updateDate', sort: 'desc' }])}>
57-
Sort Action
58-
</button>
59-
<button onClick={() => onPaginationPageChange(2)}>Pagination Action</button>
60-
</div>
61-
)
46+
47+
jest.mock('../TransactionDataTable', () =>
48+
(props: any) => (
49+
<div data-testid="transaction-data-table">
50+
<button onClick={() => props.onSortModelChange([{ field: 'updateDate', sort: 'desc' }])}>
51+
Sort Action
52+
</button>
53+
<button onClick={() => props.onPaginationPageChange(2)}>Pagination Action</button>
54+
<button onClick={() => props.handleRowAction(props.rows[0])}>Row Action</button>
55+
{props.columns.map((col: any) => {
56+
return (
57+
<div key={col.field} data-testid={`col-${col.field}`}>
58+
{col.valueGetter ? props?.rows[0]?.additionalProperties?.productName : props?.rows[0]?.[col.field]}
59+
</div>
60+
);
61+
})}
62+
</div>
63+
)
6264
);
65+
6366
jest.mock(
64-
'../../Drawer/DetailDrawer',
67+
'../TransactionDetail',
6568
() =>
66-
({ open, toggleDrawer, children }: any) =>
67-
open ? (
69+
({ isOpen, setIsOpen, children }: any) =>
70+
isOpen && (
6871
<div data-testid="detail-drawer">
6972
{children}
70-
<button onClick={() => toggleDrawer(false)}>Close Drawer</button>
73+
<button data-testid="close-button" onClick={() => setIsOpen(false)}>Close Drawer</button>
7174
</div>
72-
) : null
75+
)
7376
);
7477

7578
const MockedCustomChip = CustomChip as jest.Mock;
76-
const MockedTransactionDataTable = TransactionDataTable as jest.Mock;
7779
const mockedGetStatus = getStatus as jest.Mock;
7880
const MockedTooltip = Tooltip as jest.Mock;
7981

80-
const mockTransactions: Array<PointOfSaleTransactionProcessedDTO> = [
81-
{
82-
trxId: '1',
83-
updateDate: '2025-10-06T10:00:00Z',
84-
fiscalCode: 'AAAAAA00A00A000A',
85-
effectiveAmountCents: 5000,
86-
rewardAmountCents: 500,
87-
status: 'REWARDED',
88-
additionalProperties: { productName: 'Frigorifero' },
89-
},
90-
];
91-
9282
describe('MerchantTransactions', () => {
9383
const handleFiltersApplied = jest.fn();
9484
const handleFiltersReset = jest.fn();
9585
const handleSortChange = jest.fn();
9686
const handlePaginationPageChange = jest.fn();
9787

88+
const mockTransactions: any = [
89+
{
90+
trxId: '1',
91+
updateDate: '2025-10-06T10:00:00Z',
92+
fiscalCode: 'AAAAAA00A00A000A',
93+
effectiveAmountCents: 5000,
94+
rewardAmountCents: 500,
95+
status: 'REWARDED',
96+
additionalProperties: { productName: 'Frigorifero' },
97+
}
98+
]
99+
98100
beforeEach(() => {
99101
jest.clearAllMocks();
100102
mockedGetStatus.mockImplementation((status) => ({ label: status, color: 'green', textColor: 'white' }));
@@ -105,10 +107,14 @@ describe('MerchantTransactions', () => {
105107
<MerchantTransactions
106108
transactions={mockTransactions}
107109
handleFiltersApplied={handleFiltersApplied}
108-
handleFiltersReset={handleFiltersReset}
109-
/>
110+
handleFiltersReset={handleFiltersReset} />
110111
);
111112
expect(screen.getByTestId('transaction-data-table')).toBeInTheDocument();
113+
expect(screen.getByText('Frigorifero')).toBeInTheDocument();
114+
expect(screen.getByText('AAAAAA00A00A000A')).toBeInTheDocument();
115+
expect(screen.getByText('5000')).toBeInTheDocument();
116+
expect(screen.getByText('500')).toBeInTheDocument();
117+
expect(screen.getByText('REWARDED')).toBeInTheDocument();
112118
expect(screen.queryByTestId('empty-list')).not.toBeInTheDocument();
113119
});
114120

@@ -262,7 +268,7 @@ describe('MerchantTransactions', () => {
262268
const rowButton = screen.getByRole('button', { name: 'Row Action' });
263269
await userEvent.click(rowButton);
264270

265-
expect(screen.getByTestId('detail-drawer')).toBeInTheDocument();
271+
await waitFor(() => expect(screen.getByTestId('detail-drawer')).toBeInTheDocument());
266272
});
267273

268274
it('closes drawer when toggle is called', async () => {
@@ -276,9 +282,9 @@ describe('MerchantTransactions', () => {
276282

277283
const rowButton = screen.getByRole('button', { name: 'Row Action' });
278284
await userEvent.click(rowButton);
279-
expect(screen.getByTestId('detail-drawer')).toBeInTheDocument();
285+
await waitFor(() => expect(screen.getByTestId('detail-drawer')).toBeInTheDocument());
280286

281-
const closeButton = screen.getByRole('button', { name: 'Close Drawer' });
287+
const closeButton = screen.getByTestId('close-button');
282288
await userEvent.click(closeButton);
283289
expect(screen.queryByTestId('detail-drawer')).not.toBeInTheDocument();
284290
});
@@ -295,7 +301,8 @@ describe('MerchantTransactions', () => {
295301
const rowButton = screen.getByRole('button', { name: 'Row Action' });
296302
await userEvent.click(rowButton);
297303

298-
const closeButton = screen.getByRole('button', { name: 'Close Drawer' });
304+
await waitFor(() => expect(screen.getByTestId('detail-drawer')).toBeInTheDocument());
305+
const closeButton = screen.getByTestId('close-button');
299306
await userEvent.click(closeButton);
300307

301308
await waitFor(() => {
@@ -632,7 +639,7 @@ describe('MerchantTransactions', () => {
632639
const rowButton = screen.getByRole('button', { name: 'Row Action' });
633640
await userEvent.click(rowButton);
634641

635-
expect(screen.getByTestId('transaction-detail')).toBeInTheDocument();
642+
await waitFor(() => expect(screen.getByTestId('detail-drawer')).toBeInTheDocument());
636643
});
637644

638645
it('passes correct props to transaction data table', () => {
@@ -745,6 +752,7 @@ describe('MerchantTransactions', () => {
745752
});
746753

747754
it('does not call handleFiltersReset when callback is undefined', async () => {
755+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
748756
render(
749757
<MerchantTransactions
750758
transactions={mockTransactions}
@@ -759,11 +767,15 @@ describe('MerchantTransactions', () => {
759767
await userEvent.type(fiscalCodeInput, 'test');
760768
await userEvent.click(applyButton);
761769
});
770+
expect(consoleSpy).toHaveBeenCalled()
762771

763772
await waitFor(() => {
764773
const resetButton = screen.getByRole('button', { name: 'commons.removeFiltersBtn' });
765774
expect(resetButton).toBeInTheDocument();
775+
userEvent.click(resetButton)
766776
});
777+
expect(consoleSpy).toHaveBeenCalled()
778+
consoleSpy.mockRestore();
767779
});
768780

769781
it('does not call handleSortChange when callback is undefined', async () => {
@@ -863,7 +875,6 @@ describe('MerchantTransactions', () => {
863875

864876
await waitFor(() => {
865877
expect(screen.getByTestId('detail-drawer')).toBeInTheDocument();
866-
expect(screen.getByTestId('transaction-detail')).toBeInTheDocument();
867878
});
868879
});
869880

@@ -939,7 +950,7 @@ describe('MerchantTransactions', () => {
939950
render(<MerchantTransactions
940951
transactions={mockTransactions}
941952
handleFiltersApplied={handleFiltersApplied}
942-
handleFiltersReset={handleFiltersReset} sortModel={[]} />);
953+
handleFiltersReset={handleFiltersReset} sortModel={[]} />);
943954

944955
const applyButton = screen.getByRole('button', { name: 'commons.filterBtn' });
945956
fireEvent.click(applyButton);
@@ -956,7 +967,8 @@ describe('MerchantTransactions', () => {
956967
/>);
957968

958969
await userEvent.click(screen.getByRole('button', { name: 'Row Action' }));
959-
await userEvent.click(screen.getByRole('button', { name: 'Close Drawer' }));
970+
await waitFor(() => expect(screen.getByTestId('detail-drawer')).toBeInTheDocument());
971+
await userEvent.click(screen.getByTestId('close-button'));
960972

961973
await waitFor(() => {
962974
expect(mockSetAlert).toHaveBeenCalledWith({ isOpen: false });

0 commit comments

Comments
 (0)