"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.axeCheck=axeCheck,exports.mountToDiv=mountToDiv,exports.testAnalytics=testAnalytics;var _enzyme=require("enzyme"),_sinon=_interopRequireDefault(require("sinon"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function _toConsumableArray(e){return _arrayWithoutHoles(e)||_iterableToArray(e)||_unsupportedIterableToArray(e)||_nonIterableSpread()}function _nonIterableSpread(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(e,t){if(e){if("string"==typeof e)return _arrayLikeToArray(e,t);var r={}.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?_arrayLikeToArray(e,t):void 0}}function _iterableToArray(e){if("undefined"!=typeof Symbol&&null!=e[Symbol.iterator]||null!=e["@@iterator"])return Array.from(e)}function _arrayWithoutHoles(e){if(Array.isArray(e))return _arrayLikeToArray(e)}function _arrayLikeToArray(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=Array(t);r<t;r++)n[r]=e[r];return n}function mountToDiv(e,t){var r=document.getElementById(t);return r||((r=document.createElement("div")).setAttribute("id",t),document.body.appendChild(r)),r.innerHTML="",(0,_enzyme.mount)(e,{attachTo:r})}function axeCheck(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[],r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,n=document.getElementById("axeContainer");n||((n=document.createElement("div")).setAttribute("id","axeContainer"),document.body.appendChild(n)),n.setAttribute("role","region"),n.setAttribute("aria-label","Component ".concat(Math.floor(Math.random()*Math.floor(100)))),n.innerHTML="";var o=(0,_enzyme.mount)(e,{attachTo:n});return r&&o.setState(r),new Promise(function(e,r){axe.run(document.body,function(n,a){n&&(console.error(n),r(n));var i=a.violations.filter(function(e){return!t.includes(e.id)});i.length&&r(new Error(i.map(function(e){var t=e.nodes.reduce(function(e,t){var r=t.html,n=t.target;return[e,r].concat(_toConsumableArray(n)).join("\n")},"");return"[".concat(e.impact,"] ").concat(e.help,"\nId: ").concat(e.id,"\nSee ").concat(e.helpUrl,"\n").concat(t)}).join("\n"))),o.unmount(),e()})})}function testAnalytics(e,t){var r=_sinon.default.spy();return global.document.body.addEventListener("component-library-analytics",r),t(e),global.document.body.removeEventListener("component-library-analytics",r),r}