|
1 |
| -import { createRenderer, act } from '@mui/internal-test-utils'; |
| 1 | +import { createRenderer, act, waitFor } from '@mui/internal-test-utils'; |
2 | 2 | import { getColumnValues } from 'test/utils/helperFn';
|
3 | 3 | import * as React from 'react';
|
4 | 4 | import { RefObject } from '@mui/x-internals/types';
|
@@ -111,4 +111,45 @@ describe('<DataGridPro /> - Pagination', () => {
|
111 | 111 | 'MUI X: Usage of the `rowCount` prop with client side pagination (`paginationMode="client"`) has no effect. `rowCount` is only meant to be used with `paginationMode="server"`.',
|
112 | 112 | ]);
|
113 | 113 | });
|
| 114 | + |
| 115 | + // Test for https://github.com/mui/mui-x/issues/19281 |
| 116 | + it('should sync pagination prop with state properly', async () => { |
| 117 | + const columns = [{ field: 'name' }]; |
| 118 | + const rows = [ |
| 119 | + { id: 1, name: 'Row 1' }, |
| 120 | + { id: 2, name: 'Row 2' }, |
| 121 | + { id: 3, name: 'Row 3' }, |
| 122 | + { id: 4, name: 'Row 4' }, |
| 123 | + { id: 5, name: 'Row 5' }, |
| 124 | + { id: 6, name: 'Row 6' }, |
| 125 | + { id: 7, name: 'Row 7' }, |
| 126 | + { id: 8, name: 'Row 8' }, |
| 127 | + { id: 9, name: 'Row 9' }, |
| 128 | + { id: 10, name: 'Row 10' }, |
| 129 | + { id: 11, name: 'Row 11' }, |
| 130 | + ]; |
| 131 | + function TestComponent({ pagination = false }: { pagination?: boolean }) { |
| 132 | + return ( |
| 133 | + <div style={{ width: 300, height: 500 }}> |
| 134 | + <DataGridPro |
| 135 | + columns={columns} |
| 136 | + rows={rows} |
| 137 | + initialState={{ pagination: { paginationModel: { pageSize: 5 } } }} |
| 138 | + pageSizeOptions={[5, 10]} |
| 139 | + pagination={pagination} |
| 140 | + disableVirtualization |
| 141 | + /> |
| 142 | + </div> |
| 143 | + ); |
| 144 | + } |
| 145 | + |
| 146 | + const { setProps } = render(<TestComponent />); |
| 147 | + expect(getColumnValues(0)).to.have.length(11); |
| 148 | + setProps({ pagination: true }); |
| 149 | + |
| 150 | + await waitFor(() => { |
| 151 | + const visibleValues = getColumnValues(0); |
| 152 | + expect(visibleValues).to.have.length(5); |
| 153 | + }); |
| 154 | + }); |
114 | 155 | });
|
0 commit comments