-
-
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.
Merge branch 'master' into column-virtualization-dynamic-height
- Loading branch information
Showing
27 changed files
with
231 additions
and
52 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
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
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,15 @@ | ||
/** | ||
* Combines a type with required and additional properties. | ||
* | ||
* @template P - The original type. | ||
* @template RequiredProps - The keys to make required. | ||
* @template AdditionalProps - Additional properties to include. | ||
*/ | ||
|
||
export type DefaultizedProps< | ||
P extends {}, | ||
RequiredProps extends keyof P, | ||
AdditionalProps extends {} = {}, | ||
> = Omit<P, RequiredProps | keyof AdditionalProps> & | ||
Required<Pick<P, RequiredProps>> & | ||
AdditionalProps; |
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,7 @@ | ||
/** | ||
* Makes specified keys in a type optional. | ||
* | ||
* @template T - The original type. | ||
* @template K - The keys to make optional. | ||
*/ | ||
export type MakeOptional<T, K extends keyof T> = Omit<T, K> & Partial<Pick<T, K>>; |
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,8 @@ | ||
/** | ||
* Makes specified keys in a type required. | ||
* | ||
* @template T - The original type. | ||
* @template K - The keys to make required. | ||
*/ | ||
|
||
export type MakeRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>; |
13 changes: 13 additions & 0 deletions
13
packages/x-internals/src/types/SlotComponentPropsFromProps.ts
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,13 @@ | ||
/** | ||
* Defines the props for a slot component, which can be either partial props with overrides or a function returning such props. | ||
* | ||
* @template TProps - The original props type. | ||
* @template TOverrides - The overrides type. | ||
* @template TOwnerState - The owner state type. | ||
*/ | ||
|
||
export type SlotComponentPropsFromProps< | ||
TProps extends {}, | ||
TOverrides extends {}, | ||
TOwnerState extends {}, | ||
> = (Partial<TProps> & TOverrides) | ((ownerState: TOwnerState) => Partial<TProps> & TOverrides); |
Oops, something went wrong.