Skip to content

Commit

Permalink
fix: fix test for cr
Browse files Browse the repository at this point in the history
  • Loading branch information
leleOFA committed Feb 17, 2025
1 parent c2650c0 commit 187891f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@ const PnTableBodyCell: React.FC<PnTableBodyCellProps> = ({
borderBottom: 'none',
}}
>
{onClick ? <ButtonNaked sx={buttonNakedInheritStyle}>{children}</ButtonNaked> : <>{children}</>}
{onClick ? (
<ButtonNaked onClick={onClick} sx={buttonNakedInheritStyle}>
{children}
</ButtonNaked>
) : (
<>{children}</>
)}
</TableCell>
);
export default PnTableBodyCell;
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ describe('PnTableBodyCell', () => {
);
const cell = getByTestId('cell');
fireEvent.click(cell);
expect(mockFn).toBeCalledTimes(1);
expect(mockFn).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,17 @@ describe('PnTable Component', () => {
expect(handleSort).toHaveBeenCalledWith({ order: 'desc', orderBy: 'column-1' });
});

it('click on a column', () => {
it('click on a cell', () => {
const { getByRole } = render(<RenderPnTable />);

const table = getByRole('table');
const tableBody = within(table).getByTestId('table-test.body');
const firstRow = within(tableBody).getAllByTestId('table-test.body.row')[0];
const tableColumns = within(firstRow).getAllByTestId('table-test.body.row.cell');
fireEvent.click(tableColumns[2].querySelectorAll('button')[0]);
const thirdRow = within(tableBody).getAllByTestId('table-test.body.row')[2];
const thirdCell = within(thirdRow).getAllByTestId('table-test.body.row.cell')[2];
const button = within(thirdCell).getByRole('button');
fireEvent.click(button);

expect(handleColumnClick).toHaveBeenCalledTimes(1);
expect(handleColumnClick).toHaveBeenCalledWith(rows[0], columns[2].id);
expect(handleColumnClick).toHaveBeenCalledWith(rows[2], columns[2].id);
});
});

0 comments on commit 187891f

Please sign in to comment.