@pingux/astro 2.32.0-alpha.5 → 2.32.0-alpha.7
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/lib/cjs/components/Calendar/Calendar.test.js +9 -32
- package/lib/cjs/components/Label/Label.test.js +10 -7
- package/lib/cjs/components/PanelHeader/PanelHeader.test.js +7 -3
- package/lib/cjs/hooks/useComponentToggle/index.d.ts +1 -0
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.d.ts +32 -0
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.js +4 -20
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.test.d.ts +1 -0
- package/lib/cjs/hooks/useComponentToggle/useComponentToggle.test.js +8 -9
- package/lib/cjs/utils/testUtils/universalComponentTest.d.ts +5 -0
- package/lib/cjs/utils/testUtils/universalComponentTest.js +86 -0
- package/lib/components/Calendar/Calendar.test.js +9 -32
- package/lib/components/Label/Label.test.js +8 -5
- package/lib/components/PanelHeader/PanelHeader.test.js +7 -3
- package/lib/hooks/useComponentToggle/useComponentToggle.js +4 -21
- package/lib/hooks/useComponentToggle/useComponentToggle.test.js +8 -9
- package/lib/utils/testUtils/universalComponentTest.js +74 -0
- package/package.json +1 -1
@@ -1,28 +1,16 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
4
|
-
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
5
|
-
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
6
|
-
var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
|
7
|
-
var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
|
8
|
-
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
9
|
-
var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/set-prototype-of");
|
10
|
-
var _Promise = require("@babel/runtime-corejs3/core-js-stable/promise");
|
11
|
-
var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
|
12
|
-
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
13
3
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
14
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
15
4
|
var _map = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/map"));
|
16
5
|
var _filter = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/filter"));
|
17
6
|
var _react = _interopRequireDefault(require("react"));
|
18
7
|
var _date = require("@internationalized/date");
|
19
8
|
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
|
20
|
-
var _jestAxe = require("jest-axe");
|
21
9
|
var _isDateWithinRanges = require("../../utils/devUtils/props/isDateWithinRanges");
|
22
10
|
var _testWrapper = require("../../utils/testUtils/testWrapper");
|
11
|
+
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
23
12
|
var _Calendar = _interopRequireDefault(require("./Calendar"));
|
24
13
|
var _react2 = require("@emotion/react");
|
25
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context9; _forEachInstanceProperty(_context9 = ["next", "throw", "return"]).call(_context9, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context10; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context10 = this.tryEntries).call(_context10, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
26
14
|
var unavailableRanges = [['2022-08-01', '2022-08-03'], ['2022-08-15', '2022-08-20']];
|
27
15
|
// This function is run against each date in the calendar
|
28
16
|
var isDateUnavailable = function isDateUnavailable(date) {
|
@@ -35,6 +23,13 @@ var getComponent = function getComponent() {
|
|
35
23
|
renderFn = _ref$renderFn === void 0 ? _testWrapper.render : _ref$renderFn;
|
36
24
|
return renderFn((0, _react2.jsx)(_Calendar["default"], props));
|
37
25
|
};
|
26
|
+
|
27
|
+
// Needs to be added to each components test file.
|
28
|
+
(0, _universalComponentTest.universalComponentTests)({
|
29
|
+
renderComponent: function renderComponent(props) {
|
30
|
+
return (0, _react2.jsx)(_Calendar["default"], props);
|
31
|
+
}
|
32
|
+
});
|
38
33
|
test('renders calendar component', function () {
|
39
34
|
var _context, _context2;
|
40
35
|
getComponent({
|
@@ -299,22 +294,4 @@ test('should autofocus on current day with hasAutoFocus', function () {
|
|
299
294
|
return cell.getAttribute('aria-disabled') !== 'true';
|
300
295
|
});
|
301
296
|
expect(focusedDay[0]).toHaveTextContent(day);
|
302
|
-
});
|
303
|
-
test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
304
|
-
var _getComponent, container, results;
|
305
|
-
return _regeneratorRuntime().wrap(function _callee$(_context8) {
|
306
|
-
while (1) switch (_context8.prev = _context8.next) {
|
307
|
-
case 0:
|
308
|
-
jest.useRealTimers();
|
309
|
-
_getComponent = getComponent(), container = _getComponent.container;
|
310
|
-
_context8.next = 4;
|
311
|
-
return (0, _jestAxe.axe)(container);
|
312
|
-
case 4:
|
313
|
-
results = _context8.sent;
|
314
|
-
expect(results).toHaveNoViolations();
|
315
|
-
case 6:
|
316
|
-
case "end":
|
317
|
-
return _context8.stop();
|
318
|
-
}
|
319
|
-
}, _callee);
|
320
|
-
})));
|
297
|
+
});
|
@@ -4,9 +4,8 @@ var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequ
|
|
4
4
|
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
5
5
|
var _react = _interopRequireDefault(require("react"));
|
6
6
|
var _react2 = require("@testing-library/react");
|
7
|
-
var
|
8
|
-
var
|
9
|
-
var _ = _interopRequireDefault(require("."));
|
7
|
+
var _ = require("../..");
|
8
|
+
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
10
9
|
var _react3 = require("@emotion/react");
|
11
10
|
var testId = 'test-label';
|
12
11
|
var defaultProps = {
|
@@ -14,11 +13,15 @@ var defaultProps = {
|
|
14
13
|
};
|
15
14
|
var getComponent = function getComponent() {
|
16
15
|
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
17
|
-
return (0, _react2.render)((0, _react3.jsx)(_
|
16
|
+
return (0, _react2.render)((0, _react3.jsx)(_.Label, (0, _extends2["default"])({}, defaultProps, props)));
|
18
17
|
};
|
19
18
|
|
20
|
-
//
|
21
|
-
(0,
|
19
|
+
// Needs to be added to each components test file
|
20
|
+
(0, _universalComponentTest.universalComponentTests)({
|
21
|
+
renderComponent: function renderComponent(props) {
|
22
|
+
return (0, _react3.jsx)(_.Label, props);
|
23
|
+
}
|
24
|
+
});
|
22
25
|
test('default label', function () {
|
23
26
|
getComponent();
|
24
27
|
var label = _react2.screen.getByTestId(testId);
|
@@ -45,7 +48,7 @@ test('required label with custom indicator', function () {
|
|
45
48
|
test('label with an input', function () {
|
46
49
|
var labelText = 'This is a label';
|
47
50
|
var inputId = 'blah';
|
48
|
-
var children = (0, _react3.jsx)(_react["default"].Fragment, null, labelText, (0, _react3.jsx)(
|
51
|
+
var children = (0, _react3.jsx)(_react["default"].Fragment, null, labelText, (0, _react3.jsx)(_.Input, {
|
49
52
|
id: inputId
|
50
53
|
}));
|
51
54
|
getComponent({
|
@@ -17,8 +17,8 @@ var _AccountIcon = _interopRequireDefault(require("@pingux/mdi-react/AccountIcon
|
|
17
17
|
var _react2 = require("@testing-library/react");
|
18
18
|
var _index = require("../../index");
|
19
19
|
var _images = require("../../utils/devUtils/constants/images");
|
20
|
-
var _testAxe = _interopRequireDefault(require("../../utils/testUtils/testAxe"));
|
21
20
|
var _testWrapper = require("../../utils/testUtils/testWrapper");
|
21
|
+
var _universalComponentTest = require("../../utils/testUtils/universalComponentTest");
|
22
22
|
var _PanelHeader = require("./PanelHeader");
|
23
23
|
var _react3 = require("@emotion/react");
|
24
24
|
function ownKeys(object, enumerableOnly) { var keys = _Object$keys(object); if (_Object$getOwnPropertySymbols) { var symbols = _Object$getOwnPropertySymbols(object); enumerableOnly && (symbols = _filterInstanceProperty(symbols).call(symbols, function (sym) { return _Object$getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
@@ -47,8 +47,12 @@ jest.mock('../../hooks/useFallbackImage', function () {
|
|
47
47
|
};
|
48
48
|
});
|
49
49
|
|
50
|
-
//
|
51
|
-
(0,
|
50
|
+
// Needs to be added to each components test file
|
51
|
+
(0, _universalComponentTest.universalComponentTests)({
|
52
|
+
renderComponent: function renderComponent(props) {
|
53
|
+
return (0, _react3.jsx)(_index.PanelHeader, (0, _extends2["default"])({}, defaultProps, props));
|
54
|
+
}
|
55
|
+
});
|
52
56
|
describe('PanelHeader', function () {
|
53
57
|
test('renders data', function () {
|
54
58
|
var _context;
|
@@ -0,0 +1 @@
|
|
1
|
+
export { default } from './useComponentToggle';
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/// <reference types="react" />
|
2
|
+
interface UseComponentToggle {
|
3
|
+
/**
|
4
|
+
* Returns one of two components that are supplied via props.
|
5
|
+
* A boolean value is used to determine which component to render.
|
6
|
+
* State can be handled by either props or within this hook if props are not provided.
|
7
|
+
* Also returns a function that inverts the boolean attribute, and calls a callback function.
|
8
|
+
* @param {Object} [props] Properties provided to the state
|
9
|
+
* @param {Boolean} [props.condition] Boolean that controls which component is returned.
|
10
|
+
* @param {Component} [props.ComponentToRenderIfTrue]
|
11
|
+
* Component that is returned when the condition is true.
|
12
|
+
* @param {Component} [props.ComponentToRenderIfFalse]
|
13
|
+
* Component that is returned when the condition is false.
|
14
|
+
* @param {Function} [props.onConditionChange]
|
15
|
+
* Callback function that is called, when the condition boolean changes, if it is provided .
|
16
|
+
* @returns {Object} `{ isOpen: Boolean, open: Function, close: Function, toggle: Function }`
|
17
|
+
* @returns {Object} `{ handleCondtionChange: Function, renderedComponent: Component, }`
|
18
|
+
*/
|
19
|
+
(props: ComponentToggleProps): ComponentToggleResult;
|
20
|
+
}
|
21
|
+
interface ComponentToggleProps {
|
22
|
+
ComponentToRenderIfTrue: React.ReactNode;
|
23
|
+
ComponentToRenderIfFalse: React.ReactNode;
|
24
|
+
condition: boolean;
|
25
|
+
onConditionChange?: (newCondition: boolean, ...args: unknown[]) => void;
|
26
|
+
}
|
27
|
+
interface ComponentToggleResult {
|
28
|
+
handleConditionChange: (...args: unknown[]) => void;
|
29
|
+
RenderedComponent: React.ReactNode;
|
30
|
+
}
|
31
|
+
declare const useComponentToggle: UseComponentToggle;
|
32
|
+
export default useComponentToggle;
|
@@ -9,30 +9,14 @@ exports["default"] = void 0;
|
|
9
9
|
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
11
11
|
var _index = require("../index");
|
12
|
-
|
13
|
-
* Returns one of two components that are supplied via props.
|
14
|
-
* A boolean value is used to determine which component to render.
|
15
|
-
* State can be handled by either props or within this hook if props are not provided.
|
16
|
-
* Also returns a function that inverts the boolean attribute, and calls a callback function.
|
17
|
-
* @param {Object} [props] Properties provided to the state
|
18
|
-
* @param {Boolean} [props.condition] Boolean that controls which component is returned.
|
19
|
-
* @param {Component} [props.ComponentToRenderIfTrue]
|
20
|
-
* Component that is returned when the condition is true.
|
21
|
-
* @param {Component} [props.ComponentToRenderIfFalse]
|
22
|
-
* Component that is returned when the condition is false.
|
23
|
-
* @param {Function} [props.onConditionChange]
|
24
|
-
* Callback function that is called, when the condition boolean changes, if it is provided .
|
25
|
-
* @returns {Object} `{ isOpen: Boolean, open: Function, close: Function, toggle: Function }`
|
26
|
-
* @returns {Object} `{ handleCondtionChange: Function, renderedComponent: Component, }`
|
27
|
-
*/
|
28
|
-
|
29
|
-
var useComponentToggle = function useComponentToggle() {
|
30
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
12
|
+
var useComponentToggle = function useComponentToggle(props) {
|
31
13
|
var ComponentToRenderIfTrue = props.ComponentToRenderIfTrue,
|
32
14
|
ComponentToRenderIfFalse = props.ComponentToRenderIfFalse,
|
33
15
|
condition = props.condition,
|
34
16
|
onConditionChange = props.onConditionChange;
|
35
|
-
var _useProgressiveState = (0, _index.useProgressiveState)(condition, function () {
|
17
|
+
var _useProgressiveState = (0, _index.useProgressiveState)(condition, function () {
|
18
|
+
return null;
|
19
|
+
}),
|
36
20
|
_useProgressiveState2 = (0, _slicedToArray2["default"])(_useProgressiveState, 2),
|
37
21
|
isToggled = _useProgressiveState2[0],
|
38
22
|
setIsToggled = _useProgressiveState2[1];
|
@@ -0,0 +1 @@
|
|
1
|
+
export {};
|
@@ -14,7 +14,6 @@ var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
|
14
14
|
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
15
15
|
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
16
16
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
17
|
-
var _extends2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
18
17
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
19
18
|
var _react = _interopRequireWildcard(require("react"));
|
20
19
|
var _react2 = require("@testing-library/react");
|
@@ -30,8 +29,8 @@ var condition = false;
|
|
30
29
|
var defaultProps = {
|
31
30
|
condition: condition,
|
32
31
|
onConditionChange: callback,
|
33
|
-
ComponentToRenderIfTrue:
|
34
|
-
ComponentToRenderIfFalse:
|
32
|
+
ComponentToRenderIfTrue: (0, _react3.jsx)("span", null, "true-string"),
|
33
|
+
ComponentToRenderIfFalse: (0, _react3.jsx)("span", null, "false-string")
|
35
34
|
};
|
36
35
|
var TestComponent = function TestComponent() {
|
37
36
|
var _useState = (0, _react.useState)(false),
|
@@ -41,26 +40,26 @@ var TestComponent = function TestComponent() {
|
|
41
40
|
var conditionalRenderProps = {
|
42
41
|
condition: thisCondition,
|
43
42
|
onConditionChange: setCondition,
|
44
|
-
ComponentToRenderIfTrue:
|
45
|
-
ComponentToRenderIfFalse:
|
43
|
+
ComponentToRenderIfTrue: (0, _react3.jsx)("span", null, "true-string"),
|
44
|
+
ComponentToRenderIfFalse: (0, _react3.jsx)("span", null, "false-string"),
|
46
45
|
onConditionChangeProp: callback
|
47
46
|
};
|
48
47
|
var _useComponentToggle = (0, _useComponentToggle2["default"])(conditionalRenderProps),
|
49
48
|
handleConditionChange = _useComponentToggle.handleConditionChange,
|
50
49
|
RenderedComponent = _useComponentToggle.RenderedComponent;
|
51
50
|
return (0, _react3.jsx)("button", {
|
51
|
+
type: "button",
|
52
52
|
"data-testid": "test-div",
|
53
53
|
onClick: handleConditionChange,
|
54
54
|
onKeyDown: handleConditionChange
|
55
55
|
}, RenderedComponent);
|
56
56
|
};
|
57
57
|
var getComponent = function getComponent() {
|
58
|
-
|
59
|
-
return (0, _react2.render)((0, _react3.jsx)(TestComponent, (0, _extends2["default"])({}, props, defaultProps)));
|
58
|
+
return (0, _react2.render)((0, _react3.jsx)(TestComponent, null));
|
60
59
|
};
|
61
60
|
test('default useField', function () {
|
62
61
|
(0, _reactHooks.renderHook)(function () {
|
63
|
-
return (0, _useComponentToggle2["default"])();
|
62
|
+
return (0, _useComponentToggle2["default"])(defaultProps);
|
64
63
|
});
|
65
64
|
});
|
66
65
|
test('callback function should call, if provided', function () {
|
@@ -83,7 +82,7 @@ test('expect hook to return correct data shape', /*#__PURE__*/(0, _asyncToGenera
|
|
83
82
|
}), result = _renderHook2.result;
|
84
83
|
_result$current = result.current, handleConditionChange = _result$current.handleConditionChange, RenderedComponent = _result$current.RenderedComponent;
|
85
84
|
expect(handleConditionChange).toEqual(expect.any(Function));
|
86
|
-
expect(RenderedComponent).toEqual(
|
85
|
+
expect(RenderedComponent).toEqual((0, _react3.jsx)("span", null, "false-string"));
|
87
86
|
case 4:
|
88
87
|
case "end":
|
89
88
|
return _context.stop();
|
@@ -0,0 +1,86 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
var _typeof = require("@babel/runtime-corejs3/helpers/typeof");
|
4
|
+
var _Object$defineProperty = require("@babel/runtime-corejs3/core-js-stable/object/define-property");
|
5
|
+
var _Symbol = require("@babel/runtime-corejs3/core-js-stable/symbol");
|
6
|
+
var _Object$create = require("@babel/runtime-corejs3/core-js-stable/object/create");
|
7
|
+
var _Object$getPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/get-prototype-of");
|
8
|
+
var _forEachInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/for-each");
|
9
|
+
var _Object$setPrototypeOf = require("@babel/runtime-corejs3/core-js-stable/object/set-prototype-of");
|
10
|
+
var _Promise = require("@babel/runtime-corejs3/core-js-stable/promise");
|
11
|
+
var _reverseInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/reverse");
|
12
|
+
var _sliceInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/slice");
|
13
|
+
var _WeakMap = require("@babel/runtime-corejs3/core-js-stable/weak-map");
|
14
|
+
var _Object$getOwnPropertyDescriptor = require("@babel/runtime-corejs3/core-js-stable/object/get-own-property-descriptor");
|
15
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
16
|
+
_Object$defineProperty(exports, "__esModule", {
|
17
|
+
value: true
|
18
|
+
});
|
19
|
+
exports.universalComponentTests = void 0;
|
20
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/asyncToGenerator"));
|
21
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
22
|
+
var _react = _interopRequireWildcard(require("react"));
|
23
|
+
var _react2 = require("@testing-library/react");
|
24
|
+
var _jestAxe = require("jest-axe");
|
25
|
+
var _react3 = require("@emotion/react");
|
26
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof _WeakMap !== "function") return null; var cacheBabelInterop = new _WeakMap(); var cacheNodeInterop = new _WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
27
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = _Object$defineProperty && _Object$getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? _Object$getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { _Object$defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
28
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context3; _forEachInstanceProperty(_context3 = ["next", "throw", "return"]).call(_context3, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context4; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context4 = this.tryEntries).call(_context4, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
29
|
+
var HAS_REF = 'ref';
|
30
|
+
var ComponentWithRef = function ComponentWithRef(_ref) {
|
31
|
+
var renderComponent = _ref.renderComponent;
|
32
|
+
var _useState = (0, _react.useState)(null),
|
33
|
+
_useState2 = (0, _slicedToArray2["default"])(_useState, 2),
|
34
|
+
state = _useState2[0],
|
35
|
+
setState = _useState2[1];
|
36
|
+
var ref = (0, _react.useRef)();
|
37
|
+
(0, _react.useEffect)(function () {
|
38
|
+
if (!ref.current) return;
|
39
|
+
setState(ref.current);
|
40
|
+
}, []);
|
41
|
+
return (0, _react3.jsx)(_react["default"].Fragment, null, renderComponent({
|
42
|
+
ref: ref
|
43
|
+
}), state && HAS_REF);
|
44
|
+
};
|
45
|
+
var universalComponentTests = /*#__PURE__*/function () {
|
46
|
+
var _ref3 = (0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
47
|
+
var renderComponent, props, _ref2$rules, rules;
|
48
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
49
|
+
while (1) switch (_context2.prev = _context2.next) {
|
50
|
+
case 0:
|
51
|
+
renderComponent = _ref2.renderComponent, props = _ref2.props, _ref2$rules = _ref2.rules, rules = _ref2$rules === void 0 ? {} : _ref2$rules;
|
52
|
+
test('should have no accessibility violations', /*#__PURE__*/(0, _asyncToGenerator2["default"])( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
53
|
+
var _render, container, results;
|
54
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
55
|
+
while (1) switch (_context.prev = _context.next) {
|
56
|
+
case 0:
|
57
|
+
jest.useRealTimers();
|
58
|
+
_render = (0, _react2.render)(renderComponent(props)), container = _render.container;
|
59
|
+
_context.next = 4;
|
60
|
+
return (0, _jestAxe.axe)(container, rules);
|
61
|
+
case 4:
|
62
|
+
results = _context.sent;
|
63
|
+
expect(results).toHaveNoViolations();
|
64
|
+
case 6:
|
65
|
+
case "end":
|
66
|
+
return _context.stop();
|
67
|
+
}
|
68
|
+
}, _callee);
|
69
|
+
})));
|
70
|
+
test('should forward refs properly', function () {
|
71
|
+
(0, _react2.render)((0, _react3.jsx)(ComponentWithRef, {
|
72
|
+
renderComponent: renderComponent
|
73
|
+
}));
|
74
|
+
_react2.screen.getByText(HAS_REF);
|
75
|
+
});
|
76
|
+
case 3:
|
77
|
+
case "end":
|
78
|
+
return _context2.stop();
|
79
|
+
}
|
80
|
+
}, _callee2);
|
81
|
+
}));
|
82
|
+
return function universalComponentTests(_x) {
|
83
|
+
return _ref3.apply(this, arguments);
|
84
|
+
};
|
85
|
+
}();
|
86
|
+
exports.universalComponentTests = universalComponentTests;
|
@@ -1,23 +1,11 @@
|
|
1
|
-
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
2
|
-
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
3
|
-
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context9; _forEachInstanceProperty(_context9 = ["next", "throw", "return"]).call(_context9, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context10; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context10 = this.tryEntries).call(_context10, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
4
1
|
import _mapInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/map";
|
5
2
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
6
|
-
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
7
|
-
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
8
|
-
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
9
|
-
import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
|
10
|
-
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
11
|
-
import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
|
12
|
-
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
13
|
-
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
14
|
-
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
15
3
|
import React from 'react';
|
16
4
|
import { getLocalTimeZone, today } from '@internationalized/date';
|
17
5
|
import userEvent from '@testing-library/user-event';
|
18
|
-
import { axe } from 'jest-axe';
|
19
6
|
import { isDateWithinRanges } from '../../utils/devUtils/props/isDateWithinRanges';
|
20
7
|
import { act, fireEvent, render, screen, within } from '../../utils/testUtils/testWrapper';
|
8
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
21
9
|
import Calendar from './Calendar';
|
22
10
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
23
11
|
var unavailableRanges = [['2022-08-01', '2022-08-03'], ['2022-08-15', '2022-08-20']];
|
@@ -32,6 +20,13 @@ var getComponent = function getComponent() {
|
|
32
20
|
renderFn = _ref$renderFn === void 0 ? render : _ref$renderFn;
|
33
21
|
return renderFn(___EmotionJSX(Calendar, props));
|
34
22
|
};
|
23
|
+
|
24
|
+
// Needs to be added to each components test file.
|
25
|
+
universalComponentTests({
|
26
|
+
renderComponent: function renderComponent(props) {
|
27
|
+
return ___EmotionJSX(Calendar, props);
|
28
|
+
}
|
29
|
+
});
|
35
30
|
test('renders calendar component', function () {
|
36
31
|
var _context, _context2;
|
37
32
|
getComponent({
|
@@ -296,22 +291,4 @@ test('should autofocus on current day with hasAutoFocus', function () {
|
|
296
291
|
return cell.getAttribute('aria-disabled') !== 'true';
|
297
292
|
});
|
298
293
|
expect(focusedDay[0]).toHaveTextContent(day);
|
299
|
-
});
|
300
|
-
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
301
|
-
var _getComponent, container, results;
|
302
|
-
return _regeneratorRuntime().wrap(function _callee$(_context8) {
|
303
|
-
while (1) switch (_context8.prev = _context8.next) {
|
304
|
-
case 0:
|
305
|
-
jest.useRealTimers();
|
306
|
-
_getComponent = getComponent(), container = _getComponent.container;
|
307
|
-
_context8.next = 4;
|
308
|
-
return axe(container);
|
309
|
-
case 4:
|
310
|
-
results = _context8.sent;
|
311
|
-
expect(results).toHaveNoViolations();
|
312
|
-
case 6:
|
313
|
-
case "end":
|
314
|
-
return _context8.stop();
|
315
|
-
}
|
316
|
-
}, _callee);
|
317
|
-
})));
|
294
|
+
});
|
@@ -1,9 +1,8 @@
|
|
1
1
|
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
2
2
|
import React from 'react';
|
3
3
|
import { fireEvent, render, screen } from '@testing-library/react';
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import Label from '.';
|
4
|
+
import { Input, Label } from '../..';
|
5
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
7
6
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
8
7
|
var testId = 'test-label';
|
9
8
|
var defaultProps = {
|
@@ -14,8 +13,12 @@ var getComponent = function getComponent() {
|
|
14
13
|
return render(___EmotionJSX(Label, _extends({}, defaultProps, props)));
|
15
14
|
};
|
16
15
|
|
17
|
-
//
|
18
|
-
|
16
|
+
// Needs to be added to each components test file
|
17
|
+
universalComponentTests({
|
18
|
+
renderComponent: function renderComponent(props) {
|
19
|
+
return ___EmotionJSX(Label, props);
|
20
|
+
}
|
21
|
+
});
|
19
22
|
test('default label', function () {
|
20
23
|
getComponent();
|
21
24
|
var label = screen.getByTestId(testId);
|
@@ -16,8 +16,8 @@ import AccountIcon from '@pingux/mdi-react/AccountIcon';
|
|
16
16
|
import { act } from '@testing-library/react';
|
17
17
|
import { PanelHeader, PanelHeaderSwitchField } from '../../index';
|
18
18
|
import { pingImg } from '../../utils/devUtils/constants/images';
|
19
|
-
import axeTest from '../../utils/testUtils/testAxe';
|
20
19
|
import { render, screen } from '../../utils/testUtils/testWrapper';
|
20
|
+
import { universalComponentTests } from '../../utils/testUtils/universalComponentTest';
|
21
21
|
import { PANEL_HEADER_ICON } from './PanelHeader';
|
22
22
|
import { jsx as ___EmotionJSX } from "@emotion/react";
|
23
23
|
var defaultProps = {
|
@@ -44,8 +44,12 @@ jest.mock('../../hooks/useFallbackImage', function () {
|
|
44
44
|
};
|
45
45
|
});
|
46
46
|
|
47
|
-
//
|
48
|
-
|
47
|
+
// Needs to be added to each components test file
|
48
|
+
universalComponentTests({
|
49
|
+
renderComponent: function renderComponent(props) {
|
50
|
+
return ___EmotionJSX(PanelHeader, _extends({}, defaultProps, props));
|
51
|
+
}
|
52
|
+
});
|
49
53
|
describe('PanelHeader', function () {
|
50
54
|
test('renders data', function () {
|
51
55
|
var _context;
|
@@ -1,31 +1,14 @@
|
|
1
1
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
2
2
|
import _concatInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/concat";
|
3
3
|
import { useProgressiveState } from '../index';
|
4
|
-
|
5
|
-
/**
|
6
|
-
* Returns one of two components that are supplied via props.
|
7
|
-
* A boolean value is used to determine which component to render.
|
8
|
-
* State can be handled by either props or within this hook if props are not provided.
|
9
|
-
* Also returns a function that inverts the boolean attribute, and calls a callback function.
|
10
|
-
* @param {Object} [props] Properties provided to the state
|
11
|
-
* @param {Boolean} [props.condition] Boolean that controls which component is returned.
|
12
|
-
* @param {Component} [props.ComponentToRenderIfTrue]
|
13
|
-
* Component that is returned when the condition is true.
|
14
|
-
* @param {Component} [props.ComponentToRenderIfFalse]
|
15
|
-
* Component that is returned when the condition is false.
|
16
|
-
* @param {Function} [props.onConditionChange]
|
17
|
-
* Callback function that is called, when the condition boolean changes, if it is provided .
|
18
|
-
* @returns {Object} `{ isOpen: Boolean, open: Function, close: Function, toggle: Function }`
|
19
|
-
* @returns {Object} `{ handleCondtionChange: Function, renderedComponent: Component, }`
|
20
|
-
*/
|
21
|
-
|
22
|
-
var useComponentToggle = function useComponentToggle() {
|
23
|
-
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
4
|
+
var useComponentToggle = function useComponentToggle(props) {
|
24
5
|
var ComponentToRenderIfTrue = props.ComponentToRenderIfTrue,
|
25
6
|
ComponentToRenderIfFalse = props.ComponentToRenderIfFalse,
|
26
7
|
condition = props.condition,
|
27
8
|
onConditionChange = props.onConditionChange;
|
28
|
-
var _useProgressiveState = useProgressiveState(condition, function () {
|
9
|
+
var _useProgressiveState = useProgressiveState(condition, function () {
|
10
|
+
return null;
|
11
|
+
}),
|
29
12
|
_useProgressiveState2 = _slicedToArray(_useProgressiveState, 2),
|
30
13
|
isToggled = _useProgressiveState2[0],
|
31
14
|
setIsToggled = _useProgressiveState2[1];
|
@@ -9,7 +9,6 @@ import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/inst
|
|
9
9
|
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
10
10
|
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
11
11
|
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
12
|
-
import _extends from "@babel/runtime-corejs3/helpers/esm/extends";
|
13
12
|
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
14
13
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context3; _forEachInstanceProperty(_context3 = ["next", "throw", "return"]).call(_context3, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context4; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context4 = this.tryEntries).call(_context4, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
15
14
|
import React, { useState } from 'react';
|
@@ -23,8 +22,8 @@ var condition = false;
|
|
23
22
|
var defaultProps = {
|
24
23
|
condition: condition,
|
25
24
|
onConditionChange: callback,
|
26
|
-
ComponentToRenderIfTrue:
|
27
|
-
ComponentToRenderIfFalse:
|
25
|
+
ComponentToRenderIfTrue: ___EmotionJSX("span", null, "true-string"),
|
26
|
+
ComponentToRenderIfFalse: ___EmotionJSX("span", null, "false-string")
|
28
27
|
};
|
29
28
|
var TestComponent = function TestComponent() {
|
30
29
|
var _useState = useState(false),
|
@@ -34,26 +33,26 @@ var TestComponent = function TestComponent() {
|
|
34
33
|
var conditionalRenderProps = {
|
35
34
|
condition: thisCondition,
|
36
35
|
onConditionChange: setCondition,
|
37
|
-
ComponentToRenderIfTrue:
|
38
|
-
ComponentToRenderIfFalse:
|
36
|
+
ComponentToRenderIfTrue: ___EmotionJSX("span", null, "true-string"),
|
37
|
+
ComponentToRenderIfFalse: ___EmotionJSX("span", null, "false-string"),
|
39
38
|
onConditionChangeProp: callback
|
40
39
|
};
|
41
40
|
var _useComponentToggle = useComponentToggle(conditionalRenderProps),
|
42
41
|
handleConditionChange = _useComponentToggle.handleConditionChange,
|
43
42
|
RenderedComponent = _useComponentToggle.RenderedComponent;
|
44
43
|
return ___EmotionJSX("button", {
|
44
|
+
type: "button",
|
45
45
|
"data-testid": "test-div",
|
46
46
|
onClick: handleConditionChange,
|
47
47
|
onKeyDown: handleConditionChange
|
48
48
|
}, RenderedComponent);
|
49
49
|
};
|
50
50
|
var getComponent = function getComponent() {
|
51
|
-
|
52
|
-
return render(___EmotionJSX(TestComponent, _extends({}, props, defaultProps)));
|
51
|
+
return render(___EmotionJSX(TestComponent, null));
|
53
52
|
};
|
54
53
|
test('default useField', function () {
|
55
54
|
renderHook(function () {
|
56
|
-
return useComponentToggle();
|
55
|
+
return useComponentToggle(defaultProps);
|
57
56
|
});
|
58
57
|
});
|
59
58
|
test('callback function should call, if provided', function () {
|
@@ -76,7 +75,7 @@ test('expect hook to return correct data shape', /*#__PURE__*/_asyncToGenerator(
|
|
76
75
|
}), result = _renderHook2.result;
|
77
76
|
_result$current = result.current, handleConditionChange = _result$current.handleConditionChange, RenderedComponent = _result$current.RenderedComponent;
|
78
77
|
expect(handleConditionChange).toEqual(expect.any(Function));
|
79
|
-
expect(RenderedComponent).toEqual(
|
78
|
+
expect(RenderedComponent).toEqual(___EmotionJSX("span", null, "false-string"));
|
80
79
|
case 4:
|
81
80
|
case "end":
|
82
81
|
return _context.stop();
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import _Object$defineProperty from "@babel/runtime-corejs3/core-js-stable/object/define-property";
|
2
|
+
import _Symbol from "@babel/runtime-corejs3/core-js-stable/symbol";
|
3
|
+
import _Object$create from "@babel/runtime-corejs3/core-js-stable/object/create";
|
4
|
+
import _Object$getPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/get-prototype-of";
|
5
|
+
import _forEachInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/for-each";
|
6
|
+
import _Object$setPrototypeOf from "@babel/runtime-corejs3/core-js-stable/object/set-prototype-of";
|
7
|
+
import _Promise from "@babel/runtime-corejs3/core-js-stable/promise";
|
8
|
+
import _reverseInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/reverse";
|
9
|
+
import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/slice";
|
10
|
+
import _typeof from "@babel/runtime-corejs3/helpers/esm/typeof";
|
11
|
+
import _asyncToGenerator from "@babel/runtime-corejs3/helpers/esm/asyncToGenerator";
|
12
|
+
import _slicedToArray from "@babel/runtime-corejs3/helpers/esm/slicedToArray";
|
13
|
+
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, defineProperty = _Object$defineProperty || function (obj, key, desc) { obj[key] = desc.value; }, $Symbol = "function" == typeof _Symbol ? _Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return _Object$defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = _Object$create(protoGenerator.prototype), context = new Context(tryLocsList || []); return defineProperty(generator, "_invoke", { value: makeInvokeMethod(innerFn, self, context) }), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = _Object$getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = _Object$create(IteratorPrototype); function defineIteratorMethods(prototype) { var _context3; _forEachInstanceProperty(_context3 = ["next", "throw", "return"]).call(_context3, function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; defineProperty(this, "_invoke", { value: function value(method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; } function maybeInvokeDelegate(delegate, context) { var methodName = context.method, method = delegate.iterator[methodName]; if (undefined === method) return context.delegate = null, "throw" === methodName && delegate.iterator["return"] && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method) || "return" !== methodName && (context.method = "throw", context.arg = new TypeError("The iterator does not provide a '" + methodName + "' method")), ContinueSentinel; var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], _forEachInstanceProperty(tryLocsList).call(tryLocsList, pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, defineProperty(Gp, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), defineProperty(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return _Object$setPrototypeOf ? _Object$setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = _Object$create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = _Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (val) { var object = Object(val), keys = []; for (var key in object) keys.push(key); return _reverseInstanceProperty(keys).call(keys), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { var _context4; if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, _forEachInstanceProperty(_context4 = this.tryEntries).call(_context4, resetTryEntry), !skipTempReset) for (var name in this) "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+_sliceInstanceProperty(name).call(name, 1)) && (this[name] = undefined); }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, "catch": function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
|
14
|
+
import React, { useEffect, useRef, useState } from 'react';
|
15
|
+
import { render, screen } from '@testing-library/react';
|
16
|
+
import { axe } from 'jest-axe';
|
17
|
+
import { jsx as ___EmotionJSX } from "@emotion/react";
|
18
|
+
var HAS_REF = 'ref';
|
19
|
+
var ComponentWithRef = function ComponentWithRef(_ref) {
|
20
|
+
var renderComponent = _ref.renderComponent;
|
21
|
+
var _useState = useState(null),
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
23
|
+
state = _useState2[0],
|
24
|
+
setState = _useState2[1];
|
25
|
+
var ref = useRef();
|
26
|
+
useEffect(function () {
|
27
|
+
if (!ref.current) return;
|
28
|
+
setState(ref.current);
|
29
|
+
}, []);
|
30
|
+
return ___EmotionJSX(React.Fragment, null, renderComponent({
|
31
|
+
ref: ref
|
32
|
+
}), state && HAS_REF);
|
33
|
+
};
|
34
|
+
export var universalComponentTests = /*#__PURE__*/function () {
|
35
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(_ref2) {
|
36
|
+
var renderComponent, props, _ref2$rules, rules;
|
37
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
38
|
+
while (1) switch (_context2.prev = _context2.next) {
|
39
|
+
case 0:
|
40
|
+
renderComponent = _ref2.renderComponent, props = _ref2.props, _ref2$rules = _ref2.rules, rules = _ref2$rules === void 0 ? {} : _ref2$rules;
|
41
|
+
test('should have no accessibility violations', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
42
|
+
var _render, container, results;
|
43
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
44
|
+
while (1) switch (_context.prev = _context.next) {
|
45
|
+
case 0:
|
46
|
+
jest.useRealTimers();
|
47
|
+
_render = render(renderComponent(props)), container = _render.container;
|
48
|
+
_context.next = 4;
|
49
|
+
return axe(container, rules);
|
50
|
+
case 4:
|
51
|
+
results = _context.sent;
|
52
|
+
expect(results).toHaveNoViolations();
|
53
|
+
case 6:
|
54
|
+
case "end":
|
55
|
+
return _context.stop();
|
56
|
+
}
|
57
|
+
}, _callee);
|
58
|
+
})));
|
59
|
+
test('should forward refs properly', function () {
|
60
|
+
render(___EmotionJSX(ComponentWithRef, {
|
61
|
+
renderComponent: renderComponent
|
62
|
+
}));
|
63
|
+
screen.getByText(HAS_REF);
|
64
|
+
});
|
65
|
+
case 3:
|
66
|
+
case "end":
|
67
|
+
return _context2.stop();
|
68
|
+
}
|
69
|
+
}, _callee2);
|
70
|
+
}));
|
71
|
+
return function universalComponentTests(_x) {
|
72
|
+
return _ref3.apply(this, arguments);
|
73
|
+
};
|
74
|
+
}();
|