2022-06-22 14:57:09 +08:00
|
|
|
import React from 'react';
|
|
|
|
import Radio, { Button, Group } from '..';
|
2017-11-19 01:41:40 +08:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2019-08-26 22:53:20 +08:00
|
|
|
import mountTest from '../../../tests/shared/mountTest';
|
2020-01-02 19:10:16 +08:00
|
|
|
import rtlTest from '../../../tests/shared/rtlTest';
|
2016-12-14 14:48:09 +08:00
|
|
|
|
2022-07-24 12:33:05 +08:00
|
|
|
import { render, fireEvent } from '../../../tests/utils';
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
describe('Radio', () => {
|
2020-05-27 10:21:17 +08:00
|
|
|
focusTest(Radio, { refFocus: true });
|
2019-08-26 22:53:20 +08:00
|
|
|
mountTest(Radio);
|
|
|
|
mountTest(Group);
|
|
|
|
mountTest(Button);
|
2017-11-19 01:41:40 +08:00
|
|
|
|
2020-01-02 19:10:16 +08:00
|
|
|
rtlTest(Radio);
|
|
|
|
rtlTest(Group);
|
|
|
|
rtlTest(Button);
|
|
|
|
|
2017-03-15 14:25:43 +08:00
|
|
|
it('should render correctly', () => {
|
2022-07-24 12:33:05 +08:00
|
|
|
const { container } = render(<Radio className="customized">Test</Radio>);
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2017-03-15 14:25:43 +08:00
|
|
|
});
|
|
|
|
|
2016-12-14 14:48:09 +08:00
|
|
|
it('responses hover events', () => {
|
|
|
|
const onMouseEnter = jest.fn();
|
|
|
|
const onMouseLeave = jest.fn();
|
|
|
|
|
2022-07-24 12:33:05 +08:00
|
|
|
const { container } = render(<Radio onMouseEnter={onMouseEnter} onMouseLeave={onMouseLeave} />);
|
2016-12-14 14:48:09 +08:00
|
|
|
|
2022-07-24 12:33:05 +08:00
|
|
|
fireEvent.mouseEnter(container.querySelector('label'));
|
2016-12-14 14:48:09 +08:00
|
|
|
expect(onMouseEnter).toHaveBeenCalled();
|
|
|
|
|
2022-07-24 12:33:05 +08:00
|
|
|
fireEvent.mouseLeave(container.querySelector('label'));
|
2016-12-14 14:48:09 +08:00
|
|
|
expect(onMouseLeave).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|