-
-
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.
[DateTimeRangePicker] Fix validation behavior (#12243)
- Loading branch information
Showing
21 changed files
with
683 additions
and
91 deletions.
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
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
27 changes: 27 additions & 0 deletions
27
...s/x-date-pickers-pro/src/DateTimeRangePicker/tests/describes.DateTimeRangePicker.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,27 @@ | ||
import * as React from 'react'; | ||
import { createPickerRenderer, wrapPickerMount } from 'test/utils/pickers'; | ||
import { describeConformance } from 'test/utils/describeConformance'; | ||
import { DateTimeRangePicker } from '../DateTimeRangePicker'; | ||
|
||
describe('<DateTimeRangePicker /> - Describes', () => { | ||
const { render } = createPickerRenderer({ clock: 'fake' }); | ||
|
||
describeConformance(<DateTimeRangePicker />, () => ({ | ||
classes: {} as any, | ||
render, | ||
muiName: 'MuiDateTimeRangePicker', | ||
wrapMount: wrapPickerMount, | ||
refInstanceof: window.HTMLDivElement, | ||
skip: [ | ||
'componentProp', | ||
'componentsProp', | ||
'themeDefaultProps', | ||
'themeStyleOverrides', | ||
'themeVariants', | ||
'mergeClassName', | ||
'propsSpread', | ||
'rootClass', | ||
'reactTestRenderer', | ||
], | ||
})); | ||
}); |
168 changes: 168 additions & 0 deletions
168
...date-pickers-pro/src/DesktopDateTimeRangePicker/tests/DesktopDateTimeRangePicker.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,168 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { screen } from '@mui-internal/test-utils'; | ||
import { createPickerRenderer, adapterToUse } from 'test/utils/pickers'; | ||
import { DesktopDateTimeRangePicker } from '../DesktopDateTimeRangePicker'; | ||
|
||
describe('<DesktopDateTimeRangePicker />', () => { | ||
const { render } = createPickerRenderer({ | ||
clock: 'fake', | ||
clockConfig: new Date(2018, 0, 10, 10, 16, 0), | ||
}); | ||
|
||
describe('disabled dates', () => { | ||
it('should respect the "disablePast" prop', () => { | ||
render(<DesktopDateTimeRangePicker enableAccessibleFieldDOMStructure disablePast open />); | ||
|
||
expect(screen.getByRole('gridcell', { name: '8' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '9' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).not.to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '9 hours' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
|
||
expect(screen.getByRole('option', { name: '15 minutes' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
}); | ||
|
||
// Asserts correct behavior: https://github.com/mui/mui-x/issues/12048 | ||
it('should respect the "disablePast" prop combined with "referenceDate"', () => { | ||
render( | ||
<DesktopDateTimeRangePicker | ||
enableAccessibleFieldDOMStructure | ||
disablePast | ||
open | ||
referenceDate={adapterToUse.date('2018-01-11')} | ||
/>, | ||
); | ||
|
||
expect(screen.getByRole('gridcell', { name: '8' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '9' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).not.to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '9 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
|
||
expect(screen.getByRole('option', { name: '15 minutes' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
}); | ||
|
||
it('should respect the "disableFuture" prop', () => { | ||
render(<DesktopDateTimeRangePicker enableAccessibleFieldDOMStructure disableFuture open />); | ||
|
||
expect(screen.getByRole('gridcell', { name: '9' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '12' })).to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
expect(screen.getByRole('option', { name: '11 hours' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
}); | ||
|
||
// Asserts correct behavior: https://github.com/mui/mui-x/issues/12048 | ||
it('should respect the "disableFuture" prop combined with "referenceDate"', () => { | ||
render( | ||
<DesktopDateTimeRangePicker | ||
enableAccessibleFieldDOMStructure | ||
disableFuture | ||
open | ||
referenceDate={adapterToUse.date('2018-01-09')} | ||
/>, | ||
); | ||
|
||
expect(screen.getByRole('gridcell', { name: '9' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '12' })).to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
expect(screen.getByRole('option', { name: '11 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
}); | ||
|
||
it('should respect the "minDateTime" prop', () => { | ||
render( | ||
<DesktopDateTimeRangePicker | ||
enableAccessibleFieldDOMStructure | ||
minDateTime={adapterToUse.date('2018-01-10T10:16:00')} | ||
referenceDate={adapterToUse.date('2018-01-10T10:00:00')} | ||
open | ||
/>, | ||
); | ||
|
||
expect(screen.getByRole('gridcell', { name: '8' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '9' })).to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).not.to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '9 hours' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
|
||
expect(screen.getByRole('option', { name: '15 minutes' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
expect(screen.getByRole('option', { name: '20 minutes' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
}); | ||
|
||
it('should respect the "maxDateTime" prop', () => { | ||
render( | ||
<DesktopDateTimeRangePicker | ||
enableAccessibleFieldDOMStructure | ||
maxDateTime={adapterToUse.date('2018-01-10T10:16:00')} | ||
referenceDate={adapterToUse.date('2018-01-10T10:00:00')} | ||
open | ||
/>, | ||
); | ||
|
||
expect(screen.getByRole('gridcell', { name: '9' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '10' })).not.to.have.attribute('disabled'); | ||
expect(screen.getByRole('gridcell', { name: '11' })).to.have.attribute('disabled'); | ||
|
||
expect(screen.getByRole('option', { name: '10 hours' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
expect(screen.getByRole('option', { name: '11 hours' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
|
||
expect(screen.getByRole('option', { name: '15 minutes' })).not.to.have.attribute( | ||
'aria-disabled', | ||
); | ||
expect(screen.getByRole('option', { name: '20 minutes' })).to.have.attribute( | ||
'aria-disabled', | ||
'true', | ||
); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.