Skip to content

Commit

Permalink
Keep test
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon committed Nov 24, 2021
1 parent 2e947f8 commit 0f6dc58
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions packages/mui-material/src/RadioGroup/RadioGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,11 @@ describe('<RadioGroup />', () => {
</RadioGroup>,
);

const radios = getAllByRole('radio');

expect(radios[0].name).to.match(/^mui-[0-9]+/);
expect(radios[1].name).to.match(/^mui-[0-9]+/);
const [arbitraryRadio, ...radios] = getAllByRole('radio');
// `name` **property** will always be a string even if the **attribute** is omitted
expect(arbitraryRadio.name).not.to.equal('');
// all input[type="radio"] have the same name
expect(new Set(radios.map((radio) => radio.name))).to.have.length(1);
});

it('should support number value', () => {
Expand Down Expand Up @@ -299,21 +300,20 @@ describe('<RadioGroup />', () => {
});

describe('useRadioGroup', () => {
const RadioGroupController = React.forwardRef((_, ref) => {
const radioGroup = useRadioGroup();
React.useImperativeHandle(ref, () => radioGroup, [radioGroup]);
return null;
});
describe('from props', () => {
const MinimalRadio = React.forwardRef(function MinimalRadio(_, ref) {
const radioGroup = useRadioGroup();
return <input {...radioGroup} ref={ref} type="radio" />;
});

const RadioGroupControlled = React.forwardRef(function RadioGroupControlled(props, ref) {
return (
<RadioGroup {...props}>
<RadioGroupController ref={ref} />
</RadioGroup>
);
});
const RadioGroupControlled = React.forwardRef(function RadioGroupControlled(props, ref) {
return (
<RadioGroup {...props}>
<MinimalRadio ref={ref} />
</RadioGroup>
);
});

describe('from props', () => {
it('should have the name prop from the instance', () => {
const radioGroupRef = React.createRef();
const { setProps } = render(<RadioGroupControlled name="group" ref={radioGroupRef} />);
Expand All @@ -338,14 +338,27 @@ describe('<RadioGroup />', () => {
const radioGroupRef = React.createRef();
const { setProps } = render(<RadioGroupControlled ref={radioGroupRef} />);

expect(radioGroupRef.current.name).to.match(/^mui-[0-9]+/);
expect(radioGroupRef.current.name).not.to.equal('');

setProps({ name: 'anotherGroup' });
expect(radioGroupRef.current).to.have.property('name', 'anotherGroup');
});
});

describe('callbacks', () => {
const RadioGroupController = React.forwardRef((_, ref) => {
const radioGroup = useRadioGroup();
React.useImperativeHandle(ref, () => radioGroup, [radioGroup]);
return null;
});

const RadioGroupControlled = React.forwardRef(function RadioGroupControlled(props, ref) {
return (
<RadioGroup {...props}>
<RadioGroupController ref={ref} />
</RadioGroup>
);
});
describe('onChange', () => {
it('should set the value state', () => {
const radioGroupRef = React.createRef();
Expand Down

0 comments on commit 0f6dc58

Please sign in to comment.