Skip to content

Commit

Permalink
Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
mj12albert committed Oct 4, 2023
1 parent fd62628 commit 2fc52bd
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions packages/mui-material-next/src/InputBase/InputBase.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ import TextField from '@mui/material/TextField';
import Select from '@mui/material/Select';
import InputBase, { inputBaseClasses as classes } from '@mui/material-next/InputBase';
import { CssVarsProvider, extendTheme } from '@mui/material-next/styles';
import { InputBaseInputSlotPropsOverrides, InputBaseOwnerState, InputBaseProps } from './InputBase.types';
import {
InputBaseInputSlotPropsOverrides,
InputBaseOwnerState,
InputBaseProps,
} from './InputBase.types';

describe('<InputBase />', () => {
const { render } = createRenderer();
Expand Down Expand Up @@ -186,9 +190,12 @@ describe('<InputBase />', () => {
*
* A ref is exposed to trigger a change event instead of using fireEvent.change
*/
const BadInputComponent = React.forwardRef(function BadInputComponent(props: {
onChange: (arg: Record<string, unknown>) => void,
}, ref) {
const BadInputComponent = React.forwardRef(function BadInputComponent(
props: {
onChange: (arg: Record<string, unknown>) => void;
},
ref,
) {
const { onChange } = props;

// simulates const handleChange = () => onChange({}) and passing that
Expand Down Expand Up @@ -231,15 +238,20 @@ describe('<InputBase />', () => {
const { getByTestId } = render(
<InputBase
inputComponent="span"
slotProps={{ input: { 'data-testid': 'input-component' } as InputBaseInputSlotPropsOverrides }}
slotProps={{
input: { 'data-testid': 'input-component' } as InputBaseInputSlotPropsOverrides,
}}
/>,
);
expect(getByTestId('input-component')).to.have.property('nodeName', 'SPAN');
});

it('should inject onBlur and onFocus', () => {
let injectedProps: any = {};
const MyInputBase = React.forwardRef(function MyInputBase(props: any, ref: React.ForwardedRef<any>) {
const MyInputBase = React.forwardRef(function MyInputBase(
props: any,
ref: React.ForwardedRef<any>,
) {
injectedProps = props;
const { ownerState, ...other } = props;
return <input ref={ref} {...other} />;
Expand All @@ -255,13 +267,18 @@ describe('<InputBase />', () => {

describe('target mock implementations', () => {
it('can just mock the value', () => {
const MockedValue = React.forwardRef(function MockedValue(props: {
onChange: React.ChangeEventHandler<HTMLInputElement>,
}, ref: React.ForwardedRef<HTMLInputElement>) {
const MockedValue = React.forwardRef(function MockedValue(
props: {
onChange: React.ChangeEventHandler<HTMLInputElement>;
},
ref: React.ForwardedRef<HTMLInputElement>,
) {
const { onChange } = props;

const handleChange = (event: React.ChangeEvent<HTMLInputElement>) => {
onChange({ target: { value: event.target.value } } as React.ChangeEvent<HTMLInputElement>);
onChange({
target: { value: event.target.value },
} as React.ChangeEvent<HTMLInputElement>);
};

return <input ref={ref} onChange={handleChange} />;
Expand All @@ -286,7 +303,10 @@ describe('<InputBase />', () => {
});

it("can expose the input component's ref through the inputComponent prop", () => {
const FullTarget = React.forwardRef(function FullTarget(props: any, ref: React.ForwardedRef<HTMLInputElement>) {
const FullTarget = React.forwardRef(function FullTarget(
props: any,
ref: React.ForwardedRef<HTMLInputElement>,
) {
const { ownerState, ...otherProps } = props;
return <input ref={ref} {...otherProps} />;
});
Expand Down Expand Up @@ -406,9 +426,9 @@ describe('<InputBase />', () => {
});

type TestFormController = {
onFocus: () => {},
onBlur: () => {},
}
onFocus: () => {};
onBlur: () => {};
};

describe('focused', () => {
it('prioritizes context focus', () => {
Expand Down Expand Up @@ -583,10 +603,13 @@ describe('<InputBase />', () => {
const INPUT_VALUE = 'material';
const OUTPUT_VALUE = 'test';

const MyInputBase = React.forwardRef(function MyInputBase(props: {
onChange: (...args: string[]) => void,
ownerState: InputBaseOwnerState
}, ref: React.ForwardedRef<any>) {
const MyInputBase = React.forwardRef(function MyInputBase(
props: {
onChange: (...args: string[]) => void;
ownerState: InputBaseOwnerState;
},
ref: React.ForwardedRef<any>,
) {
const { onChange, ownerState, ...other } = props;

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
Expand Down

0 comments on commit 2fc52bd

Please sign in to comment.