@botbuddy/react 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function W(e,p){let[f,S]=react.useState({x:e,y:p}),x=react.useRef(false),m=react.useRef({x:0,y:0}),h=react.useRef(false),w=react.useCallback(c=>{x.current=true,h.current=false,m.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),s=react.useCallback(c=>{x.current&&(h.current=true,S({x:c.clientX-m.current.x,y:c.clientY-m.current.y}));},[]),u=react.useCallback(()=>{x.current=false;},[]);return {pos:f,onPointerDown:w,onPointerMove:s,onPointerUp:u,didDrag:h}}function N(e){let[p,f]=react.useState(null),[S,x]=react.useState("loading"),m=react.useCallback(async()=>{try{let s=new URLSearchParams;e.testRunId&&s.set("test_run_id",e.testRunId),e.targetUrl&&s.set("target_url",e.targetUrl),s.set("app_slug",e.appSlug),s.set("environment",e.environment),e.version&&s.set("version",e.version),e.commitSha&&s.set("commit_sha",e.commitSha),e.branchName&&s.set("branch_name",e.branchName);let u=await fetch(`${e.config.serverUrl}/widget/test-run?${s.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(u.status===404){x("no-match"),f(null);return}if(!u.ok){x("error");return}let c=await u.json();f(c),x(c.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return react.useEffect(()=>{m();},[m]),{run:p,widgetState:S,fetchRun:m,setVerdict:async(s,u,c,M="human")=>{let b=await fetch(`${e.config.serverUrl}/widget/test-cases/${s}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:u,fail_reason:c,display_name:M})});if(b.ok){let{summary:k}=await b.json();f(y=>y?{...y,summary:k,test_cases:y.test_cases.map(v=>v.id===s?{...v,verdict:u,fail_reason:u==="fail"&&c||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:v)}:null);}return b.ok},markComplete:async()=>{if(!p)return false;let s=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return s.ok&&m(),s.ok},setRun:f}}var g=({d:e,className:p})=>jsxRuntime.jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),l={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var re={pending:l.circle,pass:l.check,fail:l.x,skip:l.skip},F={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},i={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"},card:e=>({width:`${e}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:e=>{let p=F[e]||F.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}};function oe({config:e,appSlug:p,environment:f,testRunId:S,targetUrl:x,version:m,commitSha:h,branchName:w,onNavigate:s,displayName:u="human",defaultMode:c="mini",defaultPosition:M}){let[b,k]=react.useState(c),[y,v]=react.useState(""),[Y,P]=react.useState(null),[L,V]=react.useState(null),j=M?.x??16,X=M?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:$,onPointerDown:z,onPointerMove:B,onPointerUp:D,didDrag:H}=W(j,X),{run:o,widgetState:_,fetchRun:J,setVerdict:A,markComplete:Z}=N({config:e,appSlug:p,environment:f,testRunId:S,targetUrl:x,version:m,commitSha:h,branchName:w}),R=react.useCallback(async(t,a,G)=>{V(t);try{await A(t,a,G,u);}finally{V(null),P(null),v("");}},[A,u]),d=o?.summary||{total:0,pending:0,pass:0,fail:0},q=d.total>0&&d.pending===0,K=d.total>0?(d.pass+d.fail)/d.total*100:0;if(_==="no-match"||_==="loading")return null;let E=()=>{H.current||k(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},C=({icon:t,onClick:a})=>jsxRuntime.jsx("button",{style:i.btn,onClick:a,children:jsxRuntime.jsx(g,{d:t,className:""})});return jsxRuntime.jsxs("div",{style:{...i.root,left:$.x,top:$.y},children:[b==="mini"&&jsxRuntime.jsxs("div",{style:i.pill,onPointerDown:z,onPointerMove:B,onPointerUp:()=>{D(),H.current||E();},children:[jsxRuntime.jsx(g,{d:l.clipboard,className:""}),jsxRuntime.jsxs("span",{children:[d.pass,"/",d.total]}),d.fail>0&&jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:t=>t.stopPropagation(),style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:l.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:t=>t.stopPropagation(),style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:l.ticket,className:""}),o.ticket_id||"TKT"]})]}),b==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:z,onPointerMove:B,onPointerUp:D,children:[jsxRuntime.jsx(g,{d:l.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),jsxRuntime.jsxs("div",{style:i.sub,children:[jsxRuntime.jsx("span",{style:i.badge(o?.environment||"custom"),children:o?.environment}),o?.branch_name&&jsxRuntime.jsxs("span",{children:["\u2387 ",o.branch_name]})]})]}),jsxRuntime.jsx(C,{icon:l.chevronUp,onClick:E}),jsxRuntime.jsx(C,{icon:l.minus,onClick:()=>k("mini")})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[d.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[d.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:d.total})]}),o?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",maxHeight:"64px",overflowY:"auto"},children:o.description}),(o?.ticket_url||o?.pr_url)&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[o?.pr_url&&jsxRuntime.jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:l.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:l.ticket,className:""}),o.ticket_id||"Ticket"]})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(K)})})]}),b==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(340),maxHeight:"70vh"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:z,onPointerMove:B,onPointerUp:D,children:[jsxRuntime.jsx(g,{d:l.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),jsxRuntime.jsxs("div",{style:i.sub,children:[jsxRuntime.jsx("span",{style:i.badge(o?.environment||"custom"),children:o?.environment}),o?.created_by_agent_name&&jsxRuntime.jsxs("span",{children:["by ",o.created_by_agent_name]})]})]}),jsxRuntime.jsx(C,{icon:l.chevronDown,onClick:()=>k("expanded")}),jsxRuntime.jsx(C,{icon:l.minus,onClick:()=>k("mini")})]}),jsxRuntime.jsxs("div",{style:i.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[d.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[d.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:d.total})]}),_==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(g,{d:l.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:J,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),_==="completed"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[jsxRuntime.jsx(g,{d:l.checkAll,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"})]}),o?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",maxHeight:"48px",overflowY:"auto"},children:o.intro_notes}),_!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(t=>jsxRuntime.jsxs("div",{style:i.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0},children:L===t.id?jsxRuntime.jsx(g,{d:l.loader,className:""}):jsxRuntime.jsx(g,{d:re[t.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:t.title}),t.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:t.description}),t.url_path&&jsxRuntime.jsxs("a",{href:t.url_path,onClick:a=>{a.preventDefault(),a.stopPropagation(),s?s(t.url_path):window.open(t.url_path,"_blank");},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:0,marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:l.externalLink,className:""}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(a=>jsxRuntime.jsx("button",{onClick:()=>{if(a==="fail"&&t.verdict!=="fail"){P(t.id);return}if(t.verdict===a){R(t.id,"pending");return}R(t.id,a);},disabled:L!==null,style:i.verdictBtn(t.verdict===a,a==="pass"?"#34d399":a==="fail"?"#f87171":"#f59e0b"),children:a.toUpperCase()},a)),t.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),Y===t.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:y,onChange:a=>v(a.target.value),onKeyDown:a=>{a.key==="Enter"&&R(t.id,"fail",y),a.key==="Escape"&&(P(null),v(""));},placeholder:"Reason...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>R(t.id,"fail",y),style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),q&&_!=="completed"&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Z,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(K)})})]})]})}exports.TestRunWidget=oe;exports.useDraggable=W;exports.useTestRun=N;
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function W(e,p){let[f,_]=react.useState({x:e,y:p}),x=react.useRef(false),m=react.useRef({x:0,y:0}),h=react.useRef(false),w=react.useCallback(c=>{x.current=true,h.current=false,m.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),l=react.useCallback(c=>{x.current&&(h.current=true,_({x:c.clientX-m.current.x,y:c.clientY-m.current.y}));},[]),u=react.useCallback(()=>{x.current=false;},[]);return {pos:f,onPointerDown:w,onPointerMove:l,onPointerUp:u,didDrag:h}}function L(e){let[p,f]=react.useState(null),[_,x]=react.useState("loading"),m=react.useCallback(async()=>{try{let l=new URLSearchParams;e.testRunId&&l.set("test_run_id",e.testRunId),e.targetUrl&&l.set("target_url",e.targetUrl),l.set("app_slug",e.appSlug),l.set("environment",e.environment),e.version&&l.set("version",e.version),e.commitSha&&l.set("commit_sha",e.commitSha),e.branchName&&l.set("branch_name",e.branchName);let u=await fetch(`${e.config.serverUrl}/widget/test-run?${l.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(u.status===404){x("no-match"),f(null);return}if(!u.ok){x("error");return}let c=await u.json();f(c),x(c.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return react.useEffect(()=>{m();},[m]),{run:p,widgetState:_,fetchRun:m,setVerdict:async(l,u,c,M="human")=>{let b=await fetch(`${e.config.serverUrl}/widget/test-cases/${l}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:u,fail_reason:c,display_name:M})});if(b.ok){let{summary:k}=await b.json();f(y=>y?{...y,summary:k,test_cases:y.test_cases.map(v=>v.id===l?{...v,verdict:u,fail_reason:u==="fail"&&c||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:v)}:null);}return b.ok},markComplete:async()=>{if(!p)return false;let l=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return l.ok&&m(),l.ok},setRun:f}}var g=({d:e,className:p})=>jsxRuntime.jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsxRuntime.jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var re={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},F={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},o={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"},card:e=>({width:`${e}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:e=>{let p=F[e]||F.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}};function ie({config:e,appSlug:p,environment:f,testRunId:_,targetUrl:x,version:m,commitSha:h,branchName:w,onNavigate:l,displayName:u="human",defaultMode:c="mini",defaultPosition:M}){let[b,k]=react.useState(c),[y,v]=react.useState(""),[Y,P]=react.useState(null),[N,V]=react.useState(null),j=M?.x??16,X=M?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:$,onPointerDown:z,onPointerMove:B,onPointerUp:I,didDrag:H}=W(j,X),{run:i,widgetState:S,fetchRun:J,setVerdict:E,markComplete:Z}=L({config:e,appSlug:p,environment:f,testRunId:_,targetUrl:x,version:m,commitSha:h,branchName:w}),R=react.useCallback(async(r,s,G)=>{V(r);try{await E(r,s,G,u);}finally{V(null),P(null),v("");}},[E,u]),a=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},q=a.total>0&&a.pending===0,A=a.total>0?(a.pass+a.fail)/a.total*100:0;if(S==="no-match"||S==="loading")return null;let K=()=>{H.current||k(r=>r==="mini"||r==="expanded"?"max":"mini");},C=({icon:r,onClick:s})=>jsxRuntime.jsx("button",{style:o.btn,onClick:s,children:jsxRuntime.jsx(g,{d:r,className:""})});return jsxRuntime.jsxs("div",{style:{...o.root,left:$.x,top:$.y},children:[b==="mini"&&jsxRuntime.jsxs("div",{style:o.pill,onPointerDown:z,onPointerMove:B,onPointerUp:()=>{I(),H.current||K();},children:[jsxRuntime.jsx(g,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{children:[a.pass,"/",a.total]}),a.fail>0&&jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),a.skip>0&&jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),i?.pr_url&&jsxRuntime.jsxs("span",{style:{...o.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxRuntime.jsxs("span",{style:{...o.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),i.ticket_id||"TKT"]})]}),b==="expanded"&&jsxRuntime.jsxs("div",{style:o.card(300),children:[jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:z,onPointerMove:B,onPointerUp:I,children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:o.title,children:i?.title}),i?.branch_name&&jsxRuntime.jsxs("div",{style:o.sub,children:["\u2387 ",i.branch_name]})]}),jsxRuntime.jsx(C,{icon:d.chevronUp,onClick:K}),jsxRuntime.jsx(C,{icon:d.minus,onClick:()=>k("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[a.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[a.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:a.total})]}),i?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",maxHeight:"64px",overflowY:"auto"},children:i.description}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[i?.pr_url&&jsxRuntime.jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxRuntime.jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(A)})})]}),b==="max"&&jsxRuntime.jsxs("div",{style:{...o.card(340),maxHeight:"70vh"},children:[jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:z,onPointerMove:B,onPointerUp:I,children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:o.title,children:i?.title}),jsxRuntime.jsxs("div",{style:o.sub,children:[jsxRuntime.jsx("span",{style:o.badge(i?.environment||"custom"),children:i?.environment}),i?.created_by_agent_name&&jsxRuntime.jsxs("span",{children:["by ",i.created_by_agent_name]})]})]}),jsxRuntime.jsx(C,{icon:d.chevronDown,onClick:()=>k("expanded")}),jsxRuntime.jsx(C,{icon:d.minus,onClick:()=>k("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[a.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[a.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:a.total})]}),S==="error"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsxRuntime.jsx(g,{d:d.alert,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsxRuntime.jsx("button",{onClick:J,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S==="completed"&&jsxRuntime.jsxs("div",{style:{padding:"12px",textAlign:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[jsxRuntime.jsx(g,{d:d.checkAll,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"})]}),i?.intro_notes&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",maxHeight:"48px",overflowY:"auto"},children:i.intro_notes}),S!=="error"&&jsxRuntime.jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(i?.test_cases||[]).length===0?jsxRuntime.jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(i?.test_cases||[]).map(r=>jsxRuntime.jsxs("div",{style:o.caseRow,children:[jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsxRuntime.jsx("div",{style:{marginTop:"2px",flexShrink:0},children:N===r.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:re[r.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:r.title}),r.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:r.description}),r.url_path&&jsxRuntime.jsxs("a",{href:r.url_path,onClick:s=>{s.preventDefault(),s.stopPropagation(),l?l(r.url_path):window.open(r.url_path,"_blank");},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:0,marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.externalLink,className:""}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxRuntime.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(s=>jsxRuntime.jsx("button",{onClick:()=>{if(s==="fail"&&r.verdict!=="fail"){P(r.id);return}if(r.verdict===s){R(r.id,"pending");return}R(r.id,s);},disabled:N!==null,style:o.verdictBtn(r.verdict===s,s==="pass"?"#34d399":s==="fail"?"#f87171":"#f59e0b"),children:s.toUpperCase()},s)),r.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:r.verdict_by_display_name})]}),Y===r.id&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:y,onChange:s=>v(s.target.value),onKeyDown:s=>{s.key==="Enter"&&R(r.id,"fail",y),s.key==="Escape"&&(P(null),v(""));},placeholder:"Reason...",style:o.input}),jsxRuntime.jsx("button",{onClick:()=>R(r.id,"fail",y),style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},r.id))}),q&&S!=="completed"&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsxRuntime.jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsxRuntime.jsx("button",{onClick:Z,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(A)})})]})]})}exports.TestRunWidget=ie;exports.useDraggable=W;exports.useTestRun=L;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function W(e,p){let[f,S]=useState({x:e,y:p}),x=useRef(false),m=useRef({x:0,y:0}),h=useRef(false),w=useCallback(c=>{x.current=true,h.current=false,m.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),s=useCallback(c=>{x.current&&(h.current=true,S({x:c.clientX-m.current.x,y:c.clientY-m.current.y}));},[]),u=useCallback(()=>{x.current=false;},[]);return {pos:f,onPointerDown:w,onPointerMove:s,onPointerUp:u,didDrag:h}}function N(e){let[p,f]=useState(null),[S,x]=useState("loading"),m=useCallback(async()=>{try{let s=new URLSearchParams;e.testRunId&&s.set("test_run_id",e.testRunId),e.targetUrl&&s.set("target_url",e.targetUrl),s.set("app_slug",e.appSlug),s.set("environment",e.environment),e.version&&s.set("version",e.version),e.commitSha&&s.set("commit_sha",e.commitSha),e.branchName&&s.set("branch_name",e.branchName);let u=await fetch(`${e.config.serverUrl}/widget/test-run?${s.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(u.status===404){x("no-match"),f(null);return}if(!u.ok){x("error");return}let c=await u.json();f(c),x(c.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return useEffect(()=>{m();},[m]),{run:p,widgetState:S,fetchRun:m,setVerdict:async(s,u,c,M="human")=>{let b=await fetch(`${e.config.serverUrl}/widget/test-cases/${s}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:u,fail_reason:c,display_name:M})});if(b.ok){let{summary:k}=await b.json();f(y=>y?{...y,summary:k,test_cases:y.test_cases.map(v=>v.id===s?{...v,verdict:u,fail_reason:u==="fail"&&c||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:v)}:null);}return b.ok},markComplete:async()=>{if(!p)return false;let s=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return s.ok&&m(),s.ok},setRun:f}}var g=({d:e,className:p})=>jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),l={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var re={pending:l.circle,pass:l.check,fail:l.x,skip:l.skip},F={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},i={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"},card:e=>({width:`${e}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:e=>{let p=F[e]||F.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}};function oe({config:e,appSlug:p,environment:f,testRunId:S,targetUrl:x,version:m,commitSha:h,branchName:w,onNavigate:s,displayName:u="human",defaultMode:c="mini",defaultPosition:M}){let[b,k]=useState(c),[y,v]=useState(""),[Y,P]=useState(null),[L,V]=useState(null),j=M?.x??16,X=M?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:$,onPointerDown:z,onPointerMove:B,onPointerUp:D,didDrag:H}=W(j,X),{run:o,widgetState:_,fetchRun:J,setVerdict:A,markComplete:Z}=N({config:e,appSlug:p,environment:f,testRunId:S,targetUrl:x,version:m,commitSha:h,branchName:w}),R=useCallback(async(t,a,G)=>{V(t);try{await A(t,a,G,u);}finally{V(null),P(null),v("");}},[A,u]),d=o?.summary||{total:0,pending:0,pass:0,fail:0},q=d.total>0&&d.pending===0,K=d.total>0?(d.pass+d.fail)/d.total*100:0;if(_==="no-match"||_==="loading")return null;let E=()=>{H.current||k(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},C=({icon:t,onClick:a})=>jsx("button",{style:i.btn,onClick:a,children:jsx(g,{d:t,className:""})});return jsxs("div",{style:{...i.root,left:$.x,top:$.y},children:[b==="mini"&&jsxs("div",{style:i.pill,onPointerDown:z,onPointerMove:B,onPointerUp:()=>{D(),H.current||E();},children:[jsx(g,{d:l.clipboard,className:""}),jsxs("span",{children:[d.pass,"/",d.total]}),d.fail>0&&jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",onClick:t=>t.stopPropagation(),style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:l.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",onClick:t=>t.stopPropagation(),style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:l.ticket,className:""}),o.ticket_id||"TKT"]})]}),b==="expanded"&&jsxs("div",{style:i.card(300),children:[jsxs("div",{style:i.handle,onPointerDown:z,onPointerMove:B,onPointerUp:D,children:[jsx(g,{d:l.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),jsxs("div",{style:i.sub,children:[jsx("span",{style:i.badge(o?.environment||"custom"),children:o?.environment}),o?.branch_name&&jsxs("span",{children:["\u2387 ",o.branch_name]})]})]}),jsx(C,{icon:l.chevronUp,onClick:E}),jsx(C,{icon:l.minus,onClick:()=>k("mini")})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[d.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),jsxs("span",{style:{color:"#888"},children:[d.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:d.total})]}),o?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",maxHeight:"64px",overflowY:"auto"},children:o.description}),(o?.ticket_url||o?.pr_url)&&jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:l.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("a",{href:o.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:l.ticket,className:""}),o.ticket_id||"Ticket"]})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(K)})})]}),b==="max"&&jsxs("div",{style:{...i.card(340),maxHeight:"70vh"},children:[jsxs("div",{style:i.handle,onPointerDown:z,onPointerMove:B,onPointerUp:D,children:[jsx(g,{d:l.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),jsxs("div",{style:i.sub,children:[jsx("span",{style:i.badge(o?.environment||"custom"),children:o?.environment}),o?.created_by_agent_name&&jsxs("span",{children:["by ",o.created_by_agent_name]})]})]}),jsx(C,{icon:l.chevronDown,onClick:()=>k("expanded")}),jsx(C,{icon:l.minus,onClick:()=>k("mini")})]}),jsxs("div",{style:i.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[d.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[d.fail,"\u2717"]}),jsxs("span",{style:{color:"#888"},children:[d.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:d.total})]}),_==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(g,{d:l.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsx("button",{onClick:J,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),_==="completed"&&jsxs("div",{style:{padding:"12px",textAlign:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[jsx(g,{d:l.checkAll,className:""}),jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"})]}),o?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",maxHeight:"48px",overflowY:"auto"},children:o.intro_notes}),_!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(o?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(o?.test_cases||[]).map(t=>jsxs("div",{style:i.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0},children:L===t.id?jsx(g,{d:l.loader,className:""}):jsx(g,{d:re[t.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:t.title}),t.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:t.description}),t.url_path&&jsxs("a",{href:t.url_path,onClick:a=>{a.preventDefault(),a.stopPropagation(),s?s(t.url_path):window.open(t.url_path,"_blank");},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:0,marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none"},children:[jsx(g,{d:l.externalLink,className:""}),t.url_path]}),t.verdict==="fail"&&t.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",t.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(a=>jsx("button",{onClick:()=>{if(a==="fail"&&t.verdict!=="fail"){P(t.id);return}if(t.verdict===a){R(t.id,"pending");return}R(t.id,a);},disabled:L!==null,style:i.verdictBtn(t.verdict===a,a==="pass"?"#34d399":a==="fail"?"#f87171":"#f59e0b"),children:a.toUpperCase()},a)),t.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),Y===t.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:y,onChange:a=>v(a.target.value),onKeyDown:a=>{a.key==="Enter"&&R(t.id,"fail",y),a.key==="Escape"&&(P(null),v(""));},placeholder:"Reason...",style:i.input}),jsx("button",{onClick:()=>R(t.id,"fail",y),style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),q&&_!=="completed"&&jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsx("button",{onClick:Z,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",cursor:"pointer"},children:"COMPLETE"})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(K)})})]})]})}export{oe as TestRunWidget,W as useDraggable,N as useTestRun};
|
|
1
|
+
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function W(e,p){let[f,_]=useState({x:e,y:p}),x=useRef(false),m=useRef({x:0,y:0}),h=useRef(false),w=useCallback(c=>{x.current=true,h.current=false,m.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),l=useCallback(c=>{x.current&&(h.current=true,_({x:c.clientX-m.current.x,y:c.clientY-m.current.y}));},[]),u=useCallback(()=>{x.current=false;},[]);return {pos:f,onPointerDown:w,onPointerMove:l,onPointerUp:u,didDrag:h}}function L(e){let[p,f]=useState(null),[_,x]=useState("loading"),m=useCallback(async()=>{try{let l=new URLSearchParams;e.testRunId&&l.set("test_run_id",e.testRunId),e.targetUrl&&l.set("target_url",e.targetUrl),l.set("app_slug",e.appSlug),l.set("environment",e.environment),e.version&&l.set("version",e.version),e.commitSha&&l.set("commit_sha",e.commitSha),e.branchName&&l.set("branch_name",e.branchName);let u=await fetch(`${e.config.serverUrl}/widget/test-run?${l.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});if(u.status===404){x("no-match"),f(null);return}if(!u.ok){x("error");return}let c=await u.json();f(c),x(c.status==="completed"?"completed":"ready");}catch{x("error");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.branchName]);return useEffect(()=>{m();},[m]),{run:p,widgetState:_,fetchRun:m,setVerdict:async(l,u,c,M="human")=>{let b=await fetch(`${e.config.serverUrl}/widget/test-cases/${l}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:u,fail_reason:c,display_name:M})});if(b.ok){let{summary:k}=await b.json();f(y=>y?{...y,summary:k,test_cases:y.test_cases.map(v=>v.id===l?{...v,verdict:u,fail_reason:u==="fail"&&c||null,verdict_by_display_name:M,verdict_at:new Date().toISOString()}:v)}:null);}return b.ok},markComplete:async()=>{if(!p)return false;let l=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return l.ok&&m(),l.ok},setRun:f}}var g=({d:e,className:p})=>jsx("svg",{className:p,width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:jsx("path",{d:e})}),d={clipboard:"M9 5H7a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V7a2 2 0 0 0-2-2h-2M9 5a2 2 0 0 0 2 2h2a2 2 0 0 0 2-2M9 5a2 2 0 0 1 2-2h2a2 2 0 0 1 2 2",check:"M22 11.08V12a10 10 0 1 1-5.93-9.14M22 4 12 14.01l-3-3",x:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20M15 9l-6 6M9 9l6 6",circle:"M12 2a10 10 0 1 0 0 20 10 10 0 0 0 0-20",skip:"M5 4l10 8-10 8V4M19 5v14",grip:"M9 5h.01M15 5h.01M9 12h.01M15 12h.01M9 19h.01M15 19h.01",minus:"M5 12h14",chevronUp:"M18 15l-6-6-6 6",chevronDown:"M6 9l6 6 6-6",externalLink:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6M15 3h6v6M10 14L21 3",pr:"M6 3v18M18 9a3 3 0 1 0 0-6 3 3 0 0 0 0 6M6 21a3 3 0 1 0 0-6 3 3 0 0 0 0 6M18 9a9 9 0 0 1-9 9",ticket:"M2 9a3 3 0 0 1 0 6v2a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-2a3 3 0 0 1 0-6V7a2 2 0 0 0-2-2H4a2 2 0 0 0-2 2Z",loader:"M21 12a9 9 0 1 1-6.219-8.56",checkAll:"M18 6L7 17l-5-5M22 10l-7.5 7.5L13 16",alert:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0M12 9v4M12 17h.01"};var re={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},F={local:{bg:"rgba(59,130,246,0.15)",text:"#60a5fa",border:"rgba(59,130,246,0.3)"},preview:{bg:"rgba(168,85,247,0.15)",text:"#c084fc",border:"rgba(168,85,247,0.3)"},staging:{bg:"rgba(245,158,11,0.15)",text:"#fbbf24",border:"rgba(245,158,11,0.3)"},production:{bg:"rgba(239,68,68,0.15)",text:"#f87171",border:"rgba(239,68,68,0.3)"},custom:{bg:"rgba(128,128,128,0.15)",text:"#888",border:"rgba(128,128,128,0.3)"}},o={root:{position:"fixed",zIndex:9999,userSelect:"none",fontFamily:"ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace"},pill:{display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"},card:e=>({width:`${e}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:"1px solid rgba(255,255,255,0.15)",boxShadow:"0 8px 24px rgba(0,0,0,0.4)",overflow:"hidden",display:"flex",flexDirection:"column"}),handle:{padding:"8px 12px",display:"flex",alignItems:"center",gap:"8px",cursor:"grab",borderBottom:"1px solid rgba(255,255,255,0.06)"},title:{fontSize:"10px",fontWeight:600,color:"#e5e5e5",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},sub:{fontSize:"9px",color:"rgba(255,255,255,0.4)",display:"flex",alignItems:"center",gap:"6px"},btn:{padding:"2px",borderRadius:"4px",background:"transparent",border:"none",cursor:"pointer",color:"#888",display:"flex",flexShrink:0},stats:{padding:"4px 12px",display:"flex",alignItems:"center",gap:"8px",fontSize:"9px",borderBottom:"1px solid rgba(255,255,255,0.06)"},badge:e=>{let p=F[e]||F.custom;return {fontSize:"8px",padding:"0 4px",borderRadius:"4px",background:p.bg,color:p.text,border:`1px solid ${p.border}`,lineHeight:"14px"}},progress:{height:"2px",background:"rgba(255,255,255,0.06)",flexShrink:0},progressBar:e=>({height:"100%",width:`${e}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:e=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${e}15`,color:e,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(e,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:e?`${p}33`:"transparent",color:e?p:"#888",transition:"all 0.15s"}),input:{flex:1,fontSize:"9px",background:"rgba(0,0,0,0.3)",border:"1px solid rgba(255,255,255,0.1)",borderRadius:"4px",padding:"2px 6px",color:"#e5e5e5",outline:"none"}};function ie({config:e,appSlug:p,environment:f,testRunId:_,targetUrl:x,version:m,commitSha:h,branchName:w,onNavigate:l,displayName:u="human",defaultMode:c="mini",defaultPosition:M}){let[b,k]=useState(c),[y,v]=useState(""),[Y,P]=useState(null),[N,V]=useState(null),j=M?.x??16,X=M?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:$,onPointerDown:z,onPointerMove:B,onPointerUp:I,didDrag:H}=W(j,X),{run:i,widgetState:S,fetchRun:J,setVerdict:E,markComplete:Z}=L({config:e,appSlug:p,environment:f,testRunId:_,targetUrl:x,version:m,commitSha:h,branchName:w}),R=useCallback(async(r,s,G)=>{V(r);try{await E(r,s,G,u);}finally{V(null),P(null),v("");}},[E,u]),a=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},q=a.total>0&&a.pending===0,A=a.total>0?(a.pass+a.fail)/a.total*100:0;if(S==="no-match"||S==="loading")return null;let K=()=>{H.current||k(r=>r==="mini"||r==="expanded"?"max":"mini");},C=({icon:r,onClick:s})=>jsx("button",{style:o.btn,onClick:s,children:jsx(g,{d:r,className:""})});return jsxs("div",{style:{...o.root,left:$.x,top:$.y},children:[b==="mini"&&jsxs("div",{style:o.pill,onPointerDown:z,onPointerMove:B,onPointerUp:()=>{I(),H.current||K();},children:[jsx(g,{d:d.clipboard,className:""}),jsxs("span",{children:[a.pass,"/",a.total]}),a.fail>0&&jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),a.skip>0&&jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),i?.pr_url&&jsxs("span",{style:{...o.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxs("span",{style:{...o.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),i.ticket_id||"TKT"]})]}),b==="expanded"&&jsxs("div",{style:o.card(300),children:[jsxs("div",{style:o.handle,onPointerDown:z,onPointerMove:B,onPointerUp:I,children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:o.title,children:i?.title}),i?.branch_name&&jsxs("div",{style:o.sub,children:["\u2387 ",i.branch_name]})]}),jsx(C,{icon:d.chevronUp,onClick:K}),jsx(C,{icon:d.minus,onClick:()=>k("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[a.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[a.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:a.total})]}),i?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",maxHeight:"64px",overflowY:"auto"},children:i.description}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[i?.pr_url&&jsxs("a",{href:i.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),i.pr_id||"PR"]}),i?.ticket_url&&jsxs("a",{href:i.ticket_url,target:"_blank",rel:"noopener noreferrer",style:{...o.link("#fbbf24"),textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),i.ticket_id||"Ticket"]}),jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(A)})})]}),b==="max"&&jsxs("div",{style:{...o.card(340),maxHeight:"70vh"},children:[jsxs("div",{style:o.handle,onPointerDown:z,onPointerMove:B,onPointerUp:I,children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:o.title,children:i?.title}),jsxs("div",{style:o.sub,children:[jsx("span",{style:o.badge(i?.environment||"custom"),children:i?.environment}),i?.created_by_agent_name&&jsxs("span",{children:["by ",i.created_by_agent_name]})]})]}),jsx(C,{icon:d.chevronDown,onClick:()=>k("expanded")}),jsx(C,{icon:d.minus,onClick:()=>k("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[a.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[a.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[a.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[a.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:a.total})]}),S==="error"&&jsxs("div",{style:{padding:"12px",textAlign:"center"},children:[jsx(g,{d:d.alert,className:""}),jsx("div",{style:{fontSize:"10px",color:"#f87171"},children:"Failed to load"}),jsx("button",{onClick:J,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S==="completed"&&jsxs("div",{style:{padding:"12px",textAlign:"center",borderBottom:"1px solid rgba(255,255,255,0.06)"},children:[jsx(g,{d:d.checkAll,className:""}),jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"})]}),i?.intro_notes&&jsx("div",{style:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",fontSize:"10px",color:"rgba(255,255,255,0.4)",fontStyle:"italic",maxHeight:"48px",overflowY:"auto"},children:i.intro_notes}),S!=="error"&&jsx("div",{style:{flex:1,overflowY:"auto",minHeight:0},children:(i?.test_cases||[]).length===0?jsx("div",{style:{padding:"16px 12px",textAlign:"center",fontSize:"10px",color:"#888"},children:"No test cases"}):(i?.test_cases||[]).map(r=>jsxs("div",{style:o.caseRow,children:[jsxs("div",{style:{display:"flex",alignItems:"flex-start",gap:"8px"},children:[jsx("div",{style:{marginTop:"2px",flexShrink:0},children:N===r.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:re[r.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:r.title}),r.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:r.description}),r.url_path&&jsxs("a",{href:r.url_path,onClick:s=>{s.preventDefault(),s.stopPropagation(),l?l(r.url_path):window.open(r.url_path,"_blank");},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:0,marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none"},children:[jsx(g,{d:d.externalLink,className:""}),r.url_path]}),r.verdict==="fail"&&r.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",r.fail_reason]})]})]}),jsxs("div",{style:{display:"flex",alignItems:"center",gap:"4px",marginTop:"4px",marginLeft:"22px"},children:[["pass","fail","skip"].map(s=>jsx("button",{onClick:()=>{if(s==="fail"&&r.verdict!=="fail"){P(r.id);return}if(r.verdict===s){R(r.id,"pending");return}R(r.id,s);},disabled:N!==null,style:o.verdictBtn(r.verdict===s,s==="pass"?"#34d399":s==="fail"?"#f87171":"#f59e0b"),children:s.toUpperCase()},s)),r.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:r.verdict_by_display_name})]}),Y===r.id&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:y,onChange:s=>v(s.target.value),onKeyDown:s=>{s.key==="Enter"&&R(r.id,"fail",y),s.key==="Escape"&&(P(null),v(""));},placeholder:"Reason...",style:o.input}),jsx("button",{onClick:()=>R(r.id,"fail",y),style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},r.id))}),q&&S!=="completed"&&jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsx("button",{onClick:Z,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",cursor:"pointer"},children:"COMPLETE"})]}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(A)})})]})]})}export{ie as TestRunWidget,W as useDraggable,L as useTestRun};
|
package/package.json
CHANGED