UNPKG

testbook

Version:
2 lines 31.8 kB
(this.webpackJsonptestbook=this.webpackJsonptestbook||[]).push([[0],{32:function(e,t,n){e.exports={bg:"App_bg__H7pzh"}},40:function(e,t,n){},58:function(e,t,n){"use strict";n.r(t);var r,c=n(0),o=n(28),s=n.n(o),i=(n(40),n(10)),a=n(4),l=function(){return Object(c.jsx)("nav",{className:"flex flex-col w-full md:w-1/6 text-gray-700 bg-white dark-mode:text-gray-200 dark-mode:bg-gray-800 flex-shrink-0 bg-gray-800 p-3",children:Object(c.jsxs)("div",{className:"flex-shrink-0 flex flex-row justify-between md:justify-center text-white",children:[Object(c.jsxs)("div",{className:"flex items-center flex-shrink-0 mr-6",children:[Object(c.jsx)("svg",{className:"fill-current h-8 w-8 mr-2",width:"54",height:"54",viewBox:"0 0 20 20",children:Object(c.jsx)("path",{d:"M12.361,6.852H7.639C5.9,6.852,4.491,8.262,4.491,10s1.409,3.148,3.148,3.148h4.723c1.738,0,3.148-1.41,3.148-3.148S14.1,6.852,12.361,6.852z M12.361,12.361H7.639c-1.304,0-2.361-1.058-2.361-2.361s1.057-2.36,2.361-2.36h4.723c1.304,0,2.36,1.057,2.36,2.36S13.665,12.361,12.361,12.361z M10,0.949c-4.999,0-9.051,4.053-9.051,9.051S5.001,19.051,10,19.051c4.999,0,9.051-4.053,9.051-9.051S14.999,0.949,10,0.949z M10,18.264c-4.564,0-8.264-3.699-8.264-8.264S5.436,1.736,10,1.736c4.564,0,8.264,3.699,8.264,8.264S14.564,18.264,10,18.264z M7.639,8.819c-0.652,0-1.18,0.528-1.18,1.181s0.528,1.181,1.18,1.181c0.652,0,1.181-0.528,1.181-1.181S8.291,8.819,7.639,8.819z"})}),Object(c.jsx)(i.b,{to:"/",className:"font-semibold text-xl tracking-tight hover:underline",children:"Testbook"})]}),Object(c.jsx)("button",{className:"rounded-lg md:hidden rounded-lg focus:outline-none focus:shadow-outline",children:Object(c.jsx)("svg",{fill:"currentColor",viewBox:"0 0 20 20",className:"w-6 h-6",children:Object(c.jsx)("path",{fillRule:"evenodd",d:"M3 5a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM3 10a1 1 0 011-1h12a1 1 0 110 2H4a1 1 0 01-1-1zM9 15a1 1 0 011-1h6a1 1 0 110 2h-6a1 1 0 01-1-1z"})})})]})})},d=n(2),u=n(3),j=n(1),b=function(e){var t=e.children;return Object(c.jsx)("div",{className:"flex h-full",children:Object(c.jsxs)("div",{className:"m-auto text-center",children:[Object(c.jsx)("div",{className:"inline-block loader ease-linear rounded-full border-8 border-t-8 border-gray-200 h-16 w-16"}),Object(c.jsx)("div",{className:"mt-2 text-gray-700 font-medium",children:t})]})})},f={success:"bg-green-400",error:"bg-red-400"},h=function(e,t){return t?"bg-gray-800 text-white shadow-md":e?"bg-gray-600 hover:bg-gray-800 text-white":"text-gray-700 hover:text-gray-600 hover:bg-gray-100"},m=function(e){var t=e.link,n=e.children,r=e.selected,o=void 0!==r&&r,s=e.active,a=void 0!==s&&s,l=e.subtitle,d=void 0===l?null:l,u=e.status,j=void 0===u?null:u,b=e.onResultClick,m=void 0===b?null:b;return Object(c.jsxs)(i.b,{to:t,className:"flex items-center rounded-3xl p-2 my-2 ".concat(h(o,a)),children:[Object(c.jsx)("span",{className:"".concat(j&&f[j]||"bg-gray-400"," h-2 w-2 m-2 rounded-full flex-shrink-0 ").concat(m&&"hover:bg-red-700"),onClick:m||function(){}}),Object(c.jsx)("div",{className:"flex-grow font-medium px-2",children:n}),d&&Object(c.jsx)("div",{className:"text-xs font-normal text-gray-500 tracking-wide mr-2",children:d})]})},x=function(e){var t=e.file,n=e.components;return Object(c.jsxs)("div",{className:"p-3 mx-3 my-4 bg-white shadow-md rounded-2xl",children:[Object(c.jsx)("div",{className:"text-gray-700 text-lg font-semibold py-2 px-2",children:t}),n.map((function(e){var n;return Object(c.jsxs)(m,{link:"/tests?file=".concat(t,"&exportName=").concat(e.exportName),children:[e.name,!!(null===(n=e.tests)||void 0===n?void 0:n.length)&&Object(c.jsxs)("div",{className:"ml-4 text-xs inline-flex items-center font-bold leading-sm uppercase px-3 py-1 rounded-full bg-white text-gray-700 border",children:[Object(c.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4 mr-2",children:Object(c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 5H7a2 2 0 00-2 2v12a2 2 0 002 2h10a2 2 0 002-2V7a2 2 0 00-2-2h-2M9 5a2 2 0 002 2h2a2 2 0 002-2M9 5a2 2 0 012-2h2a2 2 0 012 2m-3 7h3m-3 4h3m-6-4h.01M9 16h.01"})}),e.tests.length," test",e.tests.length>1&&"s"]}),!!e.error&&Object(c.jsxs)("div",{className:"ml-4 text-xs inline-flex items-center font-bold leading-sm uppercase px-3 py-1 bg-red-200 text-red-700 rounded-full",children:[Object(c.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"w-4 h-4 mr-2",children:Object(c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M12 8v4m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"})}),"Error"]})]},e.exportName)}))]})};!function(e){e[e.pending=0]="pending",e[e.loading=1]="loading",e[e.error=2]="error",e[e.loaded=3]="loaded"}(r||(r={}));function p(){var e=Object(j.useState)([]),t=Object(d.a)(e,2),n=t[0],o=t[1],s=Object(j.useState)(r.pending),i=Object(d.a)(s,2),a=i[0],l=i[1],f=Object(j.useState)([]),h=Object(d.a)(f,2),m=h[0],p=h[1],O=Object(j.useState)(r.pending),g=Object(d.a)(O,2),v=g[0],y=g[1],w=Object(j.useState)(!1),N=Object(d.a)(w,2),k=N[0],C=N[1];if(Object(j.useEffect)((function(){k&&(y(r.loading),fetch("/module-component").then((function(e){return e.json()})).then(p).then((function(){return y(r.loaded)})).catch((function(){return y(r.error)})))}),[k]),Object(j.useEffect)((function(){a!==r.loaded||n.length||C(!0)}),[a,n]),Object(j.useEffect)((function(){l(r.loading),fetch("/module-test").then((function(e){return e.json()})).then(o).then((function(){return l(r.loaded)})).catch((function(){return l(r.error)}))}),[]),a===r.loading)return Object(c.jsx)(b,{children:"Loading component tests..."});var S=function(e){var t=e.filter((function(e){return e.components.every((function(e){return e.error}))}));return[t,e.filter((function(e){var n=e.file;return!t.find((function(e){return e.file===n}))}))]}(function(e,t){return!e.length&&t.length?t:e.map((function(e){var n,r,c=t.find((function(t){return t.file===e.file}));return Object(u.a)(Object(u.a)({},e),{},{components:(n=e.components,r=c?c.components:[],n.map((function(e){return r.find((function(t){return t.exportName===e.exportName}))||e})))})}))}(m,n)),E=Object(d.a)(S,2),L=E[0],M=E[1];return Object(c.jsxs)("div",{className:"p-3",children:[Object(c.jsx)("h1",{className:"p-6 text-gray-700 text-2xl font-semibold py-2",children:"Your tests"}),M.map((function(e){return Object(c.jsx)(x,{file:e.file,components:e.components},e.file)})),a===r.loaded&&!n.length&&Object(c.jsx)("div",{className:"p-4 m-3 bg-white shadow-md rounded-2xl text-gray-700 text-lg",children:"You don't have any tests yet"}),v===r.loading&&Object(c.jsx)("div",{className:"p-6",children:Object(c.jsx)(b,{children:"Looking for components..."})}),!!L.length&&Object(c.jsx)("div",{className:"p-6 block text-gray-700 text-2xl font-semibold py-2",children:"Other modules which had errors"}),L.map((function(e){return Object(c.jsx)(x,{file:e.file,components:e.components},e.file)})),!k&&Object(c.jsx)("div",{className:"flex justify-center",children:Object(c.jsx)("button",{onClick:function(){return C(!0)},className:"shadow-md border-blue-700 text-blue-700 bg-white hover:border-transparent hover:text-white hover:bg-blue-700 font-medium py-2 px-4 rounded-full m-4",children:"Look for other components"})})]})}var O=n(19),g=n.n(O),v=function(e){var t=e.history,n=e.location.search,r=Object(j.useState)([]),o=Object(d.a)(r,2),s=o[0],i=o[1],a=Object(j.useState)(!0),l=Object(d.a)(a,2),u=l[0],f=l[1],h=Object(j.useState)({}),x=Object(d.a)(h,2),p=x[0],O=x[1],v=g.a.parse(n),y=v.file,w=v.exportName;return Object(j.useEffect)((function(){fetch("/test?file=".concat(y,"&exportName=").concat(w)).then((function(e){return e.json()})).then(i).finally((function(){return f(!1)}))}),[y,w]),Object(j.useEffect)((function(){s.length&&fetch("/test/status".concat(n)).then((function(e){return e.json()})).then(O)}),[s,n]),"string"!=typeof y||"string"!=typeof w?(t.replace("/"),null):u?Object(c.jsx)(b,{children:"Loading tests..."}):Object(c.jsxs)("div",{className:"p-3",children:[Object(c.jsxs)("h1",{className:"p-6 block text-gray-700 text-2xl font-semibold py-2",children:[y," / ",w]}),!s.length&&Object(c.jsx)("div",{className:"p-4 m-3 bg-white shadow-md rounded-2xl text-gray-700 text-lg",children:"You don't have any tests yet"}),!!s.length&&Object(c.jsx)("div",{className:"p-3 mx-3 my-4 bg-white shadow-md rounded-2xl",children:s.map((function(e){return Object(c.jsx)(m,{link:"/tests/".concat(e.id,"?file=").concat(y,"&exportName=").concat(w),status:p[e.id],children:e.name||e.id},e.id)}))}),Object(c.jsx)("div",{className:"flex justify-center",children:Object(c.jsx)("button",{className:"bg-gray-700 hover:bg-gray-800 text-white font-bold py-2 px-4 rounded-full shadow-md m-4",onClick:function(){return function(e,t,n){return fetch("/test?file=".concat(e,"&exportName=").concat(t),{method:"post"}).then((function(e){return e.json()})).then(n)}(y,w,(function(e){var n=e.id;return t.push("/tests/".concat(n,"?file=").concat(y,"&exportName=").concat(w))}))},children:"Add Test"})})]})},y=n(9),w=n(14);var N,k=function(e){var t=e.children;return Object(c.jsx)("h3",{className:"text-lg leading-6 font-medium text-gray-900",id:"modal-headline",children:t})},C=function(e){var t=e.children;return Object(c.jsx)("div",{className:"bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4",children:Object(c.jsx)("div",{className:"mt-3 sm:mt-0 text-left",children:t})})},S=function(e){var t=e.children;return Object(c.jsx)("div",{className:"bg-gray-100 px-4 py-3 sm:px-6 flex justify-end",children:t})},E=function(e){var t,n,r=e.children,o=e.onClose;return t="Escape",n=o,Object(j.useEffect)((function(){var e=function(e){e.key===t&&n()};return window.addEventListener("keydown",e),function(){window.removeEventListener("keydown",e)}}),[t,n]),Object(c.jsxs)("div",{className:"fixed bottom-0 inset-x-0 px-4 pb-4 sm:inset-0 sm:flex sm:items-center sm:justify-center",children:[Object(c.jsx)("div",{className:"fixed inset-0 transition-opacity",children:Object(c.jsx)("div",{className:"absolute inset-0 bg-gray-900 opacity-50",onClick:o})}),Object(c.jsx)("div",{className:"bg-white rounded-lg overflow-hidden shadow-xl transform transition-all sm:max-w-6xl sm:w-full",role:"dialog","aria-modal":"true","aria-labelledby":"modal-headline",children:r})]})},L=function(e){var t=e.region,n=e.onClose,r=e.onSelect;return Object(c.jsxs)(E,{onClose:n,children:[Object(c.jsx)(C,{children:Object(c.jsxs)(k,{children:[t.text," ",Object(c.jsx)("span",{className:"font-bold",children:t.type})]})}),Object(c.jsxs)(S,{children:[Object(c.jsx)("button",{className:"shadow-md bg-green-700 hover:bg-green-800 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",onClick:function(){return r({type:"assertion",definition:{type:"text",target:t.text}})},children:"Assert visible"}),Object(c.jsx)("button",{className:"shadow-md bg-blue-700 hover:bg-blue-800 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",onClick:function(){return r({type:"event",definition:{type:"click",target:t.text}})},children:"Click"})]})]})},M=n(30),R=function(e){var t=Object(M.a)(e),n=t[0],r=t.slice(1),c=r.length&&r[0].method?r[0].method:"get";return"".concat(c.toUpperCase()," ").concat(n)},z=function(e){var t=Object(d.a)(e.selectedMockCall,2),n=t[0],r=t[1],o=e.onClose,s=e.onUpdateStep;return Object(c.jsxs)(E,{onClose:o,children:[Object(c.jsx)(C,{children:Object(c.jsxs)(k,{children:[n," ",Object(c.jsx)("span",{className:"font-bold",children:R(r)})]})}),Object(c.jsxs)(S,{children:[Object(c.jsx)("button",{className:"shadow-md bg-green-700 hover:bg-green-800 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",onClick:function(){return s({type:"assertion",definition:{type:"mock",target:{name:n,args:r}}})},children:"Assert called"}),Object(c.jsx)("button",{className:"shadow-md bg-blue-700 hover:bg-blue-800 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",onClick:function(){return s({type:"mock",definition:{name:n,args:r,return:null}})},children:"Mock"})]})]})},A=n(34),J={render:function(){return"Render component"},event:function(e){var t=e.definition.target;return'Click on "'.concat(t,'"')},assertion:function(e){var t=e.definition,n=t.type,r=t.target;return"text"===n?'Assert "'.concat(r,'" is visible'):"Assert ".concat(n," ").concat(r.name," ").concat(R(r.args)," called")},mock:function(e){var t=e.definition,n=t.name,r=t.args;return"Mock ".concat(n," ").concat(R(r))}},T=function(e){return J[e.type]?J[e.type](e):function(e){return Object.entries(e).map((function(e){var t=Object(d.a)(e,2),n=t[0],r=t[1];return"".concat(n,": ").concat("object"==typeof r?JSON.stringify(r):r)})).join(", ")}(e)},W={render:function(){return"props"}},U=function(e){return W[e.type]?W[e.type](e):"Edit"},B=function(e){var t=e.step,n=e.result.result,r=e.selected,o=e.active,s=e.link,i=e.onDelete,a=e.onEdit,l=e.onEditWrapper,d=e.onResultClick,u=t.type;return Object(c.jsxs)(m,{link:s,status:n,subtitle:u,selected:r,active:o,onResultClick:d,children:[T(t),Object(c.jsxs)("div",{className:"block",children:[o&&["render","mock"].includes(u)&&Object(c.jsx)("button",{onClick:a,className:"text-xs font-semibold text-white hover:bg-white hover:text-gray-800 py-1 px-2 border border-whit rounded-full my-2 mr-2",children:U(t)}),o&&["render"].includes(u)&&Object(c.jsx)("button",{onClick:l,className:"text-xs font-semibold text-white hover:bg-white hover:text-gray-800 py-1 px-2 border border-whit rounded-full my-2 mr-2",children:"wrapper"}),o&&"render"!==u&&Object(c.jsx)("button",{onClick:i,className:"text-xs font-semibold text-red-600 hover:bg-red-600 hover:text-white py-1 px-2 border border-red-600 rounded-full my-2 mr-2",children:"Remove"})]})]})},H=["object","array"],D={number:function(e){return Object(c.jsx)("input",Object(u.a)({type:"number"},e))},boolean:function(e){return Object(c.jsxs)("select",Object(u.a)(Object(u.a)({},e),{},{children:[Object(c.jsx)("option",{value:"",disabled:!0,children:"boolean"}),Object(c.jsx)("option",{value:"true",children:"true"}),Object(c.jsx)("option",{value:"false",children:"false"})]}))},object:function(e){return Object(c.jsx)("textarea",Object(u.a)({},e))},array:function(e){return Object(c.jsx)("textarea",Object(u.a)({},e))},default:function(e){return Object(c.jsx)("input",Object(u.a)({type:"text"},e))},"[]$":function(e){return Object(c.jsx)("textarea",Object(u.a)({},e))},"^{":function(e){return Object(c.jsx)("textarea",Object(u.a)({},e))}},q=function(e){var t=e.propType,n=Object(A.a)(e,["propType"]),r=function(e){if(e in D)return D[e];var t=Object.keys(D).find((function(t){return new RegExp(t).test(e)}));return t?D[t]:D.default}(t);return Object(c.jsx)(r,Object(u.a)({},n))},I=function(e,t,n){return("string"===t||""!==e||!n)&&(!H.includes(t)||(""===e&&!n||function(e){try{return JSON.parse(e),!0}catch(t){return!1}}(e)))},_=function(e,t){return Object.entries(e).reduce((function(e,n){var r=Object(d.a)(n,2),c=r[0],o=r[1],s=Object(d.a)(t[c],1)[0];return Object(u.a)(Object(u.a)({},e),{},Object(y.a)({},c,F(o,s)))}),{})},F=function(e,t){if(H.includes(t)){if(""===e)return;try{return JSON.parse(e)}catch(n){return e}}if("number"===t){if(""===e)return;return parseInt(e,10)}if("boolean"===t)return void 0===e?e:"true"===e;try{return JSON.parse(e)}catch(r){return e}},P=function(e,t){if(H.includes(t))try{return JSON.stringify(e)}catch(n){return e}return["number","boolean"].includes(t)?void 0!==e?e.toString():e:"object"===typeof e?JSON.stringify(e):e};!function(e){e[e.loading=0]="loading",e[e.error=1]="error",e[e.loaded=2]="loaded"}(N||(N={}));var Y,K=function(e){var t=e.step,n=e.onClose,r=e.onUpdateStep,o=e.file,s=e.exportName,i=Object(j.useState)(),a=Object(d.a)(i,2),l=a[0],f=a[1],h=Object(j.useState)(),m=Object(d.a)(h,2),x=m[0],p=m[1],O=Object(j.useState)(),g=Object(d.a)(O,2),v=g[0],L=g[1],M=Object(j.useState)({}),R=Object(d.a)(M,2),z=R[0],A=R[1],J=Object(j.useState)(!1),W=Object(d.a)(J,2),U=W[0],B=W[1];return Object(j.useEffect)((function(){p(N.loading),fetch("/component/prop-types?file=".concat(o,"&exportName=").concat(s)).then((function(e){return e.json()})).then(f).then((function(){return p(N.loaded)})).catch((function(){return p(N.error)}))}),[o,s]),Object(j.useEffect)((function(){l&&L(function(e,t){return Object.entries(e).filter((function(e){var n=Object(d.a)(e,1)[0];return t[n]})).reduce((function(e,n){var r=Object(d.a)(n,2),c=r[0],o=r[1],s=Object(d.a)(t[c],1)[0];return Object(u.a)(Object(u.a)({},e),{},Object(y.a)({},c,P(o,s)))}),{})}(t.definition.props,l))}),[t.definition.props,l]),Object(j.useEffect)((function(){v&&l&&A(function(e,t){return Object.entries(t).reduce((function(t,n){var r=Object(d.a)(n,2),c=r[0],o=r[1];return Object(u.a)(Object(u.a)({},t),{},Object(y.a)({},c,I.apply(void 0,[e[c]].concat(Object(w.a)(o)))))}),{})}(v,l))}),[v,l]),Object(c.jsx)(E,{onClose:n,children:Object(c.jsxs)("form",{onSubmit:function(e){e.preventDefault(),Object.values(z).every((function(e){return e}))&&v&&l&&r(Object(u.a)(Object(u.a)({},t),{},{definition:Object(u.a)(Object(u.a)({},t.definition),{},{props:_(v,l)})}))},children:[Object(c.jsxs)(C,{children:[Object(c.jsxs)(k,{children:[T(t)," ",Object(c.jsx)("span",{className:"font-bold",children:"props"})]}),Object(c.jsxs)("div",{className:"mt-2",children:[x===N.loading&&Object(c.jsx)(b,{children:"Looking for the component's props..."}),x===N.error&&Object(c.jsx)("div",{className:"text-red-700",children:"There was an issue fetching this component's props"}),l?Object.entries(l).map((function(e){var t=Object(d.a)(e,2),n=t[0],r=Object(d.a)(t[1],2),o=r[0],s=r[1];return Object(c.jsxs)("div",{className:"mb-4",children:[Object(c.jsxs)("label",{className:"block text-gray-700 text-sm font-bold mb-2",htmlFor:n,children:[n,s&&Object(c.jsx)("span",{children:"*"})]}),Object(c.jsx)(q,{propType:o,className:"shadow appearance-none border rounded w-full py-2 px-3 text-gray-700 leading-tight focus:outline-none focus:shadow-outline ".concat(!z[n]&&U?"border-red-400":"border-gray-200"),id:n,placeholder:o,name:n,required:s,value:v&&v[n]||"",onChange:function(e){var t=e.target,n=t.name,r=t.value;L((function(e){return Object(u.a)(Object(u.a)({},e),{},Object(y.a)({},n,r))})),B(!0)}})]},n)})):null,l&&Object.entries(l).some((function(e){var t=Object(d.a)(e,2);return Object(d.a)(t[1],2)[1]}))&&Object(c.jsx)("p",{className:"text-sm leading-5 text-gray-500 text-right",children:"* Required prop"}),l&&0===Object.keys(l).length?Object(c.jsx)("p",{className:"text-sm leading-5 text-gray-500",children:"No props were found for this component."}):null]})]}),Object(c.jsxs)(S,{children:[Object(c.jsx)("button",{type:"button",onClick:n,className:"shadow-md bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",children:"Cancel"}),Object(c.jsx)("button",{type:"submit",className:"shadow-md border border-blue-700 hover:border-transparent text-blue-700 hover:text-white hover:bg-blue-700 font-medium py-2 px-4 rounded-full my-2 ml-2",children:"Save"})]})]})})},$=n(33),V=n(31),G=n.n(V),Q=function(e){var t=e.step,n=e.onClose,r=e.onUpdateStep,o=Object(j.useState)(t.definition.return?t.definition.return:{}),s=Object(d.a)(o,2),i=s[0],a=s[1],l=Object(j.useState)(!0),b=Object(d.a)(l,2),f=b[0],h=b[1];return Object(c.jsx)(E,{onClose:n,children:Object(c.jsxs)("form",{onSubmit:function(e){e.preventDefault(),f&&r(Object(u.a)(Object(u.a)({},t),{},{definition:Object(u.a)(Object(u.a)({},t.definition),{},{return:i})}))},children:[Object(c.jsxs)(C,{children:[Object(c.jsxs)(k,{children:[T(t)," ",Object(c.jsx)("span",{className:"font-bold",children:"return"})]}),Object(c.jsx)("div",{className:"mt-2 flex",children:Object(c.jsx)($.a,{id:"id",placeholder:t.definition.return,theme:"light_mitsuketa_tribute",locale:G.a,width:"100%",height:"550px",onChange:function(e){var t=e.error,n=e.jsObject;a(n),h(!1===t)},waitAfterKeyPress:0})})]}),Object(c.jsxs)(S,{children:[!f&&Object(c.jsx)("div",{className:"text-red-700 py-4 mr-auto",children:"JSON validation failed"}),Object(c.jsx)("button",{type:"button",onClick:n,className:"shadow-md bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded-full my-2 ml-2",children:"Cancel"}),Object(c.jsx)("button",{type:"submit",className:"shadow-md border border-blue-700 hover:border-transparent text-blue-700 hover:text-white hover:bg-blue-700 font-medium py-2 px-4 rounded-full my-2 ml-2",children:"Save"})]})]})})};!function(e){e[e.loading=0]="loading",e[e.error=1]="error",e[e.loaded=2]="loaded"}(Y||(Y={}));var X=function(e){var t=e.step,n=e.onClose,r=e.onUpdateStep,o=e.file,s=e.exportName,i=Object(j.useState)(),a=Object(d.a)(i,2),l=a[0],f=a[1],h=Object(j.useState)(),m=Object(d.a)(h,2),x=m[0],p=m[1];Object(j.useEffect)((function(){p(Y.loading),fetch("/component/wrapper").then((function(e){return e.json()})).then(f).then((function(){return p(Y.loaded)})).catch((function(){return p(Y.error)}))}),[o,s]);var O=t.definition.wrapper;return Object(c.jsxs)(E,{onClose:n,children:[Object(c.jsxs)(C,{children:[Object(c.jsxs)(k,{children:[T(t)," ",Object(c.jsx)("span",{className:"font-bold",children:"wrapper"})]}),Object(c.jsxs)("div",{className:"mt-2",children:[x===Y.loading&&Object(c.jsx)(b,{children:"Looking for wrapper options..."}),x===Y.error&&Object(c.jsx)("div",{className:"text-red-700",children:"There was an issue fetching wrapper options"}),l?l.map((function(e){var n=e.file,o=e.exportName;return Object(c.jsx)("div",{className:"mb-4",children:Object(c.jsxs)("button",{type:"button",onClick:function(){return function(e,n){var c,o;if(e===(null===(c=t.definition.wrapper)||void 0===c?void 0:c.file)&&n===(null===(o=t.definition.wrapper)||void 0===o?void 0:o.exportName))return r(Object(u.a)(Object(u.a)({},t),{},{definition:Object(u.a)(Object(u.a)({},t.definition),{},{wrapper:null})}));r(Object(u.a)(Object(u.a)({},t),{},{definition:Object(u.a)(Object(u.a)({},t.definition),{},{wrapper:{file:e,exportName:n,props:{}}})}))}(n,o)},className:"".concat(O&&O.file===n&&O.exportName===o?"bg-blue-700 text-white":"text-blue-700"," \n inline-flex items-center shadow-md border border-blue-700 hover:border-transparent hover:text-white hover:bg-blue-700 font-medium py-2 px-4 rounded-full my-2 mr-2"),children:[n,".",o,O&&O.file===n&&O.exportName===o&&Object(c.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",className:"ml-2 w-5 h-5",children:Object(c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M9 12l2 2 4-4m6 2a9 9 0 11-18 0 9 9 0 0118 0z"})})]})},n+o)})):null,l&&0===Object.keys(l).length?Object(c.jsx)("p",{className:"text-sm leading-5 text-gray-500",children:"No wrapper options were found."}):null]})]}),Object(c.jsx)(S,{children:Object(c.jsx)("button",{type:"button",onClick:n,className:"shadow-md border border-blue-700 hover:border-transparent text-blue-700 hover:text-white hover:bg-blue-700 font-medium py-2 px-4 rounded-full my-2 ml-2",children:"Done"})})]})},Z=function(e){var t=Object(d.a)(e.stepAndResult,2),n=t[0],r=t[1],o=r.result,s=r.error,i=e.onClose;return Object(c.jsxs)(E,{onClose:i,children:[Object(c.jsxs)(C,{children:[Object(c.jsxs)(k,{children:[T(n)," ",Object(c.jsx)("span",{className:"font-bold",children:o})]}),s&&Object.entries(s).map((function(e){var t,n=Object(d.a)(e,2),r=n[0],o=n[1];return Object(c.jsxs)(j.Fragment,{children:[Object(c.jsx)("h2",{className:"font-bold mt-2 mb-1",children:(t=r,t.charAt(0).toUpperCase()+t.slice(1))}),Object(c.jsx)("code",{className:"whitespace-pre-line text-xs",children:o})]},r)}))]}),Object(c.jsx)(S,{children:Object(c.jsx)("button",{className:"bg-red-600 hover:bg-red-700 text-white font-medium py-2 px-4 rounded-full my-2 mr-2",onClick:i,children:"Close"})})]})},ee=function(e){return e.charAt(0).toUpperCase()+e.slice(1)},te={fetch:"HTTP requests"},ne=function(e){var t=e.history,n=e.file,r=e.exportName,o=e.test,s=e.step,a=Object(j.useState)([]),l=Object(d.a)(a,2),f=l[0],h=l[1],m=Object(j.useState)([]),x=Object(d.a)(m,2),p=x[0],O=x[1],g=Object(j.useState)([]),v=Object(d.a)(g,2),N=v[0],k=v[1],C=Object(j.useState)([]),S=Object(d.a)(C,2),E=S[0],M=S[1],A=Object(j.useState)(),J=Object(d.a)(A,2),T=J[0],W=J[1],U=Object(j.useState)(),H=Object(d.a)(U,2),D=H[0],q=H[1],I=Object(j.useState)(),_=Object(d.a)(I,2),F=_[0],P=_[1],Y=Object(j.useState)(!1),$=Object(d.a)(Y,2),V=$[0],G=$[1],ne=Object(j.useState)(),re=Object(d.a)(ne,2),ce=re[0],oe=re[1],se=Object(j.useState)(),ie=Object(d.a)(se,2),ae=ie[0],le=ie[1],de=Object(j.useRef)(null);Object(j.useEffect)((function(){o&&s>f.length-1&&t.replace("/tests/".concat(o.id,"?file=").concat(n,"&exportName=").concat(r,"&step=").concat((f.length?f.length:o.steps.length)-1))}),[t,n,r,o,f,s]),Object(j.useEffect)((function(){h(o.steps)}),[o.steps]),Object(j.useEffect)((function(){f.length&&(G(!0),fetch("/test/".concat(o.id,"/render/side-effects?file=").concat(n,"&exportName=").concat(r,"&step=").concat(s)).then((function(e){return e.json()})).then((function(e){var t=e.regions,n=e.mocks;M(t),k(n)})).finally((function(){return G(!1)})))}),[n,r,o.id,s,f]),Object(j.useEffect)((function(){f.length&&fetch("/test/".concat(o.id,"/run?file=").concat(n,"&exportName=").concat(r)).then((function(e){return e.json()})).then(O)}),[n,r,o.id,f]);var ue,je=function(e){return fetch("/test/".concat(o.id,"/steps?file=").concat(n,"&exportName=").concat(r),{method:"put",body:JSON.stringify(e),headers:{"Content-Type":"application/json"}}).then((function(){return h(e)}))},be=function(e,c){var i=Object(w.a)(f);i.splice(c,0,e),je(i).then((function(){W(void 0),q(void 0),t.push("/tests/".concat(o.id,"?file=").concat(n,"&exportName=").concat(r,"&step=").concat(s+1))}))},fe=(ue=function(e){return e.type},E.reduce((function(e,t){return Object(u.a)(Object(u.a)({},e),{},Object(y.a)({},ue(t),[].concat(Object(w.a)(e[ue(t)]||[]),[t])))}),{})),he=F&&{render:K,mock:Q}[F.type],me=o&&(o.name||o.id);return Object(c.jsxs)("div",{className:"flex",children:[Object(c.jsxs)("div",{className:"md:w-1/2 p-3",children:[Object(c.jsxs)("div",{className:"px-6 py-2 flex items-center text-gray-700 text-2xl font-semibold",children:[Object(c.jsx)("h1",{contentEditable:!0,onBlur:function(e){var t=e.target.textContent;t&&function(e){fetch("/test/".concat(o.id,"/name?file=").concat(n,"&exportName=").concat(r),{method:"put",body:JSON.stringify({name:e}),headers:{"Content-Type":"application/json"}})}(t)},onKeyPress:function(e){var t;"Enter"===e.key&&(e.preventDefault(),null===(t=e.target)||void 0===t||t.blur())},ref:de,suppressContentEditableWarning:!0,children:me})," ",Object(c.jsx)("svg",{xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor",className:"w-5 h-5 ml-2 cursor-pointer",onClick:function(){return de.current&&function(e){var t=document.createRange();t.selectNodeContents(e);var n=window.getSelection();n&&(n.removeAllRanges(),n.addRange(t))}(de.current)},children:Object(c.jsx)("path",{strokeLinecap:"round",strokeLinejoin:"round",strokeWidth:2,d:"M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"})})]}),Object(c.jsxs)("h2",{className:"px-6 pb-2 flex items-center text-gray-700 font-semibold",children:[n," /",Object(c.jsx)(i.b,{to:"/tests/?file=".concat(n,"&exportName=").concat(r),className:"underline ml-1",children:r})]}),V&&Object(c.jsx)(b,{children:"Rendering..."}),!!E.length&&!V&&Object(c.jsx)("div",{className:"p-3 m-3 bg-white shadow-md rounded-2xl",children:Object.entries(fe).map((function(e){var t=Object(d.a)(e,2),n=t[0],r=t[1];return Object(c.jsxs)(j.Fragment,{children:[Object(c.jsx)("h3",{className:"text-xl p-2",children:ee(n)}),r.map((function(e){return Object(c.jsx)("button",{className:"text-gray-700 hover:text-gray-600 hover:bg-gray-100 py-2 px-4 my-2 rounded-full focus:rounded-full w-full text-left",onClick:function(){return W(e)},children:e.text+(e.unique?"":" (not unique)")},"".concat(e.xpath).concat(e.text))}))]},"".concat(n))}))}),!!N.filter((function(e){return e.calls.length})).length&&!V&&Object(c.jsx)("div",{className:"p-3 m-3 bg-white shadow-md rounded-2xl",children:N.filter((function(e){return e.calls.length})).map((function(e,t){var n,r=e.name,o=e.calls;return Object(c.jsxs)(j.Fragment,{children:[Object(c.jsx)("h3",{className:"text-xl p-2",children:(n=r,te[n]?te[n]:ee(n))}),o.map((function(e,t){return Object(c.jsx)("button",{className:"text-gray-700 hover:text-gray-600 hover:bg-gray-100 py-2 px-4 my-2 rounded-full focus:rounded-full w-full text-left",onClick:function(){return q([r,e])},children:R(e)},[t].concat(Object(w.a)(e)).join(""))}))]},"".concat(r).concat(t))}))}),T&&Object(c.jsx)(L,{region:T,onSelect:function(e){return be(e,s+1)},onClose:function(){return W(void 0)}}),D&&Object(c.jsx)(z,{selectedMockCall:D,onUpdateStep:function(e){return be(e,"mock"===e.type?0:s+1)},onClose:function(){return q(void 0)}}),F&&he&&Object(c.jsx)(he,{step:F,onUpdateStep:function(e){return t=e,n=f.indexOf(F),je(f.map((function(e,r){return r===n?t:e}))).then((function(){return P(void 0)}));var t,n},onClose:function(){return P(void 0)},file:n,exportName:r}),ce&&Object(c.jsx)(X,{step:ce,onUpdateStep:function(e){return t=e,n=f.indexOf(ce),oe(t),void je(f.map((function(e,r){return r===n?t:e}))).then((function(){return P(void 0)}));var t,n},onClose:function(){return oe(void 0)},file:n,exportName:r}),ae&&Object(c.jsx)(Z,{stepAndResult:ae,onClose:function(){return le(void 0)}})]}),Object(c.jsx)("div",{className:"md:w-1/2 p-6 pl-1",children:Object(c.jsx)("div",{className:"my-2",children:f.map((function(e,i){return Object(c.jsx)(B,{step:e,result:p[i]||{},selected:i<=(null===s?p.length-1:s),active:i===s,link:"/tests/".concat(o.id,"?file=").concat(n,"&exportName=").concat(r,"&step=").concat(i),onDelete:function(){return e=i,je(f.filter((function(t,n){return n!==e}))).then((function(){W(void 0),t.replace("/tests/".concat(o.id,"?file=").concat(n,"&exportName=").concat(r,"&step=").concat(s))}));var e},onEdit:function(){return P(f[i])},onEditWrapper:function(){return oe(f[i])},onResultClick:p[i]&&"error"===p[i].result?function(){return le([e,p[i]])}:void 0},i)}))})})]})},re=function(e){var t=e.match.params.testId,n=e.location.search,r=e.history,o=Object(j.useState)(),s=Object(d.a)(o,2),i=s[0],a=s[1],l=g.a.parse(n),u=l.file,f=l.exportName,h=l.step,m="string"===typeof h?parseInt(h,10):null;return Object(j.useEffect)((function(){i&&null===m&&r.replace("/tests/".concat(i.id,"?file=").concat(u,"&exportName=").concat(f,"&step=").concat(i.steps.length-1))}),[r,u,f,i,m]),Object(j.useEffect)((function(){fetch("/test/".concat(t,"?file=").concat(u,"&exportName=").concat(f)).then((function(e){return e.json()})).then(a)}),[t,u,f]),"string"!=typeof u||"string"!=typeof f?(r.replace("/"),null):i&&null!==m?Object(c.jsx)(ne,{history:r,file:u,exportName:f,test:i,step:m}):Object(c.jsx)(b,{children:"Loading test..."})},ce=n(32),oe=n.n(ce),se=function(){return Object(c.jsx)(i.a,{children:Object(c.jsxs)("div",{className:"md:flex flex-col md:flex-row md:min-h-screen w-full h-screen bg-gray-100 ".concat(oe.a.bg),children:[Object(c.jsx)(l,{}),Object(c.jsx)("div",{className:"md:w-5/6 overflow-auto",children:Object(c.jsxs)(a.c,{children:[Object(c.jsx)(a.a,{path:"/tests/:testId",component:re}),Object(c.jsx)(a.a,{path:"/tests",component:v}),Object(c.jsx)(a.a,{path:"/",component:p})]})})]})})};Boolean("localhost"===window.location.hostname||"[::1]"===window.location.hostname||window.location.hostname.match(/^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/));s.a.render(Object(c.jsx)(se,{}),document.getElementById("root")),"serviceWorker"in navigator&&navigator.serviceWorker.ready.then((function(e){e.unregister()}))}},[[58,1,2]]]); //# sourceMappingURL=main.e7968c1b.chunk.js.map