From 306a55d793cc98c091caadffdc17802f4d7077a7 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Tue, 26 Mar 2019 21:56:14 +0100 Subject: [PATCH 01/17] [test] Add `only` option to whitelist tests --- .../src/test-utils/describeConformance.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/material-ui/src/test-utils/describeConformance.js b/packages/material-ui/src/test-utils/describeConformance.js index 8ca3526b1b5af0..67d5a9e7e3cfba 100644 --- a/packages/material-ui/src/test-utils/describeConformance.js +++ b/packages/material-ui/src/test-utils/describeConformance.js @@ -119,6 +119,7 @@ const fullSuite = { * @property {string} classes - `classes` of the component provided by `@material-ui/styles` * @property {string} inheritComponent - The element type that receives spread props. * @property {function} mount - Should be a return value from createMount + * @property {string[]?} only - If specified only run the tests listed * @property {boolean} refInstanceof - `ref` will be an instanceof this constructor. * @property {string?} testComponentPropWith - The host component that should be rendered instead. */ @@ -132,10 +133,13 @@ const fullSuite = { * */ export default function describeConformance(minimalElement, getOptions) { + const { only = Object.keys(fullSuite) } = getOptions(); describe('Material-UI component API', () => { - Object.keys(fullSuite).forEach(testKey => { - const test = fullSuite[testKey]; - test(minimalElement, getOptions); - }); + Object.keys(fullSuite) + .filter(testKey => only.indexOf(testKey) !== -1) + .forEach(testKey => { + const test = fullSuite[testKey]; + test(minimalElement, getOptions); + }); }); } From 98bb08a085cf131053596459056e9dba8f5d8b54 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:00:09 +0200 Subject: [PATCH 02/17] [test] Add skip option to describeConformance --- packages/material-ui/src/test-utils/describeConformance.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/material-ui/src/test-utils/describeConformance.js b/packages/material-ui/src/test-utils/describeConformance.js index 67d5a9e7e3cfba..0366cf28134189 100644 --- a/packages/material-ui/src/test-utils/describeConformance.js +++ b/packages/material-ui/src/test-utils/describeConformance.js @@ -121,6 +121,7 @@ const fullSuite = { * @property {function} mount - Should be a return value from createMount * @property {string[]?} only - If specified only run the tests listed * @property {boolean} refInstanceof - `ref` will be an instanceof this constructor. + * @property {string[]?} skip - Skip the specified tests * @property {string?} testComponentPropWith - The host component that should be rendered instead. */ @@ -133,10 +134,10 @@ const fullSuite = { * */ export default function describeConformance(minimalElement, getOptions) { - const { only = Object.keys(fullSuite) } = getOptions(); + const { only = Object.keys(fullSuite), skip = [] } = getOptions(); describe('Material-UI component API', () => { Object.keys(fullSuite) - .filter(testKey => only.indexOf(testKey) !== -1) + .filter(testKey => only.indexOf(testKey) !== -1 && skip.indexOf(testKey) === -1) .forEach(testKey => { const test = fullSuite[testKey]; test(minimalElement, getOptions); From 24c40d3825e088296b937719d75a9dd4d760cd41 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:08:03 +0200 Subject: [PATCH 03/17] [Backdrop] Use describeConformance for ref forward test --- .../material-ui/src/Backdrop/Backdrop.test.js | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/material-ui/src/Backdrop/Backdrop.test.js b/packages/material-ui/src/Backdrop/Backdrop.test.js index a003a341df6b7b..6abd4f5d2cc293 100644 --- a/packages/material-ui/src/Backdrop/Backdrop.test.js +++ b/packages/material-ui/src/Backdrop/Backdrop.test.js @@ -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('', () => { @@ -18,13 +23,15 @@ describe('', () => { mount.cleanUp(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render a backdrop div', () => { const wrapper = shallow(); assert.strictEqual(wrapper.childAt(0).hasClass('woofBackdrop'), true); assert.strictEqual(wrapper.childAt(0).hasClass(classes.root), true); }); - - it('does forward refs', () => { - testRef(, mount); - }); }); From 205ab5ff33666a42dfecb5d3625a7d1c2d0eebc1 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:09:41 +0200 Subject: [PATCH 04/17] [Box] Test ref forwarding --- packages/material-ui/src/Box/Box.test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/Box/Box.test.js b/packages/material-ui/src/Box/Box.test.js index c675885fccc827..66bc21415cf059 100644 --- a/packages/material-ui/src/Box/Box.test.js +++ b/packages/material-ui/src/Box/Box.test.js @@ -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('', () => { @@ -14,6 +14,12 @@ describe('', () => { mount.cleanUp(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + const testChildren =
Hello World
; it('renders children and box content', () => { From fd82f659b5dc860dc168920ce9f23c1731b8d58c Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:12:53 +0200 Subject: [PATCH 05/17] [FilledInput] Test ref forwarding --- .../material-ui/src/FilledInput/FilledInput.test.js | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/FilledInput/FilledInput.test.js b/packages/material-ui/src/FilledInput/FilledInput.test.js index 867accc42e48b7..3a6e50e62ba474 100644 --- a/packages/material-ui/src/FilledInput/FilledInput.test.js +++ b/packages/material-ui/src/FilledInput/FilledInput.test.js @@ -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('', () => { @@ -16,6 +21,12 @@ describe('', () => { mount.cleanUp(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render a
', () => { const wrapper = mount(); const root = findOutermostIntrinsic(wrapper); From 60f7f546a0bec0cb11e50af19bfed0df385a8fda Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:14:23 +0200 Subject: [PATCH 06/17] [Grid] Test ref forwarding --- packages/material-ui/src/Grid/Grid.test.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/Grid/Grid.test.js b/packages/material-ui/src/Grid/Grid.test.js index 36ecb20fb70e4a..902e11f6682712 100644 --- a/packages/material-ui/src/Grid/Grid.test.js +++ b/packages/material-ui/src/Grid/Grid.test.js @@ -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('', () => { + let mount; let shallow; let classes; before(() => { + mount = createMount(); shallow = createShallow({ dive: true }); classes = getClasses(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render', () => { const wrapper = shallow(); assert.strictEqual(wrapper.name(), 'div'); From 4c7c931e3d9141f097ba5527938249ad6beb4bb8 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:15:43 +0200 Subject: [PATCH 07/17] [Input] Test ref forwarding --- packages/material-ui/src/Input/Input.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/Input/Input.test.js b/packages/material-ui/src/Input/Input.test.js index a4fdddbc35f33a..5a2be386aeaca3 100644 --- a/packages/material-ui/src/Input/Input.test.js +++ b/packages/material-ui/src/Input/Input.test.js @@ -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('', () => { @@ -14,6 +18,12 @@ describe('', () => { mount.cleanUp(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render a
', () => { const wrapper = mount(); assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div'); From 978757f06c3383c0b80f22f373c42c4af6ccd1b8 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:24:26 +0200 Subject: [PATCH 08/17] [Menu] Use describeConformance for testRef --- packages/material-ui/src/Menu/Menu.test.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/packages/material-ui/src/Menu/Menu.test.js b/packages/material-ui/src/Menu/Menu.test.js index e5dfeea7a735c4..65ad22fedefee7 100644 --- a/packages/material-ui/src/Menu/Menu.test.js +++ b/packages/material-ui/src/Menu/Menu.test.js @@ -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'; @@ -11,13 +11,12 @@ const MENU_LIST_HEIGHT = 100; describe('', () => { let classes; let mount; - let defaultProps; + const defaultProps = { + open: false, + anchorEl: () => document.createElement('div'), + }; before(() => { - defaultProps = { - open: false, - anchorEl: document.createElement('div'), - }; classes = getClasses(); mount = createMount(); }); @@ -26,9 +25,11 @@ describe('', () => { mount.cleanUp(); }); - it('does forward refs', () => { - testRef(, mount); - }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); it('should render a Popover', () => { const wrapper = mount(); From 289e75de2cee3646a61615130eb17ad549d2394f Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 19:33:53 +0200 Subject: [PATCH 09/17] [MenuList] Use describeConformance for testRef --- packages/material-ui/src/MenuList/MenuList.test.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/material-ui/src/MenuList/MenuList.test.js b/packages/material-ui/src/MenuList/MenuList.test.js index 529f4858fd966c..c355dc50e5e5f1 100644 --- a/packages/material-ui/src/MenuList/MenuList.test.js +++ b/packages/material-ui/src/MenuList/MenuList.test.js @@ -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'; @@ -26,9 +26,11 @@ describe('', () => { mount.cleanUp(); }); - it('does forward refs', () => { - testRef(, mount); - }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLUListElement, + })); describe('list node', () => { let wrapper; From 9f3acb23ae1373fae0c29d46034a98d68780d438 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 20:22:53 +0200 Subject: [PATCH 10/17] [NativeSelectInput] Test ref forwarding --- .../NativeSelect/NativeSelectInput.test.js | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js b/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js index b10253c8f0da26..725c8ca1dcaec0 100644 --- a/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js +++ b/packages/material-ui/src/NativeSelect/NativeSelectInput.test.js @@ -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('', () => { @@ -13,15 +12,15 @@ describe('', () => { value: 10, IconComponent: 'div', children: [ - + , - + , + , - + , + , + , ], }; @@ -34,6 +33,12 @@ describe('', () => { mount.cleanUp(); }); + describeConformance( {}} />, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLSelectElement, + })); + it('should render a native select', () => { const wrapper = shallow( From c58e4b164bf43491aab6c4eb00ee065a28e071f6 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 20:24:06 +0200 Subject: [PATCH 11/17] [OutlinedInput] Test ref forwarding --- .../src/OutlinedInput/OutlinedInput.test.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/OutlinedInput/OutlinedInput.test.js b/packages/material-ui/src/OutlinedInput/OutlinedInput.test.js index a00f2ff3bf93c3..9ec17e1b7cdfae 100644 --- a/packages/material-ui/src/OutlinedInput/OutlinedInput.test.js +++ b/packages/material-ui/src/OutlinedInput/OutlinedInput.test.js @@ -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'; @@ -15,6 +19,12 @@ describe('', () => { mount.cleanUp(); }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render a
', () => { const wrapper = mount(); assert.strictEqual(findOutermostIntrinsic(wrapper).type(), 'div'); From 4b45099dbd24976c6f75b2b84e92562a425463c6 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 20:26:12 +0200 Subject: [PATCH 12/17] [Popover] Test ref forwarding --- packages/material-ui/src/Popover/Popover.test.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/material-ui/src/Popover/Popover.test.js b/packages/material-ui/src/Popover/Popover.test.js index 62194e28ef4d0d..70054c15404145 100644 --- a/packages/material-ui/src/Popover/Popover.test.js +++ b/packages/material-ui/src/Popover/Popover.test.js @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; import { createShallow, createMount, + describeConformance, findOutermostIntrinsic, getClasses, } from '@material-ui/core/test-utils'; @@ -18,7 +19,10 @@ describe('', () => { let shallow; let mount; let classes; - let defaultProps; + const defaultProps = { + open: false, + anchorEl: () => document.createElement('div'), + }; before(() => { shallow = createShallow({ dive: true }); @@ -28,16 +32,18 @@ describe('', () => {
, ); - defaultProps = { - open: false, - anchorEl: document.createElement('div'), - }; }); after(() => { mount.cleanUp(); }); + describeConformance(, () => ({ + 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( From 5fa6030bd7e06a43b4e420c9bda18236f1a00931 Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 20:40:02 +0200 Subject: [PATCH 13/17] [RadioGroup] Use describeConformance for testRef --- .../material-ui/src/RadioGroup/RadioGroup.test.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/material-ui/src/RadioGroup/RadioGroup.test.js b/packages/material-ui/src/RadioGroup/RadioGroup.test.js index 0e9818bc5fb0b3..7be00c2e405cc9 100644 --- a/packages/material-ui/src/RadioGroup/RadioGroup.test.js +++ b/packages/material-ui/src/RadioGroup/RadioGroup.test.js @@ -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'; @@ -22,9 +26,11 @@ describe('', () => { return wrapper.find(`input[value="${value}"]`).first(); } - it('does forward refs', () => { - testRef(, mount); - }); + describeConformance(, () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); it('should render a FormGroup with the radiogroup role', () => { const wrapper = mount(); From 691771b41ef907c9aebc9f455bc4b32ee1011b9d Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Sun, 31 Mar 2019 20:41:03 +0200 Subject: [PATCH 14/17] [Select] Test ref forwarding --- packages/material-ui/src/Select/Select.test.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/material-ui/src/Select/Select.test.js b/packages/material-ui/src/Select/Select.test.js index dbea6e46cd0584..cd6fd8390ddf40 100644 --- a/packages/material-ui/src/Select/Select.test.js +++ b/packages/material-ui/src/Select/Select.test.js @@ -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'; @@ -31,6 +31,12 @@ describe(', () => ({ + mount, + only: ['refForwarding'], + refInstanceof: window.HTMLDivElement, + })); + it('should render a correct top element', () => { const wrapper = mount(