-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[XGrid] Close column header menu when resizing column (#1989)
* [XGrid] Close column header menu when resizing column * Run prettier * Fix test * Remove dummy line * Run Prettier * Fix browser tests * Run prettier * Fix * Fix comments * Remove it.only * Remove useless expect * Remove 'raf' * Clean listeners when unmounting the grid in useGridColumnResize * Remove commented test lines * Code review * Add test to check behavior when resizing another column * Remove 'only' * Move test in describe * Remove async * Code review * Code review
- Loading branch information
1 parent
7964e78
commit 55972c6
Showing
4 changed files
with
124 additions
and
1 deletion.
There are no files selected for viewing
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
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
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
101 changes: 101 additions & 0 deletions
101
packages/grid/x-grid/src/tests/columnHeaders.XGrid.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,101 @@ | ||
import * as React from 'react'; | ||
import { | ||
createClientRenderStrictMode, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
fireEvent, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
screen, | ||
// @ts-expect-error need to migrate helpers to TypeScript | ||
waitFor, | ||
} from 'test/utils'; | ||
import { expect } from 'chai'; | ||
import { GRID_COLUMN_HEADER_SEPARATOR_RESIZABLE_CSS_CLASS, XGrid } from '@material-ui/x-grid'; | ||
import { getColumnHeaderCell } from 'test/utils/helperFn'; | ||
|
||
const isJSDOM = /jsdom/.test(window.navigator.userAgent); | ||
|
||
describe('<XGrid /> - Column Headers', () => { | ||
// TODO v5: replace with createClientRender | ||
const render = createClientRenderStrictMode(); | ||
|
||
const baselineProps = { | ||
autoHeight: isJSDOM, | ||
disableColumnResize: false, | ||
rows: [ | ||
{ | ||
id: 0, | ||
brand: 'Nike', | ||
foundationYear: 1964, | ||
}, | ||
{ | ||
id: 1, | ||
brand: 'Adidas', | ||
foundationYear: 1949, | ||
}, | ||
{ | ||
id: 2, | ||
brand: 'Puma', | ||
foundationYear: 1948, | ||
}, | ||
], | ||
}; | ||
|
||
describe('GridColumnHeaderMenu', () => { | ||
it('should close the menu of a column when resizing this column', async () => { | ||
render( | ||
<div style={{ width: 300, height: 500 }}> | ||
<XGrid | ||
{...baselineProps} | ||
columns={[ | ||
{ field: 'brand', resizable: true }, | ||
{ field: 'foundationYear', resizable: true }, | ||
]} | ||
/> | ||
</div>, | ||
); | ||
|
||
const columnCell = getColumnHeaderCell(0); | ||
|
||
const menuIconButton = columnCell.querySelector('button[aria-label="Menu"]'); | ||
|
||
fireEvent.click(menuIconButton); | ||
await waitFor(() => expect(screen.queryByRole('menu')).not.to.equal(null)); | ||
|
||
const separator = columnCell.querySelector('.MuiDataGrid-iconSeparator'); | ||
fireEvent.mouseDown(separator); | ||
// TODO remove mouseUp once useGridColumnReorder will handle cleanup properly | ||
fireEvent.mouseUp(separator); | ||
await waitFor(() => expect(screen.queryByRole('menu')).to.equal(null)); | ||
}); | ||
|
||
it('should close the menu of a column when resizing another column', async () => { | ||
render( | ||
<div style={{ width: 300, height: 500 }}> | ||
<XGrid | ||
{...baselineProps} | ||
columns={[ | ||
{ field: 'brand', resizable: true }, | ||
{ field: 'foundationYear', resizable: true }, | ||
]} | ||
/> | ||
</div>, | ||
); | ||
|
||
const columnWithMenuCell = getColumnHeaderCell(0); | ||
const columnToResizeCell = getColumnHeaderCell(1); | ||
|
||
const menuIconButton = columnWithMenuCell.querySelector('button[aria-label="Menu"]'); | ||
|
||
fireEvent.click(menuIconButton); | ||
await waitFor(() => expect(screen.queryByRole('menu')).not.to.equal(null)); | ||
|
||
const separator = columnToResizeCell.querySelector( | ||
`.${GRID_COLUMN_HEADER_SEPARATOR_RESIZABLE_CSS_CLASS}`, | ||
); | ||
fireEvent.mouseDown(separator); | ||
// TODO remove mouseUp once useGridColumnReorder will handle cleanup properly | ||
fireEvent.mouseUp(separator); | ||
await waitFor(() => expect(screen.queryByRole('menu')).to.equal(null)); | ||
}); | ||
}); | ||
}); |