-
-
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.
[pickers] Add
referenceDate
prop on TimeClock
, DigitalClock
and…
… `MultiSectionDigitalClock` (#9356)
- Loading branch information
1 parent
3ee9e82
commit b53ee13
Showing
29 changed files
with
468 additions
and
128 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
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
68 changes: 68 additions & 0 deletions
68
packages/x-date-pickers/src/DigitalClock/tests/DigitalClock.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,68 @@ | ||
import * as React from 'react'; | ||
import { expect } from 'chai'; | ||
import { spy } from 'sinon'; | ||
import { DigitalClock } from '@mui/x-date-pickers/DigitalClock'; | ||
import { adapterToUse, createPickerRenderer } from 'test/utils/pickers-utils'; | ||
import { digitalClockHandler } from 'test/utils/pickers/viewHandlers'; | ||
|
||
describe('<DigitalClock />', () => { | ||
const { render } = createPickerRenderer(); | ||
|
||
describe('Reference date', () => { | ||
it('should use `referenceDate` when no value defined', () => { | ||
const onChange = spy(); | ||
|
||
render( | ||
<DigitalClock | ||
onChange={onChange} | ||
referenceDate={adapterToUse.date(new Date(2018, 0, 1, 12, 30))} | ||
/>, | ||
); | ||
|
||
digitalClockHandler.setViewValue( | ||
adapterToUse, | ||
adapterToUse.setMinutes(adapterToUse.setHours(adapterToUse.date(), 15), 30), | ||
); | ||
expect(onChange.callCount).to.equal(1); | ||
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2018, 0, 1, 15, 30)); | ||
}); | ||
|
||
it('should not use `referenceDate` when a value is defined', () => { | ||
const onChange = spy(); | ||
|
||
render( | ||
<DigitalClock | ||
onChange={onChange} | ||
value={adapterToUse.date(new Date(2019, 0, 1, 12, 30))} | ||
referenceDate={adapterToUse.date(new Date(2018, 0, 1, 15, 30))} | ||
/>, | ||
); | ||
|
||
digitalClockHandler.setViewValue( | ||
adapterToUse, | ||
adapterToUse.setMinutes(adapterToUse.setHours(adapterToUse.date(), 15), 30), | ||
); | ||
expect(onChange.callCount).to.equal(1); | ||
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2019, 0, 1, 15, 30)); | ||
}); | ||
|
||
it('should not use `referenceDate` when a defaultValue is defined', () => { | ||
const onChange = spy(); | ||
|
||
render( | ||
<DigitalClock | ||
onChange={onChange} | ||
defaultValue={adapterToUse.date(new Date(2019, 0, 1, 12, 30))} | ||
referenceDate={adapterToUse.date(new Date(2018, 0, 1, 15, 30))} | ||
/>, | ||
); | ||
|
||
digitalClockHandler.setViewValue( | ||
adapterToUse, | ||
adapterToUse.setMinutes(adapterToUse.setHours(adapterToUse.date(), 15), 30), | ||
); | ||
expect(onChange.callCount).to.equal(1); | ||
expect(onChange.lastCall.firstArg).toEqualDateTime(new Date(2019, 0, 1, 15, 30)); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.