@@ -7,14 +7,12 @@ import MerchantTransactions from '../MerchantTransactions';
77import { PointOfSaleTransactionProcessedDTO } from '../../../api/generated/merchants/PointOfSaleTransactionProcessedDTO' ;
88import getStatus from '../useStatus' ;
99import CustomChip from '../../Chip/CustomChip' ;
10- import TransactionDataTable from '../TransactionDataTable' ;
1110
1211jest . mock ( 'react-i18next' , ( ) => ( {
1312 useTranslation : ( ) => ( { t : ( key : string ) => key } ) ,
1413} ) ) ;
1514
1615const mockSetAlert = jest . fn ( ) ;
17-
1816jest . mock ( '../../../hooks/useAlert' , ( ) => ( {
1917 useAlert : ( ) => ( {
2018 alert : { isOpen : false } ,
@@ -24,6 +22,7 @@ jest.mock('../../../hooks/useAlert', () => ({
2422
2523jest . mock ( '../useStatus' , ( ) => jest . fn ( ) ) ;
2624jest . mock ( '../useDetailList' , ( ) => ( ) => [ ] ) ;
25+
2726jest . 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
4241jest . mock ( '../CurrencyColumn' , ( ) => ( props : any ) => < div > { props . value } </ div > ) ;
42+
4343jest . 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+
6366jest . 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
7578const MockedCustomChip = CustomChip as jest . Mock ;
76- const MockedTransactionDataTable = TransactionDataTable as jest . Mock ;
7779const mockedGetStatus = getStatus as jest . Mock ;
7880const 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-
9282describe ( '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