Skip to content

Commit f894eaa

Browse files
author
asvarcas
committed
Added tests for isRowExpandable prop
1 parent a6f69c9 commit f894eaa

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

packages/ra-ui-materialui/src/list/datagrid/DatagridRow.spec.tsx

+40
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,46 @@ describe('<DatagridRow />', () => {
5151
};
5252
};
5353

54+
describe('isRowExpandable', () => {
55+
it('should show the expand button if it returns true', () => {
56+
const contextValue = { isRowExpandable: () => true };
57+
58+
const { queryAllByText, getByText } = renderWithRouter(
59+
<DatagridContextProvider value={contextValue}>
60+
<DatagridRow
61+
{...defaultProps}
62+
rowClick="expand"
63+
expand={<ExpandPanel />}
64+
>
65+
<TitleField />
66+
</DatagridRow>
67+
</DatagridContextProvider>
68+
);
69+
expect(queryAllByText('expanded')).toHaveLength(0);
70+
fireEvent.click(getByText('hello'));
71+
expect(queryAllByText('expanded')).toHaveLength(0);
72+
});
73+
74+
it('should not show the expand button if it returns false', () => {
75+
const contextValue = { isRowExpandable: () => false };
76+
77+
const { queryAllByText, getByText } = renderWithRouter(
78+
<DatagridContextProvider value={contextValue}>
79+
<DatagridRow
80+
{...defaultProps}
81+
rowClick="expand"
82+
expand={<ExpandPanel />}
83+
>
84+
<TitleField />
85+
</DatagridRow>
86+
</DatagridContextProvider>
87+
);
88+
expect(queryAllByText('expanded')).toHaveLength(0);
89+
fireEvent.click(getByText('hello'));
90+
expect(queryAllByText('expanded')).toHaveLength(1);
91+
});
92+
});
93+
5494
describe('rowClick', () => {
5595
it("should redirect to edit page if the 'edit' option is selected", () => {
5696
const { getByText, history } = renderWithRouter(

0 commit comments

Comments
 (0)