@botbuddy/react 0.2.0 → 0.2.2
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.d.cts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +1 -1
- package/package.json +15 -5
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function O(n,p){let[f,R]=react.useState({x:n,y:p}),y=react.useRef(false),x=react.useRef({x:0,y:0}),S=react.useRef(false),D=react.useCallback(c=>{y.current=true,S.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),T=react.useCallback(c=>{y.current&&(S.current=true,R({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=react.useCallback(()=>{y.current=false;},[]);return {pos:f,onPointerDown:D,onPointerMove:T,onPointerUp:a,didDrag:S}}function A(n){let[p,f]=react.useState(null),[R,y]=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.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){y("no-match"),f(null);return}if(!c.ok){y("error");return}let v=await c.json();f(v),y(v.status==="completed"?"completed":"ready");}catch{y("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:R,fetchRun:x,setVerdict:async(a,c,v,L="human")=>(f(m=>{if(!m)return null;let h=m.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:L,verdict_at:new Date().toISOString()}:u),b={total:h.length,pending:0,pass:0,fail:0,skip:0};return h.forEach(u=>{u.verdict in b&&b[u.verdict]++;}),{...m,test_cases:h,summary:b}}),(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:L})})).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 be={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)"}},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:n=>({width:`${n}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: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"}},ne="botbuddy-widget-state";function ve({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:S,branchName:D,onNavigate:T,displayName:a="human",defaultMode:c="expanded",defaultPosition:v}){let N=(()=>{try{let e=typeof window<"u"?localStorage.getItem(ne):null;if(e)return JSON.parse(e)}catch{}return null})(),[m,h]=react.useState(N?.mode||c),[b,u]=react.useState(""),[re,k]=react.useState(null),[Y,j]=react.useState(null),oe=N?.x??v?.x??16,ie=N?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:w,onPointerDown:E,onPointerMove:U,onPointerUp:$,didDrag:V}=O(oe,ie);react.useEffect(()=>{try{localStorage.setItem(ne,JSON.stringify({mode:m,x:w.x,y:w.y}));}catch{}},[m,w.x,w.y]);let F="botbuddy-widget-max-size",ae=()=>{try{let e=localStorage.getItem(F);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[z,J]=react.useState(ae),P=react.useRef(false),C=react.useRef({x:0,y:0,w:0,h:0}),se=react.useCallback(e=>{e.stopPropagation(),P.current=true,C.current={x:e.clientX,y:e.clientY,w:z.w,h:z.h},e.target.setPointerCapture(e.pointerId);},[z]),le=react.useCallback(e=>{if(!P.current)return;let l=Math.max(280,Math.min(600,C.current.w+(e.clientX-C.current.x))),M=Math.max(300,Math.min(window.innerHeight*.9,C.current.h+(e.clientY-C.current.y)));J({w:l,h:M});},[]),de=react.useCallback(()=>{P.current&&(P.current=false,J(e=>(localStorage.setItem(F,JSON.stringify(e)),e)));},[]),{run:o,widgetState:_,fetchRun:pe,setVerdict:X,markComplete:ce,resetRun:ge}=A({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:S,branchName:D}),I=react.useCallback(async(e,l,M)=>{j(e);try{await X(e,l,M,a);}finally{j(null),k(null),u("");}},[X,a]),s=o?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ue=s.total>0&&s.pending===0,Z=s.total>0?(s.pass+s.fail)/s.total*100:0;if(_==="no-match"||_==="loading")return null;let G=()=>{V.current||h(e=>e==="mini"||e==="expanded"?"max":"mini");},q=({icon:e,onClick:l})=>jsxRuntime.jsx("button",{style:i.btn,onClick:M=>{M.stopPropagation(),l(M);},children:jsxRuntime.jsx(g,{d:e,className:""})});return jsxRuntime.jsxs("div",{style:{...i.root,left:w.x,top:w.y},children:[m==="mini"&&jsxRuntime.jsxs("div",{style:i.pill,onPointerDown:E,onPointerMove:U,onPointerUp:()=>{$(),V.current||G();},children:[jsxRuntime.jsx(g,{d:d.clipboard,className:""}),jsxRuntime.jsxs("span",{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"]}),o?.pr_url&&jsxRuntime.jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),m==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300),children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:E,onPointerMove:U,onPointerUp:$,onClick:G,children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxRuntime.jsxs("div",{style:i.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})]}),o?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[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:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Z)})})]}),m==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(z.w),height:z.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:E,onPointerMove:U,onPointerUp:$,onClick:()=>{V.current||h("expanded");},children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxRuntime.jsxs("div",{style:i.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})]}),_==="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:pe,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:d.checkAll,className:""}),jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"}),jsxRuntime.jsx("button",{onClick:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Reset & re-test"})]}),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",flexShrink:0},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(e=>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:Y===e.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:be[e.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:e.title}),e.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:e.description}),e.url_path&&jsxRuntime.jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),T&&(l.preventDefault(),T(e.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:""}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",e.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(e.verdict===l){I(e.id,"pending"),k(null);return}if(l==="fail"){I(e.id,"fail"),k(e.id),u("");return}k(null),I(e.id,l);},disabled:Y!==null,style:i.verdictBtn(e.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),e.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:e.verdict_by_display_name})]}),re===e.id&&e.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:b,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&b.trim()&&(I(e.id,"fail",b),k(null),u("")),l.key==="Escape"&&(k(null),u(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{b.trim()&&I(e.id,"fail",b),k(null),u("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},e.id))}),ue&&_!=="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:ce,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",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:[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:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.1.9");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.1.9",jsxRuntime.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(Z)})}),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:se,onPointerMove:le,onPointerUp:de,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{P.current||(e.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=ve;exports.useDraggable=O;exports.useTestRun=A;
|
|
1
|
+
'use strict';var react=require('react'),jsxRuntime=require('react/jsx-runtime');function A(e,p){let[f,T]=react.useState({x:e,y:p}),b=react.useRef(false),x=react.useRef({x:0,y:0}),w=react.useRef(false),z=react.useCallback(c=>{b.current=true,w.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&&(w.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:w}}function Y(e){let[p,f]=react.useState(null),[T,b]=react.useState("loading"),x=react.useCallback(async()=>{try{let a=new URLSearchParams;e.testRunId&&a.set("test_run_id",e.testRunId),e.targetUrl&&a.set("target_url",e.targetUrl),a.set("app_slug",e.appSlug),a.set("environment",e.environment),e.version&&a.set("version",e.version),e.commitSha&&a.set("commit_sha",e.commitSha),e.prNumber&&a.set("pr_number",String(e.prNumber)),e.branchName&&a.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.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");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.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(`${e.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=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 a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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:e=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:e?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:e?"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:(e,p)=>({width:`${e}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:e=>{let p=ne[e]||ne.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"}},re="botbuddy-widget-state";function ke({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let n=typeof window<"u"?localStorage.getItem(re):null;if(n)return JSON.parse(n)}catch{}return null})(),[y,m]=react.useState(h?.mode||v),[u,_]=react.useState(""),[ie,k]=react.useState(null),[j,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:H}=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 n=localStorage.getItem(J);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[P,X]=react.useState(le),I=react.useRef(false),B=react.useRef({x:0,y:0,w:0,h:0}),de=react.useCallback(n=>{n.stopPropagation(),I.current=true,B.current={x:n.clientX,y:n.clientY,w:P.w,h:P.h},n.target.setPointerCapture(n.pointerId);},[P]),pe=react.useCallback(n=>{if(!I.current)return;let l=Math.max(280,Math.min(600,B.current.w+(n.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(n.clientY-B.current.y)));X({w:l,h:R});},[]),ce=react.useCallback(()=>{I.current&&(I.current=false,X(n=>(localStorage.setItem(J,JSON.stringify(n)),n)));},[]),{run:o,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=Y({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z?String(z):void 0,branchName:L}),D=react.useCallback(async(n,l,R)=>{F(n);try{await Z(n,l,R,c);}finally{F(null),k(null),_("");}},[Z,c]),s=o?.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=()=>{H.current||m(n=>n==="mini"||n==="expanded"?"max":"mini");},Q=({icon:n,onClick:l})=>jsxRuntime.jsx("button",{style:i.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsxRuntime.jsx(g,{d:n,className:""})});return jsxRuntime.jsxs("div",{style:{...i.root,left:M.x,top:M.y},children:[y==="mini"&&jsxRuntime.jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.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"]}),o?.pr_url&&jsxRuntime.jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxRuntime.jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsxRuntime.jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),y==="expanded"&&jsxRuntime.jsxs("div",{style:i.card(300,S),children:[jsxRuntime.jsxs("div",{style:i.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:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronUp,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:i.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})]}),o?.description&&jsxRuntime.jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[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:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.progressBar(G)})})]}),y==="max"&&jsxRuntime.jsxs("div",{style:{...i.card(P.w,S),height:P.h,position:"relative"},children:[jsxRuntime.jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||m("expanded");},children:[jsxRuntime.jsx(g,{d:d.grip,className:""}),jsxRuntime.jsxs("div",{style:{flex:1,minWidth:0},children:[jsxRuntime.jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxRuntime.jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsxRuntime.jsx(g,{d:d.chevronDown,className:""}),jsxRuntime.jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxRuntime.jsxs("div",{style:i.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"})]}),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",flexShrink:0},children:o.intro_notes}),N!=="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(n=>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:j===n.id?jsxRuntime.jsx(g,{d:d.loader,className:""}):jsxRuntime.jsx(g,{d:he[n.verdict],className:""})}),jsxRuntime.jsxs("div",{style:{minWidth:0,flex:1},children:[jsxRuntime.jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:n.title}),n.description&&jsxRuntime.jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:n.description}),n.url_path&&jsxRuntime.jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(n.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:""}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxRuntime.jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",n.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(n.verdict===l){D(n.id,"pending"),k(null);return}if(l==="fail"){D(n.id,"fail"),k(n.id),_("");return}k(null),D(n.id,l);},disabled:j!==null,style:i.verdictBtn(n.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),n.verdict_by_display_name&&jsxRuntime.jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:n.verdict_by_display_name})]}),ie===n.id&&n.verdict==="fail"&&jsxRuntime.jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsxRuntime.jsx("input",{autoFocus:true,value:u,onChange:l=>_(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(n.id,"fail",u),k(null),_("")),l.key==="Escape"&&(k(null),_(""));},placeholder:"Reason (optional)...",style:i.input}),jsxRuntime.jsx("button",{onClick:()=>{u.trim()&&D(n.id,"fail",u),k(null),_("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},n.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:[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:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxRuntime.jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsxRuntime.jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxRuntime.jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.1");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.2.1",jsxRuntime.jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsxRuntime.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsxRuntime.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsxRuntime.jsx("div",{style:i.progress,children:jsxRuntime.jsx("div",{style:i.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:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{I.current||(n.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=Y;
|
package/dist/index.d.cts
CHANGED
|
@@ -69,6 +69,8 @@ interface TestRunWidgetProps {
|
|
|
69
69
|
version?: string;
|
|
70
70
|
/** Match by commit SHA */
|
|
71
71
|
commitSha?: string;
|
|
72
|
+
/** Match by PR number (most stable identifier for preview deployments) */
|
|
73
|
+
prNumber?: number | string;
|
|
72
74
|
/** Match by branch name */
|
|
73
75
|
branchName?: string;
|
|
74
76
|
/** Callback when user clicks a test case URL */
|
|
@@ -84,7 +86,7 @@ interface TestRunWidgetProps {
|
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
89
|
+
declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
88
90
|
|
|
89
91
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
90
92
|
pos: {
|
|
@@ -105,6 +107,7 @@ interface UseTestRunOptions {
|
|
|
105
107
|
targetUrl?: string;
|
|
106
108
|
version?: string;
|
|
107
109
|
commitSha?: string;
|
|
110
|
+
prNumber?: number | string;
|
|
108
111
|
branchName?: string;
|
|
109
112
|
}
|
|
110
113
|
declare function useTestRun(opts: UseTestRunOptions): {
|
package/dist/index.d.ts
CHANGED
|
@@ -69,6 +69,8 @@ interface TestRunWidgetProps {
|
|
|
69
69
|
version?: string;
|
|
70
70
|
/** Match by commit SHA */
|
|
71
71
|
commitSha?: string;
|
|
72
|
+
/** Match by PR number (most stable identifier for preview deployments) */
|
|
73
|
+
prNumber?: number | string;
|
|
72
74
|
/** Match by branch name */
|
|
73
75
|
branchName?: string;
|
|
74
76
|
/** Callback when user clicks a test case URL */
|
|
@@ -84,7 +86,7 @@ interface TestRunWidgetProps {
|
|
|
84
86
|
};
|
|
85
87
|
}
|
|
86
88
|
|
|
87
|
-
declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
89
|
+
declare function TestRunWidget({ config, appSlug, environment, testRunId, targetUrl, version, commitSha, prNumber, branchName, onNavigate, displayName, defaultMode, defaultPosition, }: TestRunWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
88
90
|
|
|
89
91
|
declare function useDraggable(initialX: number, initialY: number): {
|
|
90
92
|
pos: {
|
|
@@ -105,6 +107,7 @@ interface UseTestRunOptions {
|
|
|
105
107
|
targetUrl?: string;
|
|
106
108
|
version?: string;
|
|
107
109
|
commitSha?: string;
|
|
110
|
+
prNumber?: number | string;
|
|
108
111
|
branchName?: string;
|
|
109
112
|
}
|
|
110
113
|
declare function useTestRun(opts: UseTestRunOptions): {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function O(n,p){let[f,R]=useState({x:n,y:p}),y=useRef(false),x=useRef({x:0,y:0}),S=useRef(false),D=useCallback(c=>{y.current=true,S.current=false,x.current={x:c.clientX-f.x,y:c.clientY-f.y},c.target.setPointerCapture(c.pointerId);},[f]),T=useCallback(c=>{y.current&&(S.current=true,R({x:c.clientX-x.current.x,y:c.clientY-x.current.y}));},[]),a=useCallback(()=>{y.current=false;},[]);return {pos:f,onPointerDown:D,onPointerMove:T,onPointerUp:a,didDrag:S}}function A(n){let[p,f]=useState(null),[R,y]=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.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){y("no-match"),f(null);return}if(!c.ok){y("error");return}let v=await c.json();f(v),y(v.status==="completed"?"completed":"ready");}catch{y("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:R,fetchRun:x,setVerdict:async(a,c,v,L="human")=>(f(m=>{if(!m)return null;let h=m.test_cases.map(u=>u.id===a?{...u,verdict:c,fail_reason:c==="fail"&&v||null,verdict_by_display_name:L,verdict_at:new Date().toISOString()}:u),b={total:h.length,pending:0,pass:0,fail:0,skip:0};return h.forEach(u=>{u.verdict in b&&b[u.verdict]++;}),{...m,test_cases:h,summary:b}}),(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:L})})).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 be={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)"}},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:n=>({width:`${n}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: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"}},ne="botbuddy-widget-state";function ve({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:S,branchName:D,onNavigate:T,displayName:a="human",defaultMode:c="expanded",defaultPosition:v}){let N=(()=>{try{let e=typeof window<"u"?localStorage.getItem(ne):null;if(e)return JSON.parse(e)}catch{}return null})(),[m,h]=useState(N?.mode||c),[b,u]=useState(""),[re,k]=useState(null),[Y,j]=useState(null),oe=N?.x??v?.x??16,ie=N?.y??v?.y??(typeof window<"u"?window.innerHeight-56:600),{pos:w,onPointerDown:E,onPointerMove:U,onPointerUp:$,didDrag:V}=O(oe,ie);useEffect(()=>{try{localStorage.setItem(ne,JSON.stringify({mode:m,x:w.x,y:w.y}));}catch{}},[m,w.x,w.y]);let F="botbuddy-widget-max-size",ae=()=>{try{let e=localStorage.getItem(F);if(e)return JSON.parse(e)}catch{}return {w:340,h:500}},[z,J]=useState(ae),P=useRef(false),C=useRef({x:0,y:0,w:0,h:0}),se=useCallback(e=>{e.stopPropagation(),P.current=true,C.current={x:e.clientX,y:e.clientY,w:z.w,h:z.h},e.target.setPointerCapture(e.pointerId);},[z]),le=useCallback(e=>{if(!P.current)return;let l=Math.max(280,Math.min(600,C.current.w+(e.clientX-C.current.x))),M=Math.max(300,Math.min(window.innerHeight*.9,C.current.h+(e.clientY-C.current.y)));J({w:l,h:M});},[]),de=useCallback(()=>{P.current&&(P.current=false,J(e=>(localStorage.setItem(F,JSON.stringify(e)),e)));},[]),{run:o,widgetState:_,fetchRun:pe,setVerdict:X,markComplete:ce,resetRun:ge}=A({config:n,appSlug:p,environment:f,testRunId:R,targetUrl:y,version:x,commitSha:S,branchName:D}),I=useCallback(async(e,l,M)=>{j(e);try{await X(e,l,M,a);}finally{j(null),k(null),u("");}},[X,a]),s=o?.summary||{total:0,pending:0,pass:0,fail:0,skip:0},ue=s.total>0&&s.pending===0,Z=s.total>0?(s.pass+s.fail)/s.total*100:0;if(_==="no-match"||_==="loading")return null;let G=()=>{V.current||h(e=>e==="mini"||e==="expanded"?"max":"mini");},q=({icon:e,onClick:l})=>jsx("button",{style:i.btn,onClick:M=>{M.stopPropagation(),l(M);},children:jsx(g,{d:e,className:""})});return jsxs("div",{style:{...i.root,left:w.x,top:w.y},children:[m==="mini"&&jsxs("div",{style:i.pill,onPointerDown:E,onPointerMove:U,onPointerUp:()=>{$(),V.current||G();},children:[jsx(g,{d:d.clipboard,className:""}),jsxs("span",{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"]}),o?.pr_url&&jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),m==="expanded"&&jsxs("div",{style:i.card(300),children:[jsxs("div",{style:i.handle,onPointerDown:E,onPointerMove:U,onPointerUp:$,onClick:G,children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronUp,className:""}),jsx(q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxs("div",{style:i.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})]}),o?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Z)})})]}),m==="max"&&jsxs("div",{style:{...i.card(z.w),height:z.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:E,onPointerMove:U,onPointerUp:$,onClick:()=>{V.current||h("expanded");},children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronDown,className:""}),jsx(q,{icon:d.minus,onClick:()=>h("mini")})]}),jsxs("div",{style:i.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})]}),_==="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:pe,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:d.checkAll,className:""}),jsx("div",{style:{fontSize:"10px",color:"#34d399"},children:"Run completed"}),jsx("button",{onClick:ge,style:{fontSize:"9px",color:"#3b82f6",background:"none",border:"none",cursor:"pointer",marginTop:"4px"},children:"Reset & re-test"})]}),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",flexShrink:0},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(e=>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:Y===e.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:be[e.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:e.title}),e.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:e.description}),e.url_path&&jsxs("a",{href:e.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),T&&(l.preventDefault(),T(e.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:""}),e.url_path]}),e.verdict==="fail"&&e.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",e.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(e.verdict===l){I(e.id,"pending"),k(null);return}if(l==="fail"){I(e.id,"fail"),k(e.id),u("");return}k(null),I(e.id,l);},disabled:Y!==null,style:i.verdictBtn(e.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),e.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:e.verdict_by_display_name})]}),re===e.id&&e.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:b,onChange:l=>u(l.target.value),onKeyDown:l=>{l.key==="Enter"&&b.trim()&&(I(e.id,"fail",b),k(null),u("")),l.key==="Escape"&&(k(null),u(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{b.trim()&&I(e.id,"fail",b),k(null),u("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},e.id))}),ue&&_!=="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:ce,style:{fontSize:"8px",padding:"2px 8px",borderRadius:"4px",background:"rgba(59,130,246,0.15)",color:"#60a5fa",border:"none",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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.1.9");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.1.9",jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(Z)})}),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:se,onPointerMove:le,onPointerUp:de,onPointerEnter:e=>e.currentTarget.style.opacity="0.7",onPointerLeave:e=>{P.current||(e.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{ve as TestRunWidget,O as useDraggable,A as useTestRun};
|
|
1
|
+
import {useState,useRef,useCallback,useEffect}from'react';import {jsxs,jsx}from'react/jsx-runtime';function A(e,p){let[f,T]=useState({x:e,y:p}),b=useRef(false),x=useRef({x:0,y:0}),w=useRef(false),z=useCallback(c=>{b.current=true,w.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&&(w.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:w}}function Y(e){let[p,f]=useState(null),[T,b]=useState("loading"),x=useCallback(async()=>{try{let a=new URLSearchParams;e.testRunId&&a.set("test_run_id",e.testRunId),e.targetUrl&&a.set("target_url",e.targetUrl),a.set("app_slug",e.appSlug),a.set("environment",e.environment),e.version&&a.set("version",e.version),e.commitSha&&a.set("commit_sha",e.commitSha),e.prNumber&&a.set("pr_number",String(e.prNumber)),e.branchName&&a.set("branch_name",e.branchName);let c=await fetch(`${e.config.serverUrl}/widget/test-run?${a.toString()}`,{headers:{Authorization:`Bearer ${e.config.anonKey}`,apikey:e.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");}},[e.config.serverUrl,e.config.anonKey,e.appSlug,e.environment,e.testRunId,e.targetUrl,e.version,e.commitSha,e.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(`${e.config.serverUrl}/widget/test-cases/${a}/verdict`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey},body:JSON.stringify({verdict:c,fail_reason:v,display_name:C})})).ok),markComplete:async()=>{if(!p)return false;let a=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 a.ok&&x(),a.ok},resetRun:async()=>{if(!p)return false;let a=await fetch(`${e.config.serverUrl}/widget/test-runs/${p.id}/reset`,{method:"POST",headers:{"Content-Type":"application/json",Authorization:`Bearer ${e.config.anonKey}`,apikey:e.config.anonKey}});return a.ok&&x(),a.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 he={pending:d.circle,pass:d.check,fail:d.x,skip:d.skip},ne={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:e=>({display:"inline-flex",alignItems:"center",gap:"6px",padding:"4px 8px",borderRadius:"9999px",background:"rgb(30,30,30)",border:e?"1px solid rgba(52,211,153,0.6)":"1px solid rgba(255,255,255,0.15)",boxShadow:e?"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:(e,p)=>({width:`${e}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:e=>{let p=ne[e]||ne.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"}},re="botbuddy-widget-state";function ke({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z,branchName:L,onNavigate:a,displayName:c="human",defaultMode:v="expanded",defaultPosition:C}){let h=(()=>{try{let n=typeof window<"u"?localStorage.getItem(re):null;if(n)return JSON.parse(n)}catch{}return null})(),[y,m]=useState(h?.mode||v),[u,_]=useState(""),[ie,k]=useState(null),[j,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:H}=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 n=localStorage.getItem(J);if(n)return JSON.parse(n)}catch{}return {w:340,h:500}},[P,X]=useState(le),I=useRef(false),B=useRef({x:0,y:0,w:0,h:0}),de=useCallback(n=>{n.stopPropagation(),I.current=true,B.current={x:n.clientX,y:n.clientY,w:P.w,h:P.h},n.target.setPointerCapture(n.pointerId);},[P]),pe=useCallback(n=>{if(!I.current)return;let l=Math.max(280,Math.min(600,B.current.w+(n.clientX-B.current.x))),R=Math.max(300,Math.min(window.innerHeight*.9,B.current.h+(n.clientY-B.current.y)));X({w:l,h:R});},[]),ce=useCallback(()=>{I.current&&(I.current=false,X(n=>(localStorage.setItem(J,JSON.stringify(n)),n)));},[]),{run:o,widgetState:N,fetchRun:ge,setVerdict:Z,markComplete:ue,resetRun:fe}=Y({config:e,appSlug:p,environment:f,testRunId:T,targetUrl:b,version:x,commitSha:w,prNumber:z?String(z):void 0,branchName:L}),D=useCallback(async(n,l,R)=>{F(n);try{await Z(n,l,R,c);}finally{F(null),k(null),_("");}},[Z,c]),s=o?.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=()=>{H.current||m(n=>n==="mini"||n==="expanded"?"max":"mini");},Q=({icon:n,onClick:l})=>jsx("button",{style:i.btn,onClick:R=>{R.stopPropagation(),l(R);},children:jsx(g,{d:n,className:""})});return jsxs("div",{style:{...i.root,left:M.x,top:M.y},children:[y==="mini"&&jsxs("div",{style:i.pill(S),onPointerDown:U,onPointerMove:$,onPointerUp:()=>{V(),H.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"]}),o?.pr_url&&jsxs("span",{style:{...i.link("#60a5fa"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.pr,className:""}),o.pr_id||"PR"]}),o?.ticket_url&&jsxs("span",{style:{...i.link("#fbbf24"),pointerEvents:"none",textDecoration:"none"},children:[jsx(g,{d:d.ticket,className:""}),o.ticket_id||"TKT"]})]}),y==="expanded"&&jsxs("div",{style:i.card(300,S),children:[jsxs("div",{style:i.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:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronUp,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:i.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})]}),o?.description&&jsx("div",{style:{padding:"6px 12px",fontSize:"10px",color:"#888",borderBottom:"1px solid rgba(255,255,255,0.06)",flexShrink:0},children:o.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsx("span",{style:{fontSize:"7px",color:"rgba(255,255,255,0.2)",letterSpacing:"0.05em"},children:"BotBuddy"})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.progressBar(G)})})]}),y==="max"&&jsxs("div",{style:{...i.card(P.w,S),height:P.h,position:"relative"},children:[jsxs("div",{style:i.handle,onPointerDown:U,onPointerMove:$,onPointerUp:V,onClick:()=>{H.current||m("expanded");},children:[jsx(g,{d:d.grip,className:""}),jsxs("div",{style:{flex:1,minWidth:0},children:[jsx("div",{style:i.title,children:o?.title}),o?.branch_name&&jsxs("div",{style:i.sub,children:["\u2387 ",o.branch_name]})]}),jsx(g,{d:d.chevronDown,className:""}),jsx(Q,{icon:d.minus,onClick:()=>m("mini")})]}),jsxs("div",{style:i.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"})]}),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",flexShrink:0},children:o.intro_notes}),N!=="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(n=>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:j===n.id?jsx(g,{d:d.loader,className:""}):jsx(g,{d:he[n.verdict],className:""})}),jsxs("div",{style:{minWidth:0,flex:1},children:[jsx("div",{style:{fontSize:"10px",color:"#e5e5e5",lineHeight:1.3},children:n.title}),n.description&&jsx("div",{style:{fontSize:"9px",color:"#888",marginTop:"2px"},children:n.description}),n.url_path&&jsxs("a",{href:n.url_path,target:"_blank",rel:"noopener noreferrer",onClick:l=>{l.stopPropagation(),a&&(l.preventDefault(),a(n.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:""}),n.url_path]}),n.verdict==="fail"&&n.fail_reason&&jsxs("div",{style:{fontSize:"9px",color:"#f87171",marginTop:"2px"},children:["\u2717 ",n.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(n.verdict===l){D(n.id,"pending"),k(null);return}if(l==="fail"){D(n.id,"fail"),k(n.id),_("");return}k(null),D(n.id,l);},disabled:j!==null,style:i.verdictBtn(n.verdict===l,l==="pass"?"#34d399":l==="fail"?"#f87171":"#f59e0b"),children:l.toUpperCase()},l)),n.verdict_by_display_name&&jsx("span",{style:{fontSize:"8px",color:"#555",marginLeft:"auto"},children:n.verdict_by_display_name})]}),ie===n.id&&n.verdict==="fail"&&jsxs("div",{style:{marginLeft:"22px",marginTop:"4px",display:"flex",gap:"4px"},children:[jsx("input",{autoFocus:true,value:u,onChange:l=>_(l.target.value),onKeyDown:l=>{l.key==="Enter"&&u.trim()&&(D(n.id,"fail",u),k(null),_("")),l.key==="Escape"&&(k(null),_(""));},placeholder:"Reason (optional)...",style:i.input}),jsx("button",{onClick:()=>{u.trim()&&D(n.id,"fail",u),k(null),_("");},style:i.verdictBtn(true,"#f87171"),children:"\u2713"})]})]},n.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:[o?.pr_url&&jsxs("a",{href:o.pr_url,target:"_blank",rel:"noopener noreferrer",style:{...i.link("#60a5fa"),textDecoration:"none"},children:[jsx(g,{d:d.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:d.ticket,className:""}),o.ticket_id||"Ticket"]}),o?.created_by_agent_name&&jsxs("span",{style:{fontSize:"9px",color:"#888"},children:["by ",o.created_by_agent_name]}),jsx("span",{style:{...i.badge(o?.environment||"custom"),marginLeft:"auto"},children:o?.environment}),jsxs("button",{onClick:()=>{navigator.clipboard.writeText("0.2.1");},style:{fontSize:"7px",color:"rgba(255,255,255,0.7)",letterSpacing:"0.05em",background:"none",border:"none",cursor:"pointer",display:"inline-flex",alignItems:"center",gap:"2px",padding:0},title:"Copy version",children:["BotBuddy v0.2.1",jsxs("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})]})]}),jsx("div",{style:i.progress,children:jsx("div",{style:i.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:n=>n.currentTarget.style.opacity="0.7",onPointerLeave:n=>{I.current||(n.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,Y as useTestRun};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botbuddy/react",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "BotBuddy test coordination widgets for React
|
|
3
|
+
"version": "0.2.2",
|
|
4
|
+
"description": "BotBuddy test coordination widgets for React \u2014 draggable, translucent overlays for human-in-the-loop QA",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -13,7 +13,10 @@
|
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"files": [
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"README.md"
|
|
19
|
+
],
|
|
17
20
|
"sideEffects": false,
|
|
18
21
|
"scripts": {
|
|
19
22
|
"build": "tsup",
|
|
@@ -30,10 +33,17 @@
|
|
|
30
33
|
"tsup": "^8.4.0",
|
|
31
34
|
"typescript": "^5.8.3"
|
|
32
35
|
},
|
|
33
|
-
"keywords": [
|
|
36
|
+
"keywords": [
|
|
37
|
+
"botbuddy",
|
|
38
|
+
"testing",
|
|
39
|
+
"qa",
|
|
40
|
+
"widget",
|
|
41
|
+
"react",
|
|
42
|
+
"overlay"
|
|
43
|
+
],
|
|
34
44
|
"license": "MIT",
|
|
35
45
|
"repository": {
|
|
36
46
|
"type": "git",
|
|
37
47
|
"url": "https://github.com/botbuddy/react"
|
|
38
48
|
}
|
|
39
|
-
}
|
|
49
|
+
}
|