Skip to content

Commit

Permalink
port tests from mui#35924
Browse files Browse the repository at this point in the history
  • Loading branch information
sai6855 committed Jul 24, 2023
1 parent 1da3d5f commit 7cdba2f
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 10 deletions.
27 changes: 27 additions & 0 deletions packages/mui-material/src/Card/Card.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as React from 'react';
import Card from '@mui/material/Card';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

function CardTest() {
return (
<div>
<Card />
<Card elevation={4} />
<Card
onClick={(event) => {
expectType<React.MouseEvent<HTMLDivElement, MouseEvent>, typeof event>(event);
}}
/>
<Card component="a" href="test" />

<Card component={CustomComponent} stringProp="test" numberProp={0} />
{/* @ts-expect-error missing stringProp and numberProp */}
<Card<typeof CustomComponent> component={CustomComponent} />
</div>
);
}
2 changes: 2 additions & 0 deletions packages/mui-material/src/CardHeader/CardHeader.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface ComponentProp {
component?: React.ElementType;
}

<CardHeader component={CustomComponent} stringProp="s" numberProp={2} />;

function createElementBasePropMixedTest() {
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader);
React.createElement<CardHeaderProps<DefaultComponent, ComponentProp>>(CardHeader, {
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Dialog/Dialog.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export interface DialogProps extends StandardProps<ModalProps, 'children'> {
* Props applied to the [`Paper`](/material-ui/api/paper/) element.
* @default {}
*/
PaperProps?: Partial<PaperProps>;
PaperProps?: Partial<PaperProps<React.ElementType>>;
/**
* Determine the container for scrolling the dialog.
* @default 'paper'
Expand Down
19 changes: 16 additions & 3 deletions packages/mui-material/src/Dialog/Dialog.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
import * as React from 'react';
import { Dialog } from '@mui/material';
import Dialog from '@mui/material/Dialog';
import { PaperProps } from '@mui/material/Paper';
import { expectType } from '@mui/types';

function optionalChildrenTest() {
<Dialog open />;
const paperProps: PaperProps<'span'> = {
component: 'span',
onClick: (event) => {
expectType<React.MouseEvent<HTMLSpanElement, MouseEvent>, typeof event>(event);
},
};
function Test() {
return (
<React.Fragment>
<Dialog open />;
<Dialog open PaperProps={paperProps} />;
</React.Fragment>
);
}
2 changes: 1 addition & 1 deletion packages/mui-material/src/Drawer/Drawer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface DrawerProps extends StandardProps<ModalProps, 'open' | 'childre
* Props applied to the [`Paper`](/material-ui/api/paper/) element.
* @default {}
*/
PaperProps?: Partial<PaperProps>;
PaperProps?: Partial<PaperProps<React.ElementType>>;
/**
* Props applied to the [`Slide`](/material-ui/api/slide/) element.
*/
Expand Down
19 changes: 19 additions & 0 deletions packages/mui-material/src/Drawer/Drawer.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import * as React from 'react';
import Drawer from '@mui/material/Drawer';
import { PaperProps } from '@mui/material/Paper';
import { expectType } from '@mui/types';

const paperProps: PaperProps<'span'> = {
component: 'span',
onClick: (event) => {
expectType<React.MouseEvent<HTMLSpanElement, MouseEvent>, typeof event>(event);
},
};
function Test() {
return (
<React.Fragment>
<Drawer open />;
<Drawer open PaperProps={paperProps} />;
</React.Fragment>
);
}
61 changes: 61 additions & 0 deletions packages/mui-material/src/FormHelperText/FormHelperText.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import * as React from 'react';
import FormHelperText, { FormHelperTextProps } from '@mui/material/FormHelperText';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props: FormHelperTextProps<'div'> = {
component: 'div',
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props2: FormHelperTextProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLParagraphElement>, typeof event>(event);
},
};

const props4: FormHelperTextProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
};

const props5: FormHelperTextProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: FormHelperTextProps<typeof CustomComponent> = {
component: CustomComponent,
};

const TestComponent = () => {
return (
<React.Fragment>
<FormHelperText />
<FormHelperText component={'a'} href="/test" />

<FormHelperText component={CustomComponent} stringProp="s" numberProp={1} />
{
// @ts-expect-error
<FormHelperText component={CustomComponent} />
}
<FormHelperText
component="span"
onChange={(event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
}}
/>
</React.Fragment>
);
};
60 changes: 58 additions & 2 deletions packages/mui-material/src/Grid/Grid.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,63 @@
import * as React from 'react';
import Paper from '@mui/material/Paper';
import Grid from '@mui/material/Grid';
import Grid, { GridProps } from '@mui/material/Grid';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props: GridProps<'span'> = {
component: 'span',
onChange: (event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
},
};

const props2: GridProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props4: GridProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
};

