@khanacademy/wonder-blocks-testing 7.1.4 → 7.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js DELETED
@@ -1,1285 +0,0 @@
1
- module.exports =
2
- /******/ (function(modules) { // webpackBootstrap
3
- /******/ // The module cache
4
- /******/ var installedModules = {};
5
- /******/
6
- /******/ // The require function
7
- /******/ function __webpack_require__(moduleId) {
8
- /******/
9
- /******/ // Check if module is in cache
10
- /******/ if(installedModules[moduleId]) {
11
- /******/ return installedModules[moduleId].exports;
12
- /******/ }
13
- /******/ // Create a new module (and put it into the cache)
14
- /******/ var module = installedModules[moduleId] = {
15
- /******/ i: moduleId,
16
- /******/ l: false,
17
- /******/ exports: {}
18
- /******/ };
19
- /******/
20
- /******/ // Execute the module function
21
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
22
- /******/
23
- /******/ // Flag the module as loaded
24
- /******/ module.l = true;
25
- /******/
26
- /******/ // Return the exports of the module
27
- /******/ return module.exports;
28
- /******/ }
29
- /******/
30
- /******/
31
- /******/ // expose the modules object (__webpack_modules__)
32
- /******/ __webpack_require__.m = modules;
33
- /******/
34
- /******/ // expose the module cache
35
- /******/ __webpack_require__.c = installedModules;
36
- /******/
37
- /******/ // define getter function for harmony exports
38
- /******/ __webpack_require__.d = function(exports, name, getter) {
39
- /******/ if(!__webpack_require__.o(exports, name)) {
40
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
41
- /******/ }
42
- /******/ };
43
- /******/
44
- /******/ // define __esModule on exports
45
- /******/ __webpack_require__.r = function(exports) {
46
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
47
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
48
- /******/ }
49
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
50
- /******/ };
51
- /******/
52
- /******/ // create a fake namespace object
53
- /******/ // mode & 1: value is a module id, require it
54
- /******/ // mode & 2: merge all properties of value into the ns
55
- /******/ // mode & 4: return value when already ns object
56
- /******/ // mode & 8|1: behave like require
57
- /******/ __webpack_require__.t = function(value, mode) {
58
- /******/ if(mode & 1) value = __webpack_require__(value);
59
- /******/ if(mode & 8) return value;
60
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
61
- /******/ var ns = Object.create(null);
62
- /******/ __webpack_require__.r(ns);
63
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
64
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
65
- /******/ return ns;
66
- /******/ };
67
- /******/
68
- /******/ // getDefaultExport function for compatibility with non-harmony modules
69
- /******/ __webpack_require__.n = function(module) {
70
- /******/ var getter = module && module.__esModule ?
71
- /******/ function getDefault() { return module['default']; } :
72
- /******/ function getModuleExports() { return module; };
73
- /******/ __webpack_require__.d(getter, 'a', getter);
74
- /******/ return getter;
75
- /******/ };
76
- /******/
77
- /******/ // Object.prototype.hasOwnProperty.call
78
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
79
- /******/
80
- /******/ // __webpack_public_path__
81
- /******/ __webpack_require__.p = "";
82
- /******/
83
- /******/
84
- /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 28);
86
- /******/ })
87
- /************************************************************************/
88
- /******/ ([
89
- /* 0 */
90
- /***/ (function(module, exports) {
91
-
92
- module.exports = require("react");
93
-
94
- /***/ }),
95
- /* 1 */
96
- /***/ (function(module, exports) {
97
-
98
- function _classPrivateFieldBase(receiver, privateKey) {
99
- if (!Object.prototype.hasOwnProperty.call(receiver, privateKey)) {
100
- throw new TypeError("attempted to use private field on non-instance");
101
- }
102
-
103
- return receiver;
104
- }
105
-
106
- module.exports = _classPrivateFieldBase, module.exports.__esModule = true, module.exports["default"] = module.exports;
107
-
108
- /***/ }),
109
- /* 2 */
110
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
111
-
112
- "use strict";
113
- __webpack_require__.r(__webpack_exports__);
114
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DefaultAdapters", function() { return DefaultAdapters; });
115
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "DefaultConfigs", function() { return DefaultConfigs; });
116
- /* harmony import */ var _css_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(10);
117
- /* harmony import */ var _data_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(11);
118
- /* harmony import */ var _portal_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(12);
119
- /* harmony import */ var _router_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(13);
120
-
121
-
122
-
123
-
124
-
125
- /**
126
- * NOTE: We do not type `DefaultAdapters` with `Adapters` here because we want
127
- * the individual config types of each adapter to remain intact rather than
128
- * getting changed to `any`.
129
- */
130
-
131
- /**
132
- * The default adapters provided by Wonder Blocks.
133
- */
134
- const DefaultAdapters = {
135
- css: _css_js__WEBPACK_IMPORTED_MODULE_0__[/* adapter */ "a"],
136
- data: _data_js__WEBPACK_IMPORTED_MODULE_1__[/* adapter */ "a"],
137
- portal: _portal_js__WEBPACK_IMPORTED_MODULE_2__[/* adapter */ "a"],
138
- router: _router_js__WEBPACK_IMPORTED_MODULE_3__[/* adapter */ "a"]
139
- };
140
- /**
141
- * The default configurations to use with the `DefaultAdapters`.
142
- */
143
-
144
- const DefaultConfigs = {
145
- css: _css_js__WEBPACK_IMPORTED_MODULE_0__[/* defaultConfig */ "b"],
146
- data: _data_js__WEBPACK_IMPORTED_MODULE_1__[/* defaultConfig */ "b"],
147
- portal: _portal_js__WEBPACK_IMPORTED_MODULE_2__[/* defaultConfig */ "b"],
148
- router: _router_js__WEBPACK_IMPORTED_MODULE_3__[/* defaultConfig */ "b"]
149
- };
150
-
151
- /***/ }),
152
- /* 3 */
153
- /***/ (function(module, exports) {
154
-
155
- module.exports = require("react-router-dom");
156
-
157
- /***/ }),
158
- /* 4 */
159
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
160
-
161
- "use strict";
162
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return makeTestHarness; });
163
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(26);
164
- /* harmony import */ var _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0__);
165
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(0);
166
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_1__);
167
- /* harmony import */ var _render_adapters_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(27);
168
-
169
-
170
-
171
-
172
- /**
173
- * Create a test harness method for use with React components.
174
- *
175
- * This returns a test harness method that applies the default configurations
176
- * to the given adapters, wrapping a given component.
177
- *
178
- * @param {TAdapters} adapters All the adapters to be supported by the returned
179
- * test harness.
180
- * @param {Configs<TAdapters>} defaultConfigs Default configuration values for
181
- * the adapters.
182
- * @returns {<-TProps, +Instance = mixed>(
183
- * Component: React.AbstractComponent<TProps, Instance>,
184
- * configs?: $Shape<Configs<TAdapters>>,
185
- * ) => React.AbstractComponent<TProps, Instance>} A test harness.
186
- */
187
- const makeTestHarness = (adapters, defaultConfigs) => {
188
- /**
189
- * Create a harnessed version of the given component.
190
- *
191
- * @param {React.AbstractComponent<TProps, Instance>} component The
192
- * component to be wrapped.
193
- * @param {$Shape<Configs<TAdapters>>} [configs] Any adapter
194
- * configuration that you want to override from the `defaultConfigs` values.
195
- */
196
- return (Component, configs) => {
197
- /**
198
- * $FlowIgnore[cannot-spread-indexer]
199
- * We know `configs` may overwrite `DefaultConfigs` and we're ok with it.
200
- * The interface definition handles the typing for us so we're ok
201
- * with it not being inferred here.
202
- */
203
- const fullConfig = { ...defaultConfigs,
204
- ...configs
205
- };
206
- const harnessedComponent = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["forwardRef"]((props, ref) => Object(_render_adapters_js__WEBPACK_IMPORTED_MODULE_2__[/* renderAdapters */ "a"])(adapters, fullConfig, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_1__["createElement"](Component, _babel_runtime_helpers_extends__WEBPACK_IMPORTED_MODULE_0___default()({}, props, {
207
- ref: ref
208
- })))); // We add a name for the component here so that we can detect that
209
- // later and also see it in traces and what have you.
210
-
211
- harnessedComponent.displayName = `testHarness(${Component.displayName || Component.name || "Component"})`;
212
- return harnessedComponent;
213
- };
214
- };
215
-
216
- /***/ }),
217
- /* 5 */
218
- /***/ (function(module, exports) {
219
-
220
- var id = 0;
221
-
222
- function _classPrivateFieldKey(name) {
223
- return "__private_" + id++ + "_" + name;
224
- }
225
-
226
- module.exports = _classPrivateFieldKey, module.exports.__esModule = true, module.exports["default"] = module.exports;
227
-
228
- /***/ }),
229
- /* 6 */
230
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
231
-
232
- "use strict";
233
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return makeHookHarness; });
234
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
235
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
236
- /* harmony import */ var _make_test_harness_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
237
-
238
-
239
-
240
- const HookHarness = ({
241
- children
242
- }) => children;
243
- /**
244
- * Create a test harness method for use with React hooks.
245
- *
246
- * This returns a test harness method that applies the default configurations
247
- * to the given adapters, wrapping a given component.
248
- *
249
- * @param {TAdapters} adapters All the adapters to be supported by the returned
250
- * test harness.
251
- * @param {TestHarnessConfigs<TAdapters>} defaultConfigs Default configuration values for
252
- * the adapters.
253
- * @returns {(
254
- * configs?: $Shape<TestHarnessConfigs<TAdapters>>,
255
- * ) => React.AbstractComponent<any, any>} A test harness.
256
- */
257
-
258
-
259
- const makeHookHarness = (adapters, defaultConfigs) => {
260
- const testHarness = Object(_make_test_harness_js__WEBPACK_IMPORTED_MODULE_1__[/* makeTestHarness */ "a"])(adapters, defaultConfigs);
261
- /**
262
- * Create a harness to use as a wrapper when rendering hooks.
263
- *
264
- * @param {$Shape<Configs<typeof DefaultAdapters>>} [configs] Any adapter
265
- * configuration that you want to override from the DefaultConfigs values.
266
- */
267
-
268
- return configs => testHarness(HookHarness, configs);
269
- };
270
-
271
- /***/ }),
272
- /* 7 */
273
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
274
-
275
- "use strict";
276
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockRequester; });
277
- /**
278
- * A generic mock request function for using when mocking fetch or gqlFetch.
279
- */
280
- const mockRequester = (operationMatcher, operationToString) => {
281
- // We want this to work in jest and in fixtures to make life easy for folks.
282
- // This is the array of mocked operations that we will traverse and
283
- // manipulate.
284
- const mocks = []; // What we return has to be a drop in for the fetch function that is
285
- // provided to `GqlRouter` which is how folks will then use this mock.
286
-
287
- const mockFn = (...args) => {
288
- // Iterate our mocked operations and find the first one that matches.
289
- for (const mock of mocks) {
290
- if (mock.onceOnly && mock.used) {
291
- // This is a once-only mock and it has been used, so skip it.
292
- continue;
293
- }
294
-
295
- if (operationMatcher.apply(void 0, [mock.operation].concat(args))) {
296
- mock.used = true;
297
- return mock.response();
298
- }
299
- } // Default is to reject with some helpful info on what request
300
- // we rejected.
301
-
302
-
303
- return Promise.reject(new Error(`No matching mock response found for request:
304
- ${operationToString.apply(void 0, args)}`));
305
- };
306
-
307
- const addMockedOperation = (operation, response, onceOnly) => {
308
- const mockResponse = () => response.toPromise();
309
-
310
- mocks.push({
311
- operation,
312
- response: mockResponse,
313
- onceOnly,
314
- used: false
315
- });
316
- return mockFn;
317
- };
318
-
319
- mockFn.mockOperation = (operation, response) => addMockedOperation(operation, response, false);
320
-
321
- mockFn.mockOperationOnce = (operation, response) => addMockedOperation(operation, response, true);
322
-
323
- return mockFn;
324
- };
325
-
326
- /***/ }),
327
- /* 8 */
328
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
329
-
330
- "use strict";
331
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SettleSignal; });
332
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
333
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0__);
334
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
335
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1__);
336
-
337
-
338
-
339
- var _settled = /*#__PURE__*/_babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1___default()("settled");
340
-
341
- /**
342
- * A signal for controlling the `RespondWith` API responses.
343
- *
344
- * This provide finely-grained control over the promise lifecycle to support
345
- * complex test scenarios.
346
- */
347
- class SettleSignal extends EventTarget {
348
- constructor(setSettleFn = null) {
349
- super(); // If we were given a function, we call it with a method that will
350
- // settle ourselves. This allows the appropriate SettleController
351
- // to be in charge of settling this instance.
352
-
353
- Object.defineProperty(this, _settled, {
354
- writable: true,
355
- value: false
356
- });
357
- setSettleFn == null ? void 0 : setSettleFn(() => {
358
- if (_babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _settled)[_settled]) {
359
- throw new Error("SettleSignal already settled");
360
- }
361
-
362
- _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _settled)[_settled] = true;
363
- this.dispatchEvent(new Event("settled"));
364
- });
365
- }
366
- /**
367
- * An already settled signal.
368
- */
369
-
370
-
371
- static settle() {
372
- const signal = new SettleSignal();
373
- _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(signal, _settled)[_settled] = true;
374
- return signal;
375
- }
376
- /**
377
- * Has this signal been settled yet?
378
- */
379
-
380
-
381
- get settled() {
382
- return _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _settled)[_settled];
383
- }
384
-
385
- }
386
-
387
- /***/ }),
388
- /* 9 */
389
- /***/ (function(module, exports) {
390
-
391
- module.exports = require("@storybook/addon-actions");
392
-
393
- /***/ }),
394
- /* 10 */
395
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
396
-
397
- "use strict";
398
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return defaultConfig; });
399
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return adapter; });
400
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
401
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
402
-
403
- // The default configuration is to omit this adapter.
404
- const defaultConfig = null;
405
-
406
- const normalizeConfig = config => {
407
- if (typeof config === "string") {
408
- return {
409
- classes: [config],
410
- style: {}
411
- };
412
- }
413
-
414
- if (Array.isArray(config)) {
415
- return {
416
- classes: config,
417
- style: {}
418
- };
419
- }
420
-
421
- if (typeof config === "object") {
422
- if (config.classes != null && config.style != null) {
423
- // This is a heuristic check and by nature isn't perfect.
424
- // So we have to tell flow to just accept it.
425
- // $FlowIgnore[prop-missing]
426
- return config;
427
- } // Again, since the previous check is heuristic, so is this outcome
428
- // and so we still have to assure flow everything is OK.
429
- // $FlowIgnore[prop-missing]
430
-
431
-
432
- return {
433
- classes: [],
434
- style: config
435
- };
436
- }
437
-
438
- throw new Error(`Invalid config: ${config}`);
439
- };
440
- /**
441
- * Test harness adapter for adding CSS to the harnessed component wrapper.
442
- */
443
-
444
-
445
- const adapter = (children, config) => {
446
- const {
447
- classes,
448
- style
449
- } = normalizeConfig(config);
450
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"]("div", {
451
- "data-test-id": "css-adapter-container",
452
- className: classes.join(" "),
453
- style: style
454
- }, children);
455
- };
456
-
457
- /***/ }),
458
- /* 11 */
459
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
460
-
461
- "use strict";
462
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return defaultConfig; });
463
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return adapter; });
464
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
465
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
466
- /* harmony import */ var _khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(25);
467
- /* harmony import */ var _khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__);
468
-
469
-
470
-
471
- /**
472
- * Default configuration for the Wonder Blocks Data adapter.
473
- */
474
- const defaultConfig = [];
475
- /**
476
- * Test harness adapter to mock Wonder Blocks Data usage.
477
- *
478
- * NOTE: Consumers are responsible for properly defining their intercepts.
479
- * This component does not validate the configuration to ensure interceptors
480
- * are not overriding one another.
481
- */
482
-
483
- const adapter = (children, config) => {
484
- // First we render the cache intercepts.
485
- let currentChildren = children;
486
- const interceptors = Array.isArray(config) ? config : [config]; // Then we render the data intercepts.
487
-
488
- for (const interceptor of interceptors) {
489
- currentChildren = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_data__WEBPACK_IMPORTED_MODULE_1__["InterceptRequests"], {
490
- interceptor: interceptor
491
- }, currentChildren);
492
- }
493
- /**
494
- * `currentChildren` is a `React.Node` but we need it to be a
495
- * `React.Element<>`. Return it rendered in a fragment allows us to do
496
- * that.
497
- */
498
-
499
-
500
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, currentChildren);
501
- };
502
-
503
- /***/ }),
504
- /* 12 */
505
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
506
-
507
- "use strict";
508
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return defaultConfig; });
509
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return adapter; });
510
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
511
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
512
-
513
- // The default configuration is to omit this adapter.
514
- const defaultConfig = null;
515
- /**
516
- * Test harness adapter for supporting portals.
517
- *
518
- * Some components rely on rendering with a React Portal. This adapter ensures
519
- * that the DOM contains a mounting point for the portal with the expected
520
- * identifier.
521
- */
522
-
523
- const adapter = (children, config) => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react__WEBPACK_IMPORTED_MODULE_0__["Fragment"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"]("div", {
524
- id: config,
525
- "data-test-id": config
526
- }), children);
527
-
528
- /***/ }),
529
- /* 13 */
530
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
531
-
532
- "use strict";
533
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "b", function() { return defaultConfig; });
534
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return adapter; });
535
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
536
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
537
- /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(3);
538
- /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_1__);
539
-
540
-
541
-
542
- /**
543
- * The default configuration for this adapter.
544
- */
545
- const defaultConfig = {
546
- location: "/"
547
- };
548
-
549
- const maybeWithRoute = (children, path) => {
550
- if (path == null) {
551
- return children;
552
- }
553
-
554
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["Switch"], null, /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["Route"], {
555
- exact: true,
556
- path: path
557
- }, children), /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["Route"], {
558
- path: "*",
559
- render: () => {
560
- throw new Error("The configured path must match the configured location or your harnessed component will not render.");
561
- }
562
- }));
563
- };
564
- /**
565
- * Adapter that sets up a router and AppShell location-specific contexts.
566
- *
567
- * This allows you to ensure that components are being tested in the
568
- * AppShell world.
569
- *
570
- * NOTE(somewhatabstract): The AppShell component itself already does
571
- * the work of setting up routing and the AppShellContext and so using this
572
- * adapter with the App component will have zero-effect since AppShell will
573
- * override it.
574
- */
575
-
576
-
577
- const adapter = (children, config) => {
578
- if (typeof config === "string") {
579
- config = {
580
- location: config
581
- };
582
- } // Wrap children with the various contexts and routes, as per the config.
583
-
584
-
585
- const wrappedWithRoute = maybeWithRoute(children, config.path);
586
-
587
- if (config.forceStatic) {
588
- /**
589
- * There may be times (SSR testing comes to mind) where we will be
590
- * really strict about not permitting client-side navigation events.
591
- */
592
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["StaticRouter"], {
593
- location: config.location,
594
- context: {}
595
- }, wrappedWithRoute);
596
- }
597
- /**
598
- * OK, we must be OK with a memory router.
599
- *
600
- * There are two flavors of config for this. The easy one with just a
601
- * location, and the complex one for those gnarlier setups.
602
- *
603
- * First, the easy one.
604
- */
605
-
606
-
607
- if (typeof config.location !== "undefined") {
608
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["MemoryRouter"], {
609
- initialEntries: [config.location]
610
- }, wrappedWithRoute);
611
- }
612
- /**
613
- * If it's not the easy one, it should be the complex one.
614
- * Let's make sure we have good data (also keeps flow happy).
615
- */
616
-
617
-
618
- if (typeof config.initialEntries === "undefined") {
619
- throw new Error("A location or initial history entries must be provided.");
620
- }
621
- /**
622
- * What should happen if no entries were in the array?
623
- * It likely uses the root one anyway, but a consistent API is what
624
- * we want, so let's ensure we always have our default location at least.
625
- */
626
-
627
-
628
- const entries = config.initialEntries.length === 0 ? [defaultConfig.location] : config.initialEntries; // Memory router doesn't allow us to pass maybe types in its flow types.
629
- // So let's build props then spread them.
630
-
631
- const routerProps = {
632
- initialEntries: entries
633
- };
634
-
635
- if (config.initialIndex != null) {
636
- routerProps.initialIndex = config.initialIndex;
637
- }
638
-
639
- if (config.getUserConfirmation != null) {
640
- routerProps.getUserConfirmation = config.getUserConfirmation;
641
- }
642
-
643
- return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router_dom__WEBPACK_IMPORTED_MODULE_1__["MemoryRouter"], routerProps, wrappedWithRoute);
644
- };
645
-
646
- /***/ }),
647
- /* 14 */
648
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
649
-
650
- "use strict";
651
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return fixtures; });
652
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
653
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
654
- /* harmony import */ var _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9);
655
- /* harmony import */ var _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__);
656
-
657
-
658
-
659
- /**
660
- * Describe a group of fixtures for a given component.
661
- *
662
- * Only one `fixtures` call should be used per fixture file as it returns
663
- * the exports for that file.
664
- *
665
- * @param {component: React.ComponentType<any>} options Options describing the
666
- * fixture group.
667
- * @param {FixtureFn<TProps> => void} fn A function that provides a `fixture`
668
- * function for defining fixtures.
669
- * @returns {(
670
- * description: string,
671
- * props: FixtureProps<TProps>,
672
- * wrapper?: React.ComponentType<TProps>,
673
- * ) => mixed} A function to create a CSF compatible story.
674
- */
675
- const fixtures = Component => {
676
- const templateMap = new WeakMap(); // We use this to make sure each story gets a unique name.
677
-
678
- let storyNumber = 1;
679
- const getPropsOptions = {
680
- log: (message, ...args) => Object(_storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__["action"])(message).apply(void 0, args),
681
- logHandler: _storybook_addon_actions__WEBPACK_IMPORTED_MODULE_1__["action"]
682
- };
683
-
684
- const makeStory = (description, props, wrapper = null) => {
685
- const storyName = `${storyNumber++} ${description}`;
686
-
687
- const getProps = options => typeof props === "function" ? props(options) : props;
688
-
689
- const RealComponent = wrapper || Component; // We create a “template” of how args map to rendering
690
- // for each type of component as the component here could
691
- // be the component under test, or wrapped in a wrapper
692
- // component. We don't use decorators for the wrapper
693
- // because we may not be in a storybook context and it
694
- // keeps the framework API simpler this way.
695
-
696
- let Template = templateMap.get(RealComponent);
697
-
698
- if (Template == null) {
699
- Template = args => /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](RealComponent, args);
700
-
701
- templateMap.set(RealComponent, Template);
702
- } // Each story that shares that component then reuses that
703
- // template.
704
-
705
-
706
- const story = Template.bind({});
707
- story.args = getProps(getPropsOptions); // Adding a story name here means that we don't have to
708
- // care about naming the exports correctly, if we don't
709
- // want (useful if we need to autogenerate or manually
710
- // expose ESM exports).
711
-
712
- story.storyName = storyName;
713
- return story;
714
- };
715
-
716
- return makeStory;
717
- };
718
-
719
- /***/ }),
720
- /* 15 */
721
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
722
-
723
- "use strict";
724
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockFetch; });
725
- /* harmony import */ var _fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(22);
726
- /* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
727
-
728
-
729
-
730
- /**
731
- * A mock for the fetch function passed to GqlRouter.
732
- */
733
- const mockFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1__[/* mockRequester */ "a"])(_fetch_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* fetchRequestMatchesMock */ "a"], (input, init) => `Input: ${typeof input === "string" ? input : JSON.stringify(input, null, 2)}
734
- Options: ${init == null ? "None" : JSON.stringify(init, null, 2)}`);
735
-
736
- /***/ }),
737
- /* 16 */
738
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
739
-
740
- "use strict";
741
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return mockGqlFetch; });
742
- /* harmony import */ var _gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(23);
743
- /* harmony import */ var _mock_requester_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(7);
744
-
745
-
746
-
747
- /**
748
- * A mock for the fetch function passed to GqlRouter.
749
- */
750
- const mockGqlFetch = () => Object(_mock_requester_js__WEBPACK_IMPORTED_MODULE_1__[/* mockRequester */ "a"])(_gql_request_matches_mock_js__WEBPACK_IMPORTED_MODULE_0__[/* gqlRequestMatchesMock */ "a"], (operation, variables, context) => `Operation: ${operation.type} ${operation.id}
751
- Variables: ${variables == null ? "None" : JSON.stringify(variables, null, 2)}
752
- Context: ${JSON.stringify(context, null, 2)}`);
753
-
754
- /***/ }),
755
- /* 17 */
756
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
757
-
758
- "use strict";
759
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return RespondWith; });
760
- /* harmony import */ var _settle_signal_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(8);
761
- /* harmony import */ var _response_impl_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(24);
762
-
763
-
764
-
765
- /**
766
- * Helper for creating a text-based mock response.
767
- */
768
- const textResponse = (text, statusCode, signal) => ({
769
- toPromise: () => makeMockResponse({
770
- type: "text",
771
- text,
772
- statusCode,
773
- signal
774
- })
775
- });
776
- /**
777
- * Helper for creating a rejected mock response.
778
- */
779
-
780
-
781
- const rejectResponse = (error, signal) => ({
782
- toPromise: () => makeMockResponse({
783
- type: "reject",
784
- error,
785
- signal
786
- })
787
- });
788
- /**
789
- * Helpers to define mock responses for mocked requests.
790
- */
791
-
792
-
793
- const RespondWith = Object.freeze({
794
- /**
795
- * Response with text body and status code.
796
- * Status code defaults to 200.
797
- */
798
- text: (text, statusCode = 200, signal = null) => textResponse(text, statusCode, signal),
799
-
800
- /**
801
- * Response with JSON body and status code 200.
802
- */
803
- json: (json, signal = null) => textResponse(() => JSON.stringify(json), 200, signal),
804
-
805
- /**
806
- * Response with GraphQL data JSON body and status code 200.
807
- */
808
- graphQLData: (data, signal = null) => textResponse(() => JSON.stringify({
809
- data
810
- }), 200, signal),
811
-
812
- /**
813
- * Response with body that will not parse as JSON and status code 200.
814
- */
815
- unparseableBody: (signal = null) => textResponse("INVALID JSON", 200, signal),
816
-
817
- /**
818
- * Rejects with an AbortError to simulate an aborted request.
819
- */
820
- abortedRequest: (signal = null) => rejectResponse(() => {
821
- const abortError = new Error("Mock request aborted");
822
- abortError.name = "AbortError";
823
- return abortError;
824
- }, signal),
825
-
826
- /**
827
- * Rejects with the given error.
828
- */
829
- reject: (error, signal = null) => rejectResponse(error, signal),
830
-
831
- /**
832
- * A non-200 status code with empty text body.
833
- * Equivalent to calling `ResponseWith.text("", statusCode)`.
834
- */
835
- errorStatusCode: (statusCode, signal = null) => {
836
- if (statusCode < 300) {
837
- throw new Error(`${statusCode} is not a valid error status code`);
838
- }
839
-
840
- return textResponse("{}", statusCode, signal);
841
- },
842
-
843
- /**
844
- * Response body that is valid JSON but not a valid GraphQL response.
845
- */
846
- nonGraphQLBody: (signal = null) => textResponse(() => JSON.stringify({
847
- valid: "json",
848
- that: "is not a valid graphql response"
849
- }), 200, signal),
850
-
851
- /**
852
- * Response that is a GraphQL errors response with status code 200.
853
- */
854
- graphQLErrors: (errorMessages, signal = null) => textResponse(() => JSON.stringify({
855
- errors: errorMessages.map(e => ({
856
- message: e
857
- }))
858
- }), 200, signal)
859
- });
860
-
861
- const callOnSettled = (signal, fn) => {
862
- if (signal == null || signal.settled) {
863
- fn();
864
- return;
865
- }
866
-
867
- const onSettled = () => {
868
- signal.removeEventListener("settled", onSettled);
869
- fn();
870
- };
871
-
872
- signal.addEventListener("settled", onSettled);
873
- };
874
- /**
875
- * Turns a MockResponse value to an actual Response that represents the mock.
876
- */
877
-
878
-
879
- const makeMockResponse = response => {
880
- const {
881
- signal
882
- } = response;
883
-
884
- switch (response.type) {
885
- case "text":
886
- return new Promise((resolve, reject) => {
887
- callOnSettled(signal, () => {
888
- const text = typeof response.text === "function" ? response.text() : response.text;
889
- resolve(new _response_impl_js__WEBPACK_IMPORTED_MODULE_1__[/* ResponseImpl */ "a"](text, {
890
- status: response.statusCode
891
- }));
892
- });
893
- });
894
-
895
- case "reject":
896
- return new Promise((resolve, reject) => {
897
- callOnSettled(signal, () => reject(response.error instanceof Error ? response.error : response.error()));
898
- });
899
-
900
- /* istanbul ignore next */
901
-
902
- default:
903
- if (false) {} // Production; assume a rejection.
904
-
905
-
906
- return makeMockResponse({
907
- type: "reject",
908
- error: new Error("Unknown response type"),
909
- signal
910
- });
911
- }
912
- };
913
-
914
- /***/ }),
915
- /* 18 */
916
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
917
-
918
- "use strict";
919
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return SettleController; });
920
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1);
921
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0__);
922
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
923
- /* harmony import */ var _babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(_babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1__);
924
- /* harmony import */ var _settle_signal_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
925
-
926
-
927
-
928
- /**
929
- * A controller for the `RespondWith` API to control response settlement.
930
- */
931
-
932
- var _settleFn = /*#__PURE__*/_babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1___default()("settleFn");
933
-
934
- var _signal = /*#__PURE__*/_babel_runtime_helpers_classPrivateFieldLooseKey__WEBPACK_IMPORTED_MODULE_1___default()("signal");
935
-
936
- class SettleController {
937
- constructor() {
938
- Object.defineProperty(this, _settleFn, {
939
- writable: true,
940
- value: void 0
941
- });
942
- Object.defineProperty(this, _signal, {
943
- writable: true,
944
- value: void 0
945
- });
946
- // Create our signal.
947
- // We pass in a method to capture it's settle function so that
948
- // only we can call it.
949
- _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _signal)[_signal] = new _settle_signal_js__WEBPACK_IMPORTED_MODULE_2__[/* SettleSignal */ "a"](settleFn => _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _settleFn)[_settleFn] = settleFn);
950
- }
951
- /**
952
- * The signal to pass to the `RespondWith` API.
953
- */
954
-
955
-
956
- get signal() {
957
- return _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _signal)[_signal];
958
- }
959
- /**
960
- * Settle the signal and therefore any associated responses.
961
- *
962
- * @throws {Error} if the signal has already been settled.
963
- */
964
-
965
-
966
- settle() {
967
- _babel_runtime_helpers_classPrivateFieldLooseBase__WEBPACK_IMPORTED_MODULE_0___default()(this, _settleFn)[_settleFn]();
968
- }
969
-
970
- }
971
-
972
- /***/ }),
973
- /* 19 */
974
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
975
-
976
- "use strict";
977
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
978
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
979
-
980
- /**
981
- * A adapter to be composed with our test harnass infrastructure.
982
- */
983
-
984
- /***/ }),
985
- /* 20 */
986
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
987
-
988
- "use strict";
989
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return hookHarness; });
990
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
991
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
992
- /* harmony import */ var _make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(6);
993
- /* harmony import */ var _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
994
-
995
-
996
-
997
-
998
- /**
999
- * Create test wrapper for hook testing with Wonder Blocks default adapters.
1000
- *
1001
- * This is primarily useful for tests within Wonder Blocks.
1002
- *
1003
- * If you want to expand the range of adapters or change the default
1004
- * configurations, use `makeHookHarness` to create a new `hookHarness`
1005
- * function.
1006
- */
1007
- const hookHarness = Object(_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_1__[/* makeHookHarness */ "a"])(_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultAdapters"], _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultConfigs"]);
1008
-
1009
- /***/ }),
1010
- /* 21 */
1011
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1012
-
1013
- "use strict";
1014
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return testHarness; });
1015
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1016
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1017
- /* harmony import */ var _make_test_harness_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(4);
1018
- /* harmony import */ var _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(2);
1019
-
1020
-
1021
-
1022
-
1023
- /**
1024
- * Wrap a component with a test harness using Wonder Blocks default adapters.
1025
- *
1026
- * This is primarily useful for tests within Wonder Blocks.
1027
- *
1028
- * If you want to expand the range of adapters or change the default
1029
- * configurations, use `makeTestHarness` to create a new `testHarness`
1030
- * function.
1031
- */
1032
- const testHarness = Object(_make_test_harness_js__WEBPACK_IMPORTED_MODULE_1__[/* makeTestHarness */ "a"])(_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultAdapters"], _adapters_adapters_js__WEBPACK_IMPORTED_MODULE_2__["DefaultConfigs"]);
1033
-
1034
- /***/ }),
1035
- /* 22 */
1036
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1037
-
1038
- "use strict";
1039
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return fetchRequestMatchesMock; });
1040
- /**
1041
- * Get the URL from the given RequestInfo.
1042
- *
1043
- * Since we could be running in Node or in JSDOM, we don't check instance
1044
- * types, but just use a heuristic so that this works without knowing what
1045
- * was polyfilling things.
1046
- */
1047
- const getHref = input => {
1048
- if (typeof input === "string") {
1049
- return input;
1050
- } else if (typeof input.url === "string") {
1051
- return input.url;
1052
- } else if (typeof input.href === "string") {
1053
- return input.href;
1054
- } else {
1055
- throw new Error(`Unsupported input type`);
1056
- }
1057
- };
1058
- /**
1059
- * Determines if a given fetch invocation matches the given mock.
1060
- */
1061
-
1062
-
1063
- const fetchRequestMatchesMock = (mock, input, init) => {
1064
- // Currently, we only match on the input portion.
1065
- // This can be a Request, a URL, or a string.
1066
- const href = getHref(input); // Our mock operation is either a string for an exact match, or a regex.
1067
-
1068
- if (typeof mock === "string") {
1069
- return href === mock;
1070
- } else if (mock instanceof RegExp) {
1071
- return mock.test(href);
1072
- } else {
1073
- throw new Error(`Unsupported mock operation: ${JSON.stringify(mock)}`);
1074
- }
1075
- };
1076
-
1077
- /***/ }),
1078
- /* 23 */
1079
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1080
-
1081
- "use strict";
1082
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return gqlRequestMatchesMock; });
1083
- const safeHasOwnProperty = (obj, prop) => // Flow really shouldn't be raising this error here.
1084
- // $FlowFixMe[method-unbinding]
1085
- Object.prototype.hasOwnProperty.call(obj, prop); // TODO(somewhatabstract, FEI-4268): use a third-party library to do this and
1086
- // possibly make it also support the jest `jest.objectContaining` type matching
1087
- // to simplify mock declaration (note that it would need to work in regular
1088
- // tests and stories/fixtures).
1089
-
1090
-
1091
- const areObjectsEqual = (a, b) => {
1092
- if (a === b) {
1093
- return true;
1094
- }
1095
-
1096
- if (a == null || b == null) {
1097
- return false;
1098
- }
1099
-
1100
- if (typeof a !== "object" || typeof b !== "object") {
1101
- return false;
1102
- }
1103
-
1104
- const aKeys = Object.keys(a);
1105
- const bKeys = Object.keys(b);
1106
-
1107
- if (aKeys.length !== bKeys.length) {
1108
- return false;
1109
- }
1110
-
1111
- for (let i = 0; i < aKeys.length; i++) {
1112
- const key = aKeys[i];
1113
-
1114
- if (!safeHasOwnProperty(b, key) || !areObjectsEqual(a[key], b[key])) {
1115
- return false;
1116
- }
1117
- }
1118
-
1119
- return true;
1120
- };
1121
-
1122
- const gqlRequestMatchesMock = (mock, operation, variables, context) => {
1123
- // If they don't represent the same operation, then they can't match.
1124
- // NOTE: Operations can include more fields than id and type, but we only
1125
- // care about id and type. The rest is ignored.
1126
- if (mock.operation.id !== operation.id || mock.operation.type !== operation.type) {
1127
- return false;
1128
- } // We do a loose match, so if the lhs doesn't define variables,
1129
- // we just assume it matches everything.
1130
-
1131
-
1132
- if (mock.variables != null) {
1133
- // Variables have to match.
1134
- if (!areObjectsEqual(mock.variables, variables)) {
1135
- return false;
1136
- }
1137
- } // We do a loose match, so if the lhs doesn't define context,
1138
- // we just assume it matches everything.
1139
-
1140
-
1141
- if (mock.context != null) {
1142
- // Context has to match.
1143
- if (!areObjectsEqual(mock.context, context)) {
1144
- return false;
1145
- }
1146
- } // If we get here, we have a match.
1147
-
1148
-
1149
- return true;
1150
- };
1151
-
1152
- /***/ }),
1153
- /* 24 */
1154
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1155
-
1156
- "use strict";
1157
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return ResponseImpl; });
1158
- // We need a version of Response. When we're in Jest JSDOM environment or a
1159
- // version of Node that supports the fetch API (17 and up, possibly with
1160
- // --experimental-fetch flag), then we're good, but otherwise we need an
1161
- // implementation, so this uses node-fetch as a peer dependency and uses that
1162
- // to provide the implementation if we don't already have one.
1163
- const ResponseImpl = typeof Response === "undefined" ? __webpack_require__(29).Response : Response;
1164
-
1165
- /***/ }),
1166
- /* 25 */
1167
- /***/ (function(module, exports) {
1168
-
1169
- module.exports = require("@khanacademy/wonder-blocks-data");
1170
-
1171
- /***/ }),
1172
- /* 26 */
1173
- /***/ (function(module, exports) {
1174
-
1175
- function _extends() {
1176
- module.exports = _extends = Object.assign ? Object.assign.bind() : function (target) {
1177
- for (var i = 1; i < arguments.length; i++) {
1178
- var source = arguments[i];
1179
-
1180
- for (var key in source) {
1181
- if (Object.prototype.hasOwnProperty.call(source, key)) {
1182
- target[key] = source[key];
1183
- }
1184
- }
1185
- }
1186
-
1187
- return target;
1188
- }, module.exports.__esModule = true, module.exports["default"] = module.exports;
1189
- return _extends.apply(this, arguments);
1190
- }
1191
-
1192
- module.exports = _extends, module.exports.__esModule = true, module.exports["default"] = module.exports;
1193
-
1194
- /***/ }),
1195
- /* 27 */
1196
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1197
-
1198
- "use strict";
1199
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return renderAdapters; });
1200
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
1201
- /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
1202
-
1203
-
1204
- /**
1205
- * Render test adapters around a child component.
1206
- */
1207
- const renderAdapters = (adapters, configs, children) => {
1208
- let currentChildren = children;
1209
-
1210
- for (const adapterName of Object.keys(adapters)) {
1211
- const adapter = adapters[adapterName];
1212
- const config = configs[adapterName];
1213
- /**
1214
- * Some adapters support a null config, some don't, either way
1215
- * we always assume that null config means no adapter.
1216
- */
1217
-
1218
- if (config != null) {
1219
- currentChildren = adapter(currentChildren, config);
1220
- }
1221
- }
1222
-
1223
- return currentChildren;
1224
- };
1225
-
1226
- /***/ }),
1227
- /* 28 */
1228
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
1229
-
1230
- "use strict";
1231
- __webpack_require__.r(__webpack_exports__);
1232
- /* harmony import */ var _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(14);
1233
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "fixtures", function() { return _fixtures_fixtures_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
1234
-
1235
- /* harmony import */ var _fetch_mock_fetch_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(15);
1236
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mockFetch", function() { return _fetch_mock_fetch_js__WEBPACK_IMPORTED_MODULE_1__["a"]; });
1237
-
1238
- /* harmony import */ var _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(16);
1239
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "mockGqlFetch", function() { return _gql_mock_gql_fetch_js__WEBPACK_IMPORTED_MODULE_2__["a"]; });
1240
-
1241
- /* harmony import */ var _respond_with_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(17);
1242
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "RespondWith", function() { return _respond_with_js__WEBPACK_IMPORTED_MODULE_3__["a"]; });
1243
-
1244
- /* harmony import */ var _settle_controller_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(18);
1245
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "SettleController", function() { return _settle_controller_js__WEBPACK_IMPORTED_MODULE_4__["a"]; });
1246
-
1247
- /* harmony import */ var _harness_types_js__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(19);
1248
- /* harmony import */ var _harness_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(2);
1249
- /* harmony reexport (module object) */ __webpack_require__.d(__webpack_exports__, "harnessAdapters", function() { return _harness_adapters_adapters_js__WEBPACK_IMPORTED_MODULE_6__; });
1250
- /* harmony import */ var _harness_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(6);
1251
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeHookHarness", function() { return _harness_make_hook_harness_js__WEBPACK_IMPORTED_MODULE_7__["a"]; });
1252
-
1253
- /* harmony import */ var _harness_make_test_harness_js__WEBPACK_IMPORTED_MODULE_8__ = __webpack_require__(4);
1254
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "makeTestHarness", function() { return _harness_make_test_harness_js__WEBPACK_IMPORTED_MODULE_8__["a"]; });
1255
-
1256
- /* harmony import */ var _harness_hook_harness_js__WEBPACK_IMPORTED_MODULE_9__ = __webpack_require__(20);
1257
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "hookHarness", function() { return _harness_hook_harness_js__WEBPACK_IMPORTED_MODULE_9__["a"]; });
1258
-
1259
- /* harmony import */ var _harness_test_harness_js__WEBPACK_IMPORTED_MODULE_10__ = __webpack_require__(21);
1260
- /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "testHarness", function() { return _harness_test_harness_js__WEBPACK_IMPORTED_MODULE_10__["a"]; });
1261
-
1262
- // Fixtures framework
1263
-
1264
- // Fetch mocking framework
1265
-
1266
-
1267
-
1268
-
1269
- // Test harness framework
1270
-
1271
-
1272
-
1273
-
1274
-
1275
-
1276
-
1277
-
1278
- /***/ }),
1279
- /* 29 */
1280
- /***/ (function(module, exports) {
1281
-
1282
- module.exports = require("node-fetch");
1283
-
1284
- /***/ })
1285
- /******/ ]);