1 | "use strict";
|
2 |
|
3 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
4 |
|
5 | Object.defineProperty(exports, "__esModule", {
|
6 | value: true
|
7 | });
|
8 | exports.default = describeConformance;
|
9 |
|
10 | var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
11 |
|
12 | var _chai = require("chai");
|
13 |
|
14 | var _react = _interopRequireDefault(require("react"));
|
15 |
|
16 | var _findOutermostIntrinsic = _interopRequireDefault(require("./findOutermostIntrinsic"));
|
17 |
|
18 | var _reactTestRenderer = _interopRequireDefault(require("react-test-renderer"));
|
19 |
|
20 | var _testRef = _interopRequireDefault(require("./testRef"));
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 | function findRootComponent(wrapper, _ref) {
|
40 | var component = _ref.component;
|
41 | var outermostHostElement = (0, _findOutermostIntrinsic.default)(wrapper).getElement();
|
42 | return wrapper.find(component).filterWhere(function (componentWrapper) {
|
43 | return componentWrapper.contains(outermostHostElement);
|
44 | });
|
45 | }
|
46 |
|
47 | function randomStringValue() {
|
48 | return Math.random().toString(36).slice(2);
|
49 | }
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 | function testClassName(element, getOptions) {
|
60 | it('applies the className to the root component', function () {
|
61 | var _getOptions = getOptions(),
|
62 | mount = _getOptions.mount;
|
63 |
|
64 | var className = randomStringValue();
|
65 | var wrapper = mount(_react.default.cloneElement(element, {
|
66 | className: className
|
67 | }));
|
68 |
|
69 | _chai.assert.strictEqual((0, _findOutermostIntrinsic.default)(wrapper).hasClass(className), true, 'does have a custom `className`');
|
70 | });
|
71 | }
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 | function testComponentProp(element, getOptions) {
|
82 | describe('prop: component', function () {
|
83 | it('can render another root component with the `component` prop', function () {
|
84 | var _getOptions2 = getOptions(),
|
85 | classes = _getOptions2.classes,
|
86 | mount = _getOptions2.mount,
|
87 | _getOptions2$testComp = _getOptions2.testComponentPropWith,
|
88 | component = _getOptions2$testComp === void 0 ? 'em' : _getOptions2$testComp;
|
89 |
|
90 | var wrapper = mount(_react.default.cloneElement(element, {
|
91 | component: component
|
92 | }));
|
93 |
|
94 | _chai.assert.strictEqual(findRootComponent(wrapper, {
|
95 | classes: classes,
|
96 | component: component
|
97 | }).exists(), true);
|
98 | });
|
99 | });
|
100 | }
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 |
|
109 |
|
110 | function testPropsSpread(element, getOptions) {
|
111 | it("does spread props to the root component", function () {
|
112 |
|
113 | var _getOptions3 = getOptions(),
|
114 | classes = _getOptions3.classes,
|
115 | inheritComponent = _getOptions3.inheritComponent,
|
116 | mount = _getOptions3.mount;
|
117 |
|
118 | var testProp = 'data-test-props-spread';
|
119 | var value = randomStringValue();
|
120 | var wrapper = mount(_react.default.cloneElement(element, (0, _defineProperty2.default)({}, testProp, value)));
|
121 | var root = findRootComponent(wrapper, {
|
122 | classes: classes,
|
123 | component: inheritComponent
|
124 | });
|
125 |
|
126 | _chai.assert.strictEqual(root.props()[testProp], value);
|
127 | });
|
128 | }
|
129 |
|
130 |
|
131 |
|
132 |
|
133 |
|
134 |
|
135 |
|
136 |
|
137 |
|
138 |
|
139 |
|
140 | function describeRef(element, getOptions) {
|
141 | describe('ref', function () {
|
142 | it("attaches the ref", function () {
|
143 |
|
144 | var _getOptions4 = getOptions(),
|
145 | inheritComponent = _getOptions4.inheritComponent,
|
146 | mount = _getOptions4.mount,
|
147 | refInstanceof = _getOptions4.refInstanceof;
|
148 |
|
149 | (0, _testRef.default)(element, mount, function (instance, wrapper) {
|
150 | _chai.assert.instanceOf(instance, refInstanceof);
|
151 |
|
152 | if (inheritComponent && instance instanceof window.Element) {
|
153 | var rootHost = (0, _findOutermostIntrinsic.default)(wrapper);
|
154 |
|
155 | _chai.assert.strictEqual(instance, rootHost.instance());
|
156 | }
|
157 | });
|
158 | });
|
159 | });
|
160 | }
|
161 |
|
162 |
|
163 |
|
164 |
|
165 |
|
166 |
|
167 |
|
168 |
|
169 | function testRootClass(element, getOptions) {
|
170 | it('applies to root class to the root component if it has this class', function () {
|
171 | var _getOptions5 = getOptions(),
|
172 | classes = _getOptions5.classes,
|
173 | mount = _getOptions5.mount;
|
174 |
|
175 | if (classes.root == null) {
|
176 | return;
|
177 | }
|
178 |
|
179 | var className = randomStringValue();
|
180 | var wrapper = mount(_react.default.cloneElement(element, {
|
181 | className: className
|
182 | }));
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | _chai.assert.strictEqual((0, _findOutermostIntrinsic.default)(wrapper).hasClass(classes.root), true);
|
188 |
|
189 | _chai.assert.strictEqual((0, _findOutermostIntrinsic.default)(wrapper).hasClass(className), true);
|
190 | });
|
191 | }
|
192 |
|
193 |
|
194 |
|
195 |
|
196 |
|
197 |
|
198 |
|
199 |
|
200 | function testReactTestRenderer(element) {
|
201 | it('should render without errors in ReactTestRenderer', function () {
|
202 | _reactTestRenderer.default.act(function () {
|
203 | _reactTestRenderer.default.create(element, {
|
204 | createNodeMock: function createNodeMock(node) {
|
205 | return document.createElement(node.type);
|
206 | }
|
207 | });
|
208 | });
|
209 | });
|
210 | }
|
211 |
|
212 | var fullSuite = {
|
213 | componentProp: testComponentProp,
|
214 | mergeClassName: testClassName,
|
215 | propsSpread: testPropsSpread,
|
216 | refForwarding: describeRef,
|
217 | rootClass: testRootClass,
|
218 | reactTestRenderer: testReactTestRenderer
|
219 | };
|
220 |
|
221 |
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 |
|
228 |
|
229 |
|
230 |
|
231 |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 |
|
237 |
|
238 |
|
239 |
|
240 | function describeConformance(minimalElement, getOptions) {
|
241 | var _getOptions6 = getOptions(),
|
242 | _getOptions6$after = _getOptions6.after,
|
243 | runAfterHook = _getOptions6$after === void 0 ? function () {} : _getOptions6$after,
|
244 | _getOptions6$only = _getOptions6.only,
|
245 | only = _getOptions6$only === void 0 ? Object.keys(fullSuite) : _getOptions6$only,
|
246 | _getOptions6$skip = _getOptions6.skip,
|
247 | skip = _getOptions6$skip === void 0 ? [] : _getOptions6$skip;
|
248 |
|
249 | describe('Material-UI component API', function () {
|
250 | after(runAfterHook);
|
251 | Object.keys(fullSuite).filter(function (testKey) {
|
252 | return only.indexOf(testKey) !== -1 && skip.indexOf(testKey) === -1;
|
253 | }).forEach(function (testKey) {
|
254 | var test = fullSuite[testKey];
|
255 | test(minimalElement, getOptions);
|
256 | });
|
257 | });
|
258 | } |
\ | No newline at end of file |