-
-
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.
[pickers] Use
props.referenceDate
timezone when props.value
and `…
…props.defaultValue` are not defined (@flaviendelangle) (#15544) Co-authored-by: Flavien DELANGLE <[email protected]>
- Loading branch information
1 parent
ead5d30
commit ad56ac0
Showing
16 changed files
with
178 additions
and
26 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
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
108 changes: 108 additions & 0 deletions
108
packages/x-date-pickers/src/internals/hooks/useValueWithTimezone.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 { expect } from 'chai'; | ||
import { screen } from '@mui/internal-test-utils'; | ||
import { PickersTimezone, PickerValidDate } from '@mui/x-date-pickers/models'; | ||
import { createPickerRenderer } from 'test/utils/pickers'; | ||
import { useValueWithTimezone } from './useValueWithTimezone'; | ||
import { singleItemValueManager } from '../utils/valueManagers'; | ||
|
||
describe('useValueWithTimezone', () => { | ||
const { render, adapter } = createPickerRenderer({ | ||
clock: 'fake', | ||
adapterName: 'luxon', | ||
}); | ||
|
||
function runTest(params: { | ||
timezone: PickersTimezone | undefined; | ||
value: PickerValidDate | null | undefined; | ||
defaultValue: PickerValidDate | null | undefined; | ||
referenceDate: PickerValidDate | undefined; | ||
expectedTimezone: PickersTimezone; | ||
}) { | ||
const { expectedTimezone, ...other } = params; | ||
|
||
function TestComponent(props: typeof other) { | ||
const { timezone } = useValueWithTimezone({ | ||
...props, | ||
valueManager: singleItemValueManager, | ||
onChange: () => {}, | ||
}); | ||
|
||
return <div data-testid="result">{timezone}</div>; | ||
} | ||
|
||
render(<TestComponent {...other} />); | ||
|
||
expect(screen.getByTestId('result').textContent).to.equal(expectedTimezone); | ||
} | ||
|
||
it('should use the timezone parameter when provided', () => { | ||
runTest({ | ||
timezone: 'America/New_York', | ||
value: undefined, | ||
defaultValue: undefined, | ||
referenceDate: undefined, | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the timezone parameter over the value parameter when both are provided', () => { | ||
runTest({ | ||
timezone: 'America/New_York', | ||
value: adapter.date(undefined, 'Europe/Paris'), | ||
defaultValue: undefined, | ||
referenceDate: undefined, | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the value parameter when provided', () => { | ||
runTest({ | ||
timezone: undefined, | ||
value: adapter.date(undefined, 'America/New_York'), | ||
defaultValue: undefined, | ||
referenceDate: undefined, | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the value parameter over the defaultValue parameter when both are provided', () => { | ||
runTest({ | ||
timezone: undefined, | ||
value: adapter.date(undefined, 'America/New_York'), | ||
defaultValue: adapter.date(undefined, 'Europe/Paris'), | ||
referenceDate: undefined, | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the defaultValue parameter when provided', () => { | ||
runTest({ | ||
timezone: undefined, | ||
value: undefined, | ||
defaultValue: adapter.date(undefined, 'America/New_York'), | ||
referenceDate: undefined, | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the referenceDate parameter when provided', () => { | ||
runTest({ | ||
timezone: undefined, | ||
value: undefined, | ||
defaultValue: undefined, | ||
referenceDate: adapter.date(undefined, 'America/New_York'), | ||
expectedTimezone: 'America/New_York', | ||
}); | ||
}); | ||
|
||
it('should use the "default" timezone is there is no way to deduce the user timezone', () => { | ||
runTest({ | ||
timezone: undefined, | ||
value: undefined, | ||
defaultValue: undefined, | ||
referenceDate: undefined, | ||
expectedTimezone: 'default', | ||
}); | ||
}); | ||
}); |
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