Skip to content

Commit

Permalink
second iteration of the reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
oliviertassinari committed Jul 3, 2019
1 parent b08f759 commit 311e8d6
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 34 deletions.
3 changes: 3 additions & 0 deletions packages/material-ui-lab/src/Slider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export default React.forwardRef(function DeprecatedSlider(props, ref) {
false,
[
'Material-UI: the Slider component was moved from the lab to the core.',
'',
'Yay, the component is stable! 🎉',
'',
"You should use `import { Slider } from '@material-ui/core'`",
"or `import Slider from '@material-ui/core/Slider'`",
].join('\n'),
Expand Down
47 changes: 23 additions & 24 deletions packages/material-ui/src/Slider/Slider.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ function fireBodyMouseEvent(name, properties = {}) {
return event;
}

describe('<Slider />', () => {
describe.only('<Slider />', () => {
let mount;
let render;
let classes;
const render = createClientRender({ strict: true });

before(() => {
render = createClientRender({ strict: true });
classes = getClasses(<Slider value={0} />);
mount = createMount({ strict: true });
});
Expand Down Expand Up @@ -145,7 +144,7 @@ describe('<Slider />', () => {
it('should render with the vertical classes', () => {
const { container, getByRole } = render(<Slider orientation="vertical" value={0} />);
expect(container.firstChild).to.have.class(classes.vertical);
expect(getByRole('slider').getAttribute('aria-orientation')).to.equal('vertical');
expect(getByRole('slider')).to.have.attribute('aria-orientation', 'vertical');
});

it('should report the right position', () => {
Expand Down Expand Up @@ -244,26 +243,26 @@ describe('<Slider />', () => {
changedTouches: touchList([{ identifier: 1, pageX: 21, pageY: 0 }]),
});
container.firstChild.dispatchEvent(event);
expect(thumb.getAttribute('aria-valuenow')).to.equal('20');
expect(thumb).to.have.attribute('aria-valuenow', '20');

thumb.focus();
fireEvent.keyDown(document.activeElement, {
key: 'ArrowUp',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('30');
expect(thumb).to.have.attribute('aria-valuenow', '30');

fireEvent.keyDown(document.activeElement, {
key: 'ArrowDown',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('20');
expect(thumb).to.have.attribute('aria-valuenow', '20');
});
});

describe('prop: disabled', () => {
it('should render the disabled classes', () => {
const { container, getByRole } = render(<Slider disabled value={0} />);
expect(container.firstChild).to.have.class(classes.disabled);
expect(getByRole('slider').getAttribute('tabIndex')).to.equal(null);
expect(getByRole('slider')).to.not.have.attribute('tabIndex');
});
});

Expand All @@ -276,27 +275,27 @@ describe('<Slider />', () => {
fireEvent.keyDown(document.activeElement, {
key: 'Home',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('0');
expect(thumb).to.have.attribute('aria-valuenow', '0');

fireEvent.keyDown(document.activeElement, {
key: 'End',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('100');
expect(thumb).to.have.attribute('aria-valuenow', '100');

fireEvent.keyDown(document.activeElement, {
key: 'PageDown',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('90');
expect(thumb).to.have.attribute('aria-valuenow', '90');

fireEvent.keyDown(document.activeElement, {
key: 'Escape',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('90');
expect(thumb).to.have.attribute('aria-valuenow', '90');

fireEvent.keyDown(document.activeElement, {
key: 'PageUp',
});
expect(thumb.getAttribute('aria-valuenow')).to.equal('100');
expect(thumb).to.have.attribute('aria-valuenow', '100');
});

const moveLeftEvent = {
Expand All @@ -312,16 +311,16 @@ describe('<Slider />', () => {
thumb.focus();

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('100');
expect(thumb).to.have.attribute('aria-valuenow', '100');

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('108');
expect(thumb).to.have.attribute('aria-valuenow', '108');

fireEvent.keyDown(document.activeElement, moveLeftEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('100');
expect(thumb).to.have.attribute('aria-valuenow', '100');

fireEvent.keyDown(document.activeElement, moveLeftEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('90');
expect(thumb).to.have.attribute('aria-valuenow', '90');
});

it('should reach left edge value', () => {
Expand All @@ -330,16 +329,16 @@ describe('<Slider />', () => {
thumb.focus();

fireEvent.keyDown(document.activeElement, moveLeftEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('10');
expect(thumb).to.have.attribute('aria-valuenow', '10');

fireEvent.keyDown(document.activeElement, moveLeftEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('6');
expect(thumb).to.have.attribute('aria-valuenow', '6');

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('20');
expect(thumb).to.have.attribute('aria-valuenow', '20');

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('30');
expect(thumb).to.have.attribute('aria-valuenow', '30');
});

it('should round value to step precision', () => {
Expand All @@ -348,7 +347,7 @@ describe('<Slider />', () => {
thumb.focus();

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('0.3');
expect(thumb).to.have.attribute('aria-valuenow', '0.3');
});

it('should not fail to round value to step precision when step is very small', () => {
Expand All @@ -359,7 +358,7 @@ describe('<Slider />', () => {
thumb.focus();

fireEvent.keyDown(document.activeElement, moveRightEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('3e-8');
expect(thumb).to.have.attribute('aria-valuenow', '3e-8');
});

it('should not fail to round value to step precision when step is very small and negative', () => {
Expand All @@ -370,7 +369,7 @@ describe('<Slider />', () => {
thumb.focus();

fireEvent.keyDown(document.activeElement, moveLeftEvent);
expect(thumb.getAttribute('aria-valuenow')).to.equal('-3e-8');
expect(thumb).to.have.attribute('aria-valuenow', '-3e-8');
});
});

Expand Down
4 changes: 1 addition & 3 deletions packages/material-ui/src/test-utils/createMount.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ export default function createMount(options = {}) {
mountWithContext.attachTo = attachTo;
mountWithContext.cleanUp = () => {
ReactDOM.unmountComponentAtNode(attachTo);
if (attachTo.parentNode) {
attachTo.parentNode.removeChild(attachTo);
}
attachTo.parentNode.removeChild(attachTo);
};

return mountWithContext;
Expand Down
7 changes: 0 additions & 7 deletions packages/material-ui/src/test-utils/describeConformance.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,6 @@ const fullSuite = {
export default function describeConformance(minimalElement, getOptions) {
const { only = Object.keys(fullSuite), skip = [] } = getOptions();
describe('Material-UI component API', () => {
after(() => {
const { mount } = getOptions();
if (mount.attachTo) {
ReactDOM.unmountComponentAtNode(mount.attachTo);
}
});

Object.keys(fullSuite)
.filter(testKey => only.indexOf(testKey) !== -1 && skip.indexOf(testKey) === -1)
.forEach(testKey => {
Expand Down

0 comments on commit 311e8d6

Please sign in to comment.