Skip to content

Commit

Permalink
[test] Migrate ButtonBase to react-testing-library (#23011)
Browse files Browse the repository at this point in the history
  • Loading branch information
deiga authored Oct 14, 2020
1 parent 1261e18 commit 888614b
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions packages/material-ui/src/ButtonBase/ButtonBase.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import * as React from 'react';
import { expect } from 'chai';
import { spy } from 'sinon';
import { spy, stub } from 'sinon';
import {
getClasses,
createMount,
Expand All @@ -15,7 +15,6 @@ import {
programmaticFocusTriggersFocusVisible,
} from 'test/utils';
import * as PropTypes from 'prop-types';
import TouchRipple from './TouchRipple';
import ButtonBase from './ButtonBase';

describe('<ButtonBase />', () => {
Expand Down Expand Up @@ -428,13 +427,54 @@ describe('<ButtonBase />', () => {

describe('prop: centerRipple', () => {
it('centers the TouchRipple', () => {
const wrapper = mount(<ButtonBase centerRipple>Hello</ButtonBase>);
expect(wrapper.find(TouchRipple).props()).to.have.property('center', true);
const { container, getByRole } = render(
<ButtonBase
centerRipple
TouchRippleProps={{ classes: { root: 'touch-ripple', ripple: 'touch-ripple-ripple' } }}
>
Hello
</ButtonBase>,
);
// @ts-ignore
stub(container.querySelector('.touch-ripple'), 'getBoundingClientRect').callsFake(() => ({
width: 100,
height: 100,
bottom: 10,
left: 20,
top: 20,
}));
fireEvent.mouseDown(getByRole('button'), { clientX: 10, clientY: 10 });
const rippleRipple = container.querySelector('.touch-ripple-ripple');
expect(rippleRipple).to.not.equal(null);
// @ts-ignore
const rippleSyle = window.getComputedStyle(rippleRipple);
expect(rippleSyle).to.have.property('height', '101px');
expect(rippleSyle).to.have.property('width', '101px');
});

it('is disabled by default', () => {
const wrapper = mount(<ButtonBase>Hello</ButtonBase>);
expect(wrapper.find(TouchRipple).props()).to.have.property('center', false);
const { container, getByRole } = render(
<ButtonBase
TouchRippleProps={{ classes: { root: 'touch-ripple', ripple: 'touch-ripple-ripple' } }}
>
Hello
</ButtonBase>,
);
// @ts-ignore
stub(container.querySelector('.touch-ripple'), 'getBoundingClientRect').callsFake(() => ({
width: 100,
height: 100,
bottom: 10,
left: 20,
top: 20,
}));
fireEvent.mouseDown(getByRole('button'), { clientX: 10, clientY: 10 });
const rippleRipple = container.querySelector('.touch-ripple-ripple');
expect(rippleRipple).to.not.equal(null);
// @ts-ignore
const rippleSyle = window.getComputedStyle(rippleRipple);
expect(rippleSyle).to.not.have.property('height', '101px');
expect(rippleSyle).to.not.have.property('width', '101px');
});
});

Expand Down

0 comments on commit 888614b

Please sign in to comment.