-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DataGridPro] Add list view tests #15043
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
688d873
[DataGridPro] Add list view tests
KenanYusuf 438773c
add width/height to parent div
KenanYusuf c27f402
fix test
KenanYusuf 4a6cf18
Merge branch 'master' into list-view-tests
KenanYusuf 130b949
Improve warning message
KenanYusuf f56d35b
update test
KenanYusuf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
packages/x-data-grid-pro/src/tests/listView.DataGridPro.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,98 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { createRenderer, screen } from '@mui/internal-test-utils'; | ||
import { | ||
DataGridPro, | ||
DataGridProProps, | ||
GridColDef, | ||
GridListColDef, | ||
GridRowsProp, | ||
} from '@mui/x-data-grid-pro'; | ||
|
||
const rows: GridRowsProp = [{ id: '123567', title: 'test' }]; | ||
|
||
const columns: GridColDef[] = [{ field: 'id' }, { field: 'title' }]; | ||
|
||
const listColumn: GridListColDef = { | ||
field: 'listColumn', | ||
renderCell: (params) => <div data-testid="list-column">Title: {params.row.title}</div>, | ||
}; | ||
|
||
describe('<DataGridPro /> - List view', () => { | ||
const { render } = createRenderer(); | ||
|
||
function Test(props: Partial<DataGridProProps>) { | ||
return ( | ||
<div style={{ width: 300, height: 300 }}> | ||
<DataGridPro columns={columns} rows={rows} {...props} /> | ||
</div> | ||
); | ||
} | ||
|
||
it('should not render list column when list view is not enabled', () => { | ||
render( | ||
<div style={{ width: 300, height: 300 }}> | ||
<DataGridPro columns={columns} rows={rows} unstable_listColumn={listColumn} /> | ||
</div>, | ||
); | ||
expect(screen.queryByTestId('list-column')).to.equal(null); | ||
}); | ||
|
||
it('should render list column when list view is enabled', () => { | ||
render( | ||
<div style={{ width: 300, height: 300 }}> | ||
<DataGridPro | ||
columns={columns} | ||
rows={rows} | ||
unstable_listView | ||
unstable_listColumn={listColumn} | ||
/> | ||
</div>, | ||
); | ||
expect(screen.getByTestId('list-column')).not.to.equal(null); | ||
expect(screen.getByTestId('list-column')).to.have.text('Title: test'); | ||
}); | ||
|
||
it('should render list column when `unstable_listView` prop updates', () => { | ||
const { setProps } = render(<Test unstable_listColumn={listColumn} />); | ||
expect(screen.queryByTestId('list-column')).to.equal(null); | ||
|
||
setProps({ unstable_listView: true }); | ||
|
||
expect(screen.getByTestId('list-column')).not.to.equal(null); | ||
expect(screen.getByTestId('list-column')).to.have.text('Title: test'); | ||
|
||
setProps({ unstable_listView: false }); | ||
|
||
expect(screen.queryByTestId('list-column')).to.equal(null); | ||
}); | ||
|
||
it('should update cell contents when the `renderCell` function changes', () => { | ||
const { setProps } = render(<Test unstable_listView unstable_listColumn={listColumn} />); | ||
|
||
setProps({ | ||
unstable_listColumn: { | ||
...listColumn, | ||
renderCell: (params) => <div data-testid="list-column">ID: {params.row.id}</div>, | ||
}, | ||
} as Partial<DataGridProProps>); | ||
|
||
expect(screen.getByTestId('list-column')).to.have.text('ID: 123567'); | ||
}); | ||
|
||
it('should warn if the `unstable_listColumn` prop is not provided when `unstable_listView` is enabled', () => { | ||
expect(() => { | ||
render( | ||
<div style={{ width: 300, height: 300 }}> | ||
<DataGridPro columns={columns} rows={rows} unstable_listView /> | ||
</div>, | ||
); | ||
}).toWarnDev( | ||
[ | ||
'MUI X: The `unstable_listColumn` prop must be set if `unstable_listView` is enabled.', | ||
'To fix, pass a column definition to the `unstable_listColumn` prop, e.g. `{ field: "example", renderCell: (params) => <div>{params.row.id}</div> }`.', | ||
'For more details, see https://mui.com/x/react-data-grid/list-view/', | ||
].join('\n'), | ||
); | ||
}); | ||
}); |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Todo: