Fix the missing filter in the toolbar when passing a custom component in the core-components Table"

Signed-off-by: Danang <danang@canva.com>
This commit is contained in:
Danang
2022-06-02 17:20:05 +10:00
parent a9edc0eaef
commit 758e20eb87
2 changed files with 53 additions and 0 deletions
@@ -160,4 +160,55 @@ describe('<Table />', () => {
);
expect(rendered.getByText('EMPTY')).toBeInTheDocument();
});
describe('with custom components', () => {
const CustomRow = ({ data }) => {
return (
<tr>
<td>customised cell {data.col1}</td>
<td>customised cell {data.col2}</td>
</tr>
);
};
it('should not override the toolbar implementation', async () => {
const rendered = await renderInTestApp(
<Table
subtitle="subtitle"
emptyContent={<div>EMPTY</div>}
columns={minProps.columns}
data={minProps.data}
filters={[
{
column: column1.title,
type: 'select',
},
]}
components={{
Row: CustomRow,
}}
/>,
);
expect(rendered.getByText('Filters (0)')).toBeInTheDocument();
});
it('should render the provided custom row component correctly', async () => {
const rendered = await renderInTestApp(
<Table
subtitle="subtitle"
emptyContent={<div>EMPTY</div>}
columns={minProps.columns}
data={minProps.data}
components={{
Row: CustomRow,
}}
/>,
);
expect(
rendered.getByText('customised cell first value, first row'),
).toBeInTheDocument();
});
});
});
@@ -303,6 +303,7 @@ export function Table<T extends object = {}>(props: TableProps<T>) {
initialState,
emptyContent,
onStateChange,
components,
...restProps
} = props;
const tableClasses = useTableStyles();
@@ -493,6 +494,7 @@ export function Table<T extends object = {}>(props: TableProps<T>) {
Header: StyledMTableHeader,
Toolbar,
Body,
...components,
}}
options={{ ...defaultOptions, ...options }}
columns={MTColumns}