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