Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] Forward ref behavior #15131

Merged
merged 17 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions packages/material-ui/src/Backdrop/Backdrop.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';
import { assert } from 'chai';
import { createMount, createShallow, getClasses, testRef } from '@material-ui/core/test-utils';
import {
createMount,
createShallow,
describeConformance,
getClasses,
} from '@material-ui/core/test-utils';
import Backdrop from './Backdrop';

describe('<Backdrop />', () => {
Expand All @@ -18,13 +23,15 @@ describe('<Backdrop />', () => {
mount.cleanUp();
});

describeConformance(<Backdrop open />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a backdrop div', () => {
const wrapper = shallow(<Backdrop open className="woofBackdrop" />);
assert.strictEqual(wrapper.childAt(0).hasClass('woofBackdrop'), true);
assert.strictEqual(wrapper.childAt(0).hasClass(classes.root), true);
});

it('does forward refs', () => {
testRef(<Backdrop open />, mount);
});
});
8 changes: 7 additions & 1 deletion packages/material-ui/src/Box/Box.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { assert } from 'chai';
import { createMount } from '@material-ui/core/test-utils';
import { createMount, describeConformance } from '@material-ui/core/test-utils';
import Box from './Box';

describe('<Box />', () => {
Expand All @@ -14,6 +14,12 @@ describe('<Box />', () => {
mount.cleanUp();
});

describeConformance(<Box />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

const testChildren = <div className="unique">Hello World</div>;

it('renders children and box content', () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/material-ui/src/FilledInput/FilledInput.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react';
import { assert } from 'chai';
import { createMount, findOutermostIntrinsic, getClasses } from '@material-ui/core/test-utils';
import {
createMount,
describeConformance,
findOutermostIntrinsic,
getClasses,
} from '@material-ui/core/test-utils';
import FilledInput from './FilledInput';

describe('<FilledInput />', () => {
Expand All @@ -16,6 +21,12 @@ describe('<FilledInput />', () => {
mount.cleanUp();
});

describeConformance(<FilledInput />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a <div />', () => {
const wrapper = mount(<FilledInput />);
const root = findOutermostIntrinsic(wrapper);
Expand Down
15 changes: 14 additions & 1 deletion packages/material-ui/src/Grid/Grid.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,30 @@
import React from 'react';
import { assert } from 'chai';
import { createShallow, getClasses } from '@material-ui/core/test-utils';
import {
createMount,
createShallow,
describeConformance,
getClasses,
} from '@material-ui/core/test-utils';
import Grid from './Grid';

describe('<Grid />', () => {
let mount;
let shallow;
let classes;

before(() => {
mount = createMount();
shallow = createShallow({ dive: true });
classes = getClasses(<Grid />);
});

describeConformance(<Grid />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render', () => {
const wrapper = shallow(<Grid className="woofGrid" />);
assert.strictEqual(wrapper.name(), 'div');
Expand Down
12 changes: 11 additions & 1 deletion packages/material-ui/src/Input/Input.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import { assert } from 'chai';
import { createMount, findOutermostIntrinsic } from '@material-ui/core/test-utils';
import {
createMount,
describeConformance,
findOutermostIntrinsic,
} from '@material-ui/core/test-utils';
import Input from './Input';

describe('<Input />', () => {
Expand All @@ -14,6 +18,12 @@ describe('<Input />', () => {
mount.cleanUp();
});

describeConformance(<Input />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a <div />', () => {
const wrapper = mount(<Input />);
assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div');
Expand Down
19 changes: 10 additions & 9 deletions packages/material-ui/src/Menu/Menu.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { spy } from 'sinon';
import { assert } from 'chai';
import { createMount, getClasses, testRef } from '@material-ui/core/test-utils';
import { createMount, describeConformance, getClasses } from '@material-ui/core/test-utils';
import Popover from '../Popover';
import Menu from './Menu';
import MenuList from '../MenuList';
Expand All @@ -11,13 +11,12 @@ const MENU_LIST_HEIGHT = 100;
describe('<Menu />', () => {
let classes;
let mount;
let defaultProps;
const defaultProps = {
open: false,
anchorEl: () => document.createElement('div'),
};

before(() => {
defaultProps = {
open: false,
anchorEl: document.createElement('div'),
};
classes = getClasses(<Menu {...defaultProps} />);
mount = createMount();
});
Expand All @@ -26,9 +25,11 @@ describe('<Menu />', () => {
mount.cleanUp();
});

it('does forward refs', () => {
testRef(<Menu {...defaultProps} open />, mount);
});
describeConformance(<Menu {...defaultProps} open />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a Popover', () => {
const wrapper = mount(<Menu {...defaultProps} />);
Expand Down
10 changes: 6 additions & 4 deletions packages/material-ui/src/MenuList/MenuList.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { assert } from 'chai';
import { stub } from 'sinon';
import { createMount, testRef } from '@material-ui/core/test-utils';
import { createMount, describeConformance } from '@material-ui/core/test-utils';
import MenuList from './MenuList';
import getScrollbarSize from '../utils/getScrollbarSize';

Expand All @@ -26,9 +26,11 @@ describe('<MenuList />', () => {
mount.cleanUp();
});

it('does forward refs', () => {
testRef(<MenuList />, mount);
});
describeConformance(<MenuList />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLUListElement,
}));

describe('list node', () => {
let wrapper;
Expand Down
21 changes: 13 additions & 8 deletions packages/material-ui/src/NativeSelect/NativeSelectInput.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import React from 'react';
import { assert } from 'chai';
import { spy } from 'sinon';
import { createShallow, createMount } from '@material-ui/core/test-utils';
import MenuItem from '../MenuItem';
import { createShallow, createMount, describeConformance } from '@material-ui/core/test-utils';
import NativeSelectInput from './NativeSelectInput';

describe('<NativeSelectInput />', () => {
Expand All @@ -13,15 +12,15 @@ describe('<NativeSelectInput />', () => {
value: 10,
IconComponent: 'div',
children: [
<MenuItem key={1} value={10}>
<option key={1} value={10}>
Ten
</MenuItem>,
<MenuItem key={2} value={20}>
</option>,
<option key={2} value={20}>
Twenty
</MenuItem>,
<MenuItem key={3} value={30}>
</option>,
<option key={3} value={30}>
Thirty
</MenuItem>,
</option>,
],
};

Expand All @@ -34,6 +33,12 @@ describe('<NativeSelectInput />', () => {
mount.cleanUp();
});

describeConformance(<NativeSelectInput {...defaultProps} onChange={() => {}} />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLSelectElement,
}));

it('should render a native select', () => {
const wrapper = shallow(
<NativeSelectInput {...defaultProps}>
Expand Down
12 changes: 11 additions & 1 deletion packages/material-ui/src/OutlinedInput/OutlinedInput.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import React from 'react';
import { assert } from 'chai';
import { createMount, findOutermostIntrinsic } from '@material-ui/core/test-utils';
import {
createMount,
describeConformance,
findOutermostIntrinsic,
} from '@material-ui/core/test-utils';
import OutlinedInput from './OutlinedInput';
import NotchedOutline from './NotchedOutline';

Expand All @@ -15,6 +19,12 @@ describe('<OutlinedInput />', () => {
mount.cleanUp();
});

describeConformance(<OutlinedInput labelWidth={0} />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a <div />', () => {
const wrapper = mount(<OutlinedInput labelWidth={0} />);
assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div');
Expand Down
16 changes: 11 additions & 5 deletions packages/material-ui/src/Popover/Popover.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PropTypes from 'prop-types';
import {
createShallow,
createMount,
describeConformance,
findOutermostIntrinsic,
getClasses,
} from '@material-ui/core/test-utils';
Expand All @@ -18,7 +19,10 @@ describe('<Popover />', () => {
let shallow;
let mount;
let classes;
let defaultProps;
const defaultProps = {
open: false,
anchorEl: () => document.createElement('div'),
};

before(() => {
shallow = createShallow({ dive: true });
Expand All @@ -28,16 +32,18 @@ describe('<Popover />', () => {
<div />
</Popover>,
);
defaultProps = {
open: false,
anchorEl: document.createElement('div'),
};
});

after(() => {
mount.cleanUp();
});

describeConformance(<Popover {...defaultProps} open />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

describe('root node', () => {
it('should render a Modal with an invisible backdrop as the root node', () => {
const wrapper = mount(
Expand Down
14 changes: 10 additions & 4 deletions packages/material-ui/src/RadioGroup/RadioGroup.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import { assert } from 'chai';
import { spy } from 'sinon';
import { createMount, findOutermostIntrinsic, testRef } from '@material-ui/core/test-utils';
import {
createMount,
describeConformance,
findOutermostIntrinsic,
} from '@material-ui/core/test-utils';
import FormGroup from '../FormGroup';
import Radio from '../Radio';
import RadioGroup from './RadioGroup';
Expand All @@ -22,9 +26,11 @@ describe('<RadioGroup />', () => {
return wrapper.find(`input[value="${value}"]`).first();
}

it('does forward refs', () => {
testRef(<RadioGroup />, mount);
});
describeConformance(<RadioGroup value="" />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a FormGroup with the radiogroup role', () => {
const wrapper = mount(<RadioGroup value="" />);
Expand Down
8 changes: 7 additions & 1 deletion packages/material-ui/src/Select/Select.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { assert } from 'chai';
import { getClasses, createMount } from '@material-ui/core/test-utils';
import { getClasses, createMount, describeConformance } from '@material-ui/core/test-utils';
import MenuItem from '../MenuItem';
import Input from '../Input';
import Select from './Select';
Expand Down Expand Up @@ -31,6 +31,12 @@ describe('<Select />', () => {
mount.cleanUp();
});

describeConformance(<Select {...defaultProps} />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.HTMLDivElement,
}));

it('should render a correct top element', () => {
const wrapper = mount(<Select {...defaultProps} />);
assert.strictEqual(wrapper.find(Input).exists(), true);
Expand Down
8 changes: 7 additions & 1 deletion packages/material-ui/src/StepIcon/StepIcon.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { assert } from 'chai';
import CheckCircle from '../internal/svg-icons/CheckCircle';
import Warning from '../internal/svg-icons/Warning';
import { createShallow, createMount } from '@material-ui/core/test-utils';
import { createShallow, createMount, describeConformance } from '@material-ui/core/test-utils';
import StepIcon from './StepIcon';
import SvgIcon from '../SvgIcon';

Expand All @@ -19,6 +19,12 @@ describe('<StepIcon />', () => {
mount.cleanUp();
});

describeConformance(<StepIcon icon={1} />, () => ({
mount,
only: ['refForwarding'],
refInstanceof: window.SVGSVGElement,
}));

it('renders <CheckCircle> when completed', () => {
const wrapper = mount(<StepIcon icon={1} completed />);
const checkCircle = wrapper.find(CheckCircle);
Expand Down
Loading