@botbuddy/react 0.2.3 → 0.2.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 A(n,p){let[f,T]=react.useState({x:n,y:p}),b=react.useRef(false),x=react.useRef({x:0,y:0}),_=react.useRef(false),z=react.useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),L=react.useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=react.useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:L,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=react.useState(null),[T,b]=react.useState("loading"),x=react.useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return react.useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,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:n})}),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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"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:n=>{let p=te[n]||te.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:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?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"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=react.useState(h?.mode||v),[u,w]=react.useState(""),[oe,k]=react.useState(null),[Y,F]=react.useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);react.useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=react.useState(le),P=react.useRef(false),B=react.useRef({x:0,y:0,w:0,h:0}),de=react.useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=react.useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=react.useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:L}),D=react.useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"||t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsxRuntime.jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsxRuntime.jsx(g,{d:t,className:""})});return jsxRuntime.jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxRuntime.jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsxRuntime.jsx(g,{d:d.checkAll,className:""}):jsxRuntime.jsx(g,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.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"]})]}),y==="expanded"&&jsxRuntime.jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,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(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"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("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.3");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.3"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxRuntime.jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},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(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="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:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx(g,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),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",flexShrink:0},children:i.intro_notes}),N!=="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(t=>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:Y===t.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:he[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,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(g,{d:d.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(l=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsxRuntime.jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",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:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},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"]}),i?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.3");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.3"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}exports.TestRunWidget=ke;exports.useDraggable=A;exports.useTestRun=j;
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function A(n,p){let[f,T]=react.useState({x:n,y:p}),b=react.useRef(false),x=react.useRef({x:0,y:0}),_=react.useRef(false),z=react.useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),E=react.useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=react.useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:E,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=react.useState(null),[T,b]=react.useState("loading"),x=react.useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return react.useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,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:n})}),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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"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:n=>{let p=te[n]||te.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:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?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"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:E,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=react.useState(h?.mode||v),[u,w]=react.useState(""),[oe,k]=react.useState(null),[Y,F]=react.useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);react.useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=react.useState(le),P=react.useRef(false),B=react.useRef({x:0,y:0,w:0,h:0}),de=react.useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=react.useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=react.useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:E}),D=react.useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsxRuntime.jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsxRuntime.jsx(g,{d:t,className:""})});return jsxRuntime.jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxRuntime.jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsxRuntime.jsx(g,{d:d.checkAll,className:""}):jsxRuntime.jsx(g,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.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"]})]}),y==="expanded"&&jsxRuntime.jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,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(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"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:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxRuntime.jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxRuntime.jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxRuntime.jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},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(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:o.stats,children:[jsxRuntime.jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxRuntime.jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxRuntime.jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxRuntime.jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsxRuntime.jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="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:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsxRuntime.jsx(g,{d:d.checkAll,className:""}),jsxRuntime.jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),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",flexShrink:0},children:i.intro_notes}),N!=="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(t=>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:Y===t.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:he[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,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsxRuntime.jsx(g,{d:d.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(l=>jsxRuntime.jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsxRuntime.jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxRuntime.jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",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:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxRuntime.jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},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"]}),i?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsxRuntime.jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsxRuntime.jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsxRuntime.jsx("div",{style:o.progress,children:jsxRuntime.jsx("div",{style:o.progressBar(G)})}),jsxRuntime.jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsxRuntime.jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsxRuntime.jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}exports.TestRunWidget=ke;exports.useDraggable=A;exports.useTestRun=j;
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(n,p){let[f,T]=useState({x:n,y:p}),b=useRef(false),x=useRef({x:0,y:0}),_=useRef(false),z=useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),L=useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:L,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=useState(null),[T,b]=useState("loading"),x=useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,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:n})}),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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"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:n=>{let p=te[n]||te.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:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?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"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=useState(h?.mode||v),[u,w]=useState(""),[oe,k]=useState(null),[Y,F]=useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=useState(le),P=useRef(false),B=useRef({x:0,y:0,w:0,h:0}),de=useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:L}),D=useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"||t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsx(g,{d:t,className:""})});return jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsx(g,{d:d.checkAll,className:""}):jsx(g,{d:d.clipboard,className:""}),jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxs("span",{style:{color:"#f59e0b"},children:[s.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"]})]}),y==="expanded"&&jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,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(g,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"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("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.3");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.3"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},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(g,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="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:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsx(g,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),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",flexShrink:0},children:i.intro_notes}),N!=="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(t=>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:Y===t.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:he[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,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(g,{d:d.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(l=>jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsx("button",{onClick:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},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"]}),i?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.3");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.3"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}export{ke as TestRunWidget,A as useDraggable,j as useTestRun};
|
|
1
|
+
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(n,p){let[f,T]=useState({x:n,y:p}),b=useRef(false),x=useRef({x:0,y:0}),_=useRef(false),z=useCallback(c=>{b.current=true,_.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),E=useCallback(c=>{b.current&&(_.current=true,T({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=useCallback(()=>{b.current=false;},[]);return {pos:f,onPointerDown:z,onPointerMove:E,onPointerUp:a,didDrag:_}}function j(n){let[p,f]=useState(null),[T,b]=useState("loading"),x=useCallback(async()=>{try{let a=new URLSearchParams;n.testRunId&&a.set("test_run_id",n.testRunId),n.targetUrl&&a.set("target_url",n.targetUrl),a.set("app_slug",n.appSlug),a.set("environment",n.environment),n.version&&a.set("version",n.version),n.commitSha&&a.set("commit_sha",n.commitSha),n.prNumber&&a.set("pr_number",String(n.prNumber)),n.branchName&&a.set("branch_name",n.branchName);let c=await fetch(`${n.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});if(c.status===404){b("no-match"),f(null);return}if(!c.ok){b("error");return}let v=await c.json();f(v),b(v.status==="completed"?"completed":"ready");}catch{b("error");}},[n.config.serverUrl,n.config.anonKey,n.appSlug,n.environment,n.testRunId,n.targetUrl,n.version,n.commitSha,n.branchName]);return useEffect(()=>{x();},[x]),{run:p,widgetState:T,fetchRun:x,setVerdict:async(a,c,v,C="human")=>(f(h=>{if(!h)return null;let y=h.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:C,verdict_at:new Date().toISOString()}:u),m={total:y.length,pending:0,pass:0,fail:0,skip:0};return y.forEach(u=>{u.verdict in m&&m[u.verdict]++;}),{...h,test_cases:y,summary:m}}),(await fetch(`${n.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/complete`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${n.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${n.config.anonKey}`,apikey:n.config.anonKey}});return a.ok&&x(),a.ok},setRun:f}}var g=({d:n,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:n})}),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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},te={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:n=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:n?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:n?"0 4px 12px rgba(0,0,0,0.3), 0 0 0 1px rgba(52,211,153,0.2)":"0 4px 12px rgba(0,0,0,0.3)",cursor:"pointer",fontSize:"9px",color:"#e5e5e5"}),card:(n,p)=>({width:`${n}px`,borderRadius:"8px",background:"rgb(30,30,30)",border:p?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:p?"0 8px 24px rgba(0,0,0,0.4), 0 0 0 1px rgba(52,211,153,0.2)":"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:n=>{let p=te[n]||te.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:n=>({height:"100%",width:`${n}%`,background:"linear-gradient(to right, #34d399, #3b82f6)",transition:"width 0.5s"}),link:n=>({display:"inline-flex",alignItems:"center",gap:"4px",fontSize:"9px",padding:"2px 6px",borderRadius:"4px",background:`${n}15`,color:n,textDecoration:"none",border:"none",cursor:"pointer"}),caseRow:{padding:"6px 12px",borderBottom:"1px solid rgba(255,255,255,0.06)",transition:"background 0.15s"},verdictBtn:(n,p)=>({fontSize:"8px",padding:"2px 6px",borderRadius:"4px",border:"none",cursor:"pointer",background:n?`${p}33`:"transparent",color:n?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"}},re="botbuddy-widget-state";function ke({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z,branchName:E,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let t=typeof window<"u"?localStorage.getItem(re):null;if(t)return JSON.parse(t)}catch{}return null})(),[y,m]=useState(h?.mode||v),[u,w]=useState(""),[oe,k]=useState(null),[Y,F]=useState(null),ae=h?.x??C?.x??16,se=h?.y??C?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:M,onPointerDown:U,onPointerMove:$,onPointerUp:V,didDrag:K}=A(ae,se);useEffect(()=>{try{localStorage.setItem(re,JSON.stringify({mode:y,x:M.x,y:M.y}));}catch{}},[y,M.x,M.y]);let J="botbuddy-widget-max-size",le=()=>{try{let t=localStorage.getItem(J);if(t)return JSON.parse(t)}catch{}return {w:340,h:500}},[I,X]=useState(le),P=useRef(false),B=useRef({x:0,y:0,w:0,h:0}),de=useCallback(t=>{t.stopPropagation(),P.current=true,B.current={x:t.clientX,y:t.clientY,w:I.w,h:I.h},t.target.setPointerCapture(t.pointerId);},[I]),pe=useCallback(t=>{if(!P.current)return;let l=Math.max(280,Math.min(600,B.current.w+(t.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(t.clientY-B.current.y)));X({w:l,h:R});},[]),ce=useCallback(()=>{P.current&&(P.current=false,X(t=>(localStorage.setItem(J,JSON.stringify(t)),t)));},[]),{run:i,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=j({config:n,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:_,prNumber:z?String(z):void 0,branchName:E}),D=useCallback(async(t,l,R)=>{F(t);try{await Z(t,l,R,c);}finally{F(null),k(null),w("");}},[Z,c]),s=i?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},xe=s.total>0&&s.pending===0,S=N==="completed",G=s.total>0?(s.pass+s.fail)/s.total*100:0;if(N==="no-match"||N==="loading")return null;let q=()=>{K.current||m(t=>t==="mini"?"expanded":t==="expanded"?"max":"mini");},Q=({icon:t,onClick:l})=>jsx("button",{style:o.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsx(g,{d:t,className:""})});return jsxs("div",{style:{...o.root,left:M.x,top:M.y},children:[y==="mini"&&jsxs("div",{style:o.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),K.current||q();},children:[S?jsx(g,{d:d.checkAll,className:""}):jsx(g,{d:d.clipboard,className:""}),jsxs("span",{style:S?{color:"#34d399"}:void 0,children:[s.pass,"/",s.total]}),s.fail>0&&jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),s.skip>0&&jsxs("span",{style:{color:"#f59e0b"},children:[s.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"]})]}),y==="expanded"&&jsxs("div",{style:o.card(300,S),children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:q,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(g,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),i?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:i.description}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"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:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)"},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})})]}),y==="max"&&jsxs("div",{style:{...o.card(I.w,S),height:I.h,position:"relative"},children:[i?.assigned_human_display_name&&jsxs("div",{style:{padding:"4px 12px",fontSize:"9px",color:"#34d399",borderBottom:"1px solid rgba(255,255,255,0.06)",display:"flex",alignItems:"center",gap:"4px",background:"rgba(52,211,153,0.05)"},children:[jsx("span",{style:{width:6,height:6,borderRadius:"50%",background:"#34d399",display:"inline-block",flexShrink:0}}),i.assigned_human_display_name]}),jsxs("div",{style:o.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{K.current||m("expanded");},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(g,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:o.stats,children:[jsxs("span",{style:{color:"#34d399"},children:[s.pass,"\u2713"]}),jsxs("span",{style:{color:"#f87171"},children:[s.fail,"\u2717"]}),jsxs("span",{style:{color:"#f59e0b"},children:[s.skip,"\u23ED"]}),jsxs("span",{style:{color:"#888"},children:[s.pending,"\u25CC"]}),jsx("span",{style:{color:"#555",marginLeft:"auto"},children:s.total})]}),N==="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:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Retry"})]}),S&&jsxs("div",{style:{padding:"6px 12px",display:"flex",alignItems:"center",gap:"8px",borderBottom:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)"},children:[jsx(g,{d:d.checkAll,className:""}),jsx("span",{style:{fontSize:"10px",color:"#34d399",flex:1},children:"Run completed"}),jsx("button",{onClick:fe,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer"},children:"Reset"})]}),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",flexShrink:0},children:i.intro_notes}),N!=="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(t=>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:Y===t.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:he[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,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(t.url_path));},style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",padding:"2px 0",marginTop:"2px",display:"inline-flex",alignItems:"center",gap:"2px",textDecoration:"none",position:"relative",zIndex:1,pointerEvents:"auto"},children:[jsx(g,{d:d.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(l=>jsx("button",{onClick:()=>{if(t.verdict===l){D(t.id,"pending"),k(null);return}if(l==="fail"){D(t.id,"fail"),k(t.id),w("");return}k(null),D(t.id,l);},disabled:Y!==null,style:o.verdictBtn(t.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),t.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:t.verdict_by_display_name})]}),oe===t.id&&t.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:u,onChange:l=>w(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(t.id,"fail",u),k(null),w("")),l.key==="Escape"&&(k(null),w(""));},placeholder:"Reason (optional)...",style:o.input}),jsx("button",{onClick:()=>{u.trim()&&D(t.id,"fail",u),k(null),w("");},style:o.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},t.id))}),xe&&!S&&jsxs("div",{style:{padding:"6px 12px",borderTop:"1px solid rgba(52,211,153,0.2)",background:"rgba(52,211,153,0.05)",display:"flex",alignItems:"center",justifyContent:"space-between",flexShrink:0},children:[jsx("span",{style:{fontSize:"9px",color:"#34d399"},children:"All resolved"}),jsx("button",{onClick:ue,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(52,211,153,0.15)",color:"#34d399",border:"1px solid rgba(52,211,153,0.3)",cursor:"pointer"},children:"COMPLETE"})]}),jsxs("div",{style:{padding:"6px 12px",display:"flex",gap:"8px",flexWrap:"wrap",alignItems:"center",borderTop:"1px solid rgba(255,255,255,0.06)",flexShrink:0},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"]}),i?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",i.created_by_agent_name]}),jsx("span",{style:{...o.badge(i?.environment||"custom"),marginLeft:"auto"},children:i?.environment})]}),jsx("div",{style:{padding:"4px 12px",display:"flex",alignItems:"center",justifyContent:"center",borderTop:"1px solid rgba(255,255,255,0.06)",background:"rgba(255,255,255,0.02)",flexShrink:0},children:jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.4");},style:{fontSize:"9px",fontWeight:600,color:"rgba(255,255,255,0.5)",letterSpacing:"0.08em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"4px",padding:0},title:"Copy version",children:["BotBuddy ",jsx("span",{style:{color:"rgba(255,255,255,0.3)"},children:"v0.2.4"})]})}),jsx("div",{style:o.progress,children:jsx("div",{style:o.progressBar(G)})}),jsx("div",{style:{position:"absolute",bottom:0,right:0,width:16,height:16,cursor:"se-resize",zIndex:10,display:"flex",alignItems:"flex-end",justifyContent:"flex-end",padding:"2px",opacity:.3},onPointerDown:de,onPointerMove:pe,onPointerUp:ce,onPointerEnter:t=>t.currentTarget.style.opacity="0.7",onPointerLeave:t=>{P.current||(t.currentTarget.style.opacity="0.3");},children:jsx("svg",{width:"8",height:"8",viewBox:"0 0 8 8",children:jsx("path",{d:"M7 1v6H1",fill:"none",stroke:"#888",strokeWidth:"1.5",strokeLinecap:"round"})})})]})]})}export{ke as TestRunWidget,A as useDraggable,j as useTestRun};
|
package/package.json
CHANGED