const props5: GridProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: GridProps<typeof CustomComponent> = {
component: CustomComponent,
};

function ResponsiveTest() {
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square />;
return (
<React.Fragment>
<Grid item xs={12} sm={8} md={5} component={Paper} elevation={6} square />
<Grid item component={'a'} href="/test" />

<Grid item component={CustomComponent} stringProp="s" numberProp={1} />
{
// @ts-expect-error
<Grid item component={CustomComponent} />
}
<Grid
item
component="span"
onChange={(event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
}}
/>
</React.Fragment>
);
}
39 changes: 38 additions & 1 deletion packages/mui-material/src/Link/Link.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
import * as React from 'react';
import Link from '@mui/material/Link';
import Link, { LinkProps } from '@mui/material/Link';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props1: LinkProps<'div'> = {
component: 'div',
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props2: LinkProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLAnchorElement>, typeof event>(event);
},
};

const props4: LinkProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '1',
numberProp: 2,
};

const props5: LinkProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: LinkProps<typeof CustomComponent> = {
component: CustomComponent,
};

<Link
ref={(elem) => {
expectType<HTMLAnchorElement | null, typeof elem>(elem);
Expand Down
66 changes: 66 additions & 0 deletions packages/mui-material/src/MenuItem/MenuItem.spec.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import * as React from 'react';
import MenuItem, { MenuItemProps } from '@mui/material/MenuItem';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props: MenuItemProps<'div'> = {
component: 'div',
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props2: MenuItemProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLLIElement>, typeof event>(event);
},
};

const props4: MenuItemProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
};

const props5: MenuItemProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: MenuItemProps<typeof CustomComponent> = {
component: CustomComponent,
};

const TestComponent = () => {
return (
<React.Fragment>
<MenuItem />
<MenuItem component={'a'} href="/test" />

<MenuItem component={CustomComponent} stringProp="s" numberProp={1} />
{
// @ts-expect-error
<MenuItem component={CustomComponent} />
}
<MenuItem
onChange={(event) => {
expectType<React.FormEvent<HTMLLIElement>, typeof event>(event);
}}
/>
<MenuItem
component="span"
onChange={(event) => {
expectType<React.FormEvent<HTMLSpanElement>, typeof event>(event);
}}
/>
</React.Fragment>
);
};
35 changes: 34 additions & 1 deletion packages/mui-material/src/Paper/Paper.spec.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
import * as React from 'react';
import Paper from '@mui/material/Paper';
import Paper, { PaperProps } from '@mui/material/Paper';
import { expectType } from '@mui/types';

const CustomComponent: React.FC<{ stringProp: string; numberProp: number }> =
function CustomComponent() {
return <div />;
};

const props: PaperProps<'div'> = {
component: 'div',
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props2: PaperProps = {
onChange: (event) => {
expectType<React.FormEvent<HTMLDivElement>, typeof event>(event);
},
};

const props4: PaperProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
};

const props5: PaperProps<typeof CustomComponent> = {
component: CustomComponent,
stringProp: '2',
numberProp: 2,
// @ts-expect-error
inCorrectProp: 3,
};

// @ts-expect-error
const props6: PaperProps<typeof CustomComponent> = {
component: CustomComponent,
};

function PaperTest() {
return (
<div>
Expand Down
2 changes: 1 addition & 1 deletion packages/mui-material/src/Popover/Popover.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export interface PopoverProps
*
* @default {}
*/
PaperProps?: Partial<PaperProps>;
PaperProps?: Partial<PaperProps<React.ElementType>>;
/**
* The components used for each slot inside.
*
Expand Down
Loading

0 comments on commit 7cdba2f

Please sign in to comment.