Skip to content

Commit

Permalink
Avoid using setProps with debounce
Browse files Browse the repository at this point in the history
  • Loading branch information
arminmeh committed Jan 10, 2025
1 parent 9a138c0 commit 4d4f972
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
34 changes: 15 additions & 19 deletions packages/x-data-grid-pro/src/tests/dataSource.DataGridPro.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,38 +106,32 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source', () => {
});

it('should re-fetch the data on sort change', async () => {
const { setProps } = render(<TestDataSource />);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(1);
});
setProps({ sortModel: [{ field: 'name', sort: 'asc' }] });
render(<TestDataSource />);
expect(fetchRowsSpy.callCount).to.equal(1);
apiRef.current.setSortModel([{ field: 'name', sort: 'asc' }]);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
});
});

it('should re-fetch the data on pagination change', async () => {
const { setProps } = render(<TestDataSource />);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(1);
});
setProps({ paginationModel: { page: 1, pageSize: 10 } });
render(<TestDataSource />);
expect(fetchRowsSpy.callCount).to.equal(1);
apiRef.current.setPaginationModel({ page: 1, pageSize: 10 });
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
});
});

it('should re-fetch the data once if multiple models have changed', async () => {
const { setProps } = render(<TestDataSource />);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(1);
});
render(<TestDataSource />);
expect(fetchRowsSpy.callCount).to.equal(1);

setProps({
paginationModel: { page: 1, pageSize: 10 },
sortModel: [{ field: 'name', sort: 'asc' }],
filterModel: { items: [{ field: 'name', value: 'John', operator: 'contains' }] },
apiRef.current.setFilterModel({
items: [{ field: 'name', value: 'John', operator: 'contains' }],
});
apiRef.current.setSortModel([{ field: 'name', sort: 'asc' }]);
apiRef.current.setPaginationModel({ page: 1, pageSize: 10 });

await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
Expand Down Expand Up @@ -217,7 +211,9 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source', () => {
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
});
expect(cache.size).to.equal(2);
await waitFor(() => {
expect(cache.size).to.equal(2);
});

const dataRow2 = await screen.findByText(
(_, el) => el?.getAttribute('data-rowindex') === '0' && el !== dataRow1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source lazy loader', () => {
});

it('should re-fetch the data once if multiple models have changed', async () => {
const { setProps } = render(<TestDataSourceLazyLoader />);
render(<TestDataSourceLazyLoader />);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(1);
});

setProps({
sortModel: [{ field: 'name', sort: 'asc' }],
filterModel: { items: [{ field: 'name', value: 'John', operator: 'contains' }] },
apiRef.current.setFilterModel({
items: [{ field: 'name', value: 'John', operator: 'contains' }],
});
apiRef.current.setSortModel([{ field: 'name', sort: 'asc' }]);

await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ describeSkipIf(isJSDOM)('<DataGridPro /> - Data source tree data', () => {
});

it('should re-fetch the data on pagination change', async () => {
const { setProps } = render(<TestDataSource />);
render(<TestDataSource />);
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(1);
});
setProps({ paginationModel: { page: 1, pageSize: 10 } });
apiRef.current.setPaginationModel({ page: 1, pageSize: 10 });
await waitFor(() => {
expect(fetchRowsSpy.callCount).to.equal(2);
});
Expand Down

0 comments on commit 4d4f972

Please sign in to comment.