-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
112 additions
and
55 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
packages/grid/x-data-grid-premium/src/tests/DataGridPremium.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
import * as React from 'react'; | ||
import { createRenderer, act } from '@mui/monorepo/test/utils'; | ||
import { expect } from 'chai'; | ||
import { | ||
DataGridPremium as DataGrid, | ||
DataGridPremiumProps as DataGridProps, | ||
GridApi, | ||
GridToolbar, | ||
useGridApiRef, | ||
} from '@mui/x-data-grid-premium'; | ||
import { getColumnValues } from 'test/utils/helperFn'; | ||
|
||
const isJSDOM = /jsdom/.test(window.navigator.userAgent); | ||
|
||
describe('<DataGrid /> - Quick Filter', () => { | ||
const { render } = createRenderer(); | ||
|
||
const baselineProps = { | ||
autoHeight: isJSDOM, | ||
disableVirtualization: true, | ||
rows: [ | ||
{ | ||
id: 0, | ||
brand: 'Nike', | ||
}, | ||
{ | ||
id: 1, | ||
brand: 'Adidas', | ||
}, | ||
{ | ||
id: 2, | ||
brand: 'Puma', | ||
}, | ||
], | ||
columns: [{ field: 'brand' }], | ||
}; | ||
|
||
let apiRef: React.MutableRefObject<GridApi>; | ||
|
||
function TestCase(props: Partial<DataGridProps>) { | ||
apiRef = useGridApiRef(); | ||
|
||
return ( | ||
<div style={{ width: 300, height: 300 }}> | ||
<DataGrid | ||
{...baselineProps} | ||
apiRef={apiRef} | ||
slots={{ toolbar: GridToolbar }} | ||
disableColumnSelector | ||
disableDensitySelector | ||
disableColumnFilter | ||
{...props} | ||
slotProps={{ | ||
...props?.slotProps, | ||
toolbar: { | ||
showQuickFilter: true, | ||
...props?.slotProps?.toolbar, | ||
}, | ||
}} | ||
/> | ||
</div> | ||
); | ||
} | ||
|
||
// https://github.com/mui/mui-x/issues/9677 | ||
it('should not fail when adding a grouping criterion', () => { | ||
const { setProps } = render( | ||
<TestCase | ||
rows={[ | ||
{ | ||
id: 1, | ||
company: '20th Century Fox', | ||
director: 'James Cameron', | ||
year: 1999, | ||
title: 'Titanic', | ||
}, | ||
]} | ||
columns={[ | ||
{ field: 'company' }, | ||
{ field: 'director' }, | ||
{ field: 'year' }, | ||
{ field: 'title' }, | ||
]} | ||
initialState={{ | ||
rowGrouping: { | ||
model: ['company'], | ||
}, | ||
aggregation: { | ||
model: { | ||
director: 'size', | ||
}, | ||
}, | ||
}} | ||
/>, | ||
); | ||
|
||
act(() => apiRef.current.addRowGroupingCriteria('year')); | ||
|
||
setProps({ | ||
filterModel: { | ||
items: [], | ||
quickFilterValues: ['Cameron'], | ||
}, | ||
}); | ||
|
||
expect(getColumnValues(0)).to.deep.equal(['20th Century Fox (1)', '']); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters