context_drop 0.1.4 → 0.3.0
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.
- checksums.yaml +4 -4
- data/README.md +330 -116
- data/Rakefile +110 -1
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +6329 -682
- data/app/controllers/context_drop/agent_controller.rb +170 -0
- data/app/controllers/context_drop/application_controller.rb +52 -3
- data/app/controllers/context_drop/configs_controller.rb +12 -2
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +15 -11
- data/app/controllers/context_drop/feedbacks_controller.rb +396 -20
- data/app/controllers/context_drop/mcp_controller.rb +2 -1
- data/app/helpers/context_drop/widget_helper.rb +11 -1
- data/app/javascript/context_drop/__tests__/api-client.test.ts +255 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +1015 -89
- data/app/javascript/context_drop/api-client.ts +422 -19
- data/app/javascript/context_drop/element-picker.ts +186 -34
- data/app/javascript/context_drop/icons.ts +28 -0
- data/app/javascript/context_drop/markdown.ts +146 -0
- data/app/javascript/context_drop/sanitizer.ts +413 -2
- data/app/javascript/context_drop/screenshot.ts +103 -9
- data/app/javascript/context_drop/styles.ts +1705 -248
- data/app/javascript/context_drop/types.ts +243 -6
- data/app/javascript/context_drop/widget.ts +3318 -294
- data/app/models/context_drop/feedback.rb +88 -8
- data/app/services/context_drop/ownership_token.rb +114 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +13 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +19 -0
- data/app/views/layouts/context_drop/application.html.erb +6 -0
- data/config/routes.rb +22 -0
- data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -0
- data/db/migrate/20261113000005_add_deleted_at_to_context_drop_feedbacks.rb +11 -0
- data/lib/context_drop/agent/key_store.rb +290 -0
- data/lib/context_drop/agent/llm_client.rb +413 -0
- data/lib/context_drop/agent/orchestrator.rb +314 -0
- data/lib/context_drop/agent/workspace_sandbox.rb +499 -0
- data/lib/context_drop/configuration.rb +242 -3
- data/lib/context_drop/mcp/dispatcher.rb +71 -29
- data/lib/context_drop/mcp/environment_router.rb +115 -0
- data/lib/context_drop/mcp/prompts/investigate_feedback.rb +90 -9
- data/lib/context_drop/mcp/remote_client.rb +120 -0
- data/lib/context_drop/mcp/server.rb +9 -2
- data/lib/context_drop/mcp/tools/get_feedback.rb +62 -5
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +29 -4
- data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +195 -23
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +48 -5
- data/lib/context_drop/version.rb +1 -1
- data/lib/context_drop.rb +8 -2
- data/lib/generators/context_drop/install/templates/initializer.rb.tt +29 -2
- metadata +14 -2
|
@@ -4,12 +4,14 @@ import {
|
|
|
4
4
|
captureElementSnapshot,
|
|
5
5
|
computeDomPath,
|
|
6
6
|
computeSelector,
|
|
7
|
+
describeSmartComponent,
|
|
7
8
|
extractSanitizedAttributes,
|
|
8
9
|
extractSanitizedText,
|
|
9
10
|
isElementExcluded,
|
|
10
11
|
isSelectableElement,
|
|
11
12
|
resolveAncestorChain,
|
|
12
|
-
resolveCandidateStack
|
|
13
|
+
resolveCandidateStack,
|
|
14
|
+
resolveSmartComponent
|
|
13
15
|
} from "../sanitizer.ts";
|
|
14
16
|
import { ElementPicker } from "../element-picker.ts";
|
|
15
17
|
import { ContextDropWidgetElement } from "../widget.ts";
|
|
@@ -316,6 +318,57 @@ describe("ContextDrop Frontend DOM Sanitizer & Snapshot Capture", () => {
|
|
|
316
318
|
assert.equal(picker.selectElementDirectly(btn as unknown as Element), true);
|
|
317
319
|
assert.equal(selectedRef, "#submit-order");
|
|
318
320
|
});
|
|
321
|
+
|
|
322
|
+
it("promotes leaf nodes to meaningful UI components with plain-language labels in smart mode", () => {
|
|
323
|
+
const iconSpan = new MockElement({
|
|
324
|
+
tagName: "SPAN",
|
|
325
|
+
attributes: { class: "btn-label" },
|
|
326
|
+
children: [new MockTextNode("Pay $49.00")],
|
|
327
|
+
rect: { x: 88, y: 188, width: 90, height: 18 }
|
|
328
|
+
});
|
|
329
|
+
const payButton = new MockElement({
|
|
330
|
+
tagName: "BUTTON",
|
|
331
|
+
attributes: { id: "pay-btn" },
|
|
332
|
+
children: [iconSpan],
|
|
333
|
+
rect: { x: 80, y: 180, width: 160, height: 42 }
|
|
334
|
+
});
|
|
335
|
+
const planHeading = new MockElement({
|
|
336
|
+
tagName: "H3",
|
|
337
|
+
children: [new MockTextNode("Pro Plan")],
|
|
338
|
+
rect: { x: 64, y: 112, width: 140, height: 24 }
|
|
339
|
+
});
|
|
340
|
+
const planParagraph = new MockElement({
|
|
341
|
+
tagName: "P",
|
|
342
|
+
attributes: { class: "fine-print" },
|
|
343
|
+
children: [new MockTextNode("Includes automated backups and regional failover.")],
|
|
344
|
+
rect: { x: 64, y: 144, width: 260, height: 28 }
|
|
345
|
+
});
|
|
346
|
+
const pricingCard = new MockElement({
|
|
347
|
+
tagName: "DIV",
|
|
348
|
+
attributes: { class: "pricing-card" },
|
|
349
|
+
children: [planHeading, planParagraph, payButton],
|
|
350
|
+
rect: { x: 52, y: 96, width: 320, height: 210 }
|
|
351
|
+
});
|
|
352
|
+
const giantMain = new MockElement({
|
|
353
|
+
tagName: "MAIN",
|
|
354
|
+
attributes: { id: "page-shell" },
|
|
355
|
+
children: [pricingCard],
|
|
356
|
+
rect: { x: 0, y: 0, width: 1280, height: 800 }
|
|
357
|
+
});
|
|
358
|
+
|
|
359
|
+
// 1. Inner <span> inside <button> promotes to the interactive button
|
|
360
|
+
const promotedBtn = resolveSmartComponent(iconSpan as unknown as Element);
|
|
361
|
+
assert.equal(promotedBtn, payButton);
|
|
362
|
+
assert.equal(describeSmartComponent(promotedBtn!).label, "“Pay $49.00” button");
|
|
363
|
+
|
|
364
|
+
// 2. Paragraph leaf inside .pricing-card promotes to the bounded card (and NOT full-page <main>)
|
|
365
|
+
const promotedCard = resolveSmartComponent(planParagraph as unknown as Element);
|
|
366
|
+
assert.equal(promotedCard, pricingCard);
|
|
367
|
+
assert.equal(describeSmartComponent(promotedCard!).label, "“Pro Plan” card");
|
|
368
|
+
|
|
369
|
+
// 3. Direct giant <main> shell is not treated as a bounded smart component when better targets exist
|
|
370
|
+
assert.ok(giantMain);
|
|
371
|
+
});
|
|
319
372
|
});
|
|
320
373
|
|
|
321
374
|
interface MockListenerEntry {
|
|
@@ -331,6 +384,7 @@ class MockUiEvent {
|
|
|
331
384
|
public readonly deltaY: number;
|
|
332
385
|
public readonly deltaMode: number;
|
|
333
386
|
public readonly key: string;
|
|
387
|
+
public readonly code: string;
|
|
334
388
|
public readonly shiftKey: boolean;
|
|
335
389
|
public readonly altKey: boolean;
|
|
336
390
|
public readonly ctrlKey: boolean;
|
|
@@ -439,8 +493,12 @@ class MockDomElement {
|
|
|
439
493
|
public placeholder: string = "";
|
|
440
494
|
public value: string = "";
|
|
441
495
|
public disabled: boolean = false;
|
|
496
|
+
public selected: boolean = false;
|
|
497
|
+
public autocomplete: string = "";
|
|
442
498
|
public multiple: boolean = false;
|
|
443
499
|
public accept: string = "";
|
|
500
|
+
public src: string = "";
|
|
501
|
+
public alt: string = "";
|
|
444
502
|
public scrollTop: number = 0;
|
|
445
503
|
public scrollHeight: number = 0;
|
|
446
504
|
private rawHtml: string = "";
|
|
@@ -654,13 +712,24 @@ function withMountedWidget(
|
|
|
654
712
|
widget: ContextDropWidgetElement;
|
|
655
713
|
shadowRoot: MockDomElement;
|
|
656
714
|
mockBody: MockDomElement;
|
|
715
|
+
mockHtml: MockDomElement;
|
|
657
716
|
mockDocument: {
|
|
658
717
|
body: MockDomElement;
|
|
718
|
+
documentElement: MockDomElement;
|
|
659
719
|
createElement: (tag: string) => MockDomElement;
|
|
720
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
660
721
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
661
722
|
};
|
|
662
723
|
mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
|
|
663
|
-
}) => void | Promise<void
|
|
724
|
+
}) => void | Promise<void>,
|
|
725
|
+
hostAttrs: Record<string, string> = {
|
|
726
|
+
"data-config": JSON.stringify({
|
|
727
|
+
enabled: true,
|
|
728
|
+
environment: "staging",
|
|
729
|
+
position: "bottom_right",
|
|
730
|
+
agent: { enabled: false }
|
|
731
|
+
})
|
|
732
|
+
}
|
|
664
733
|
): Promise<void> {
|
|
665
734
|
const g = globalThis as Record<string, unknown>;
|
|
666
735
|
const prevWindow = g.window;
|
|
@@ -671,14 +740,21 @@ function withMountedWidget(
|
|
|
671
740
|
innerHeight: 800,
|
|
672
741
|
location: { href: "http://localhost:3000/orders" }
|
|
673
742
|
});
|
|
743
|
+
const mockHtml = new MockDomElement("html");
|
|
674
744
|
const mockBody = new MockDomElement("body");
|
|
745
|
+
mockHtml.appendChild(mockBody);
|
|
746
|
+
|
|
675
747
|
const mockDocument: {
|
|
676
748
|
body: MockDomElement;
|
|
749
|
+
documentElement: MockDomElement;
|
|
677
750
|
createElement: (tag: string) => MockDomElement;
|
|
751
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
678
752
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
679
753
|
} = {
|
|
680
754
|
body: mockBody,
|
|
681
|
-
|
|
755
|
+
documentElement: mockHtml,
|
|
756
|
+
createElement: (tag: string) => new MockDomElement(tag),
|
|
757
|
+
querySelector: () => null
|
|
682
758
|
};
|
|
683
759
|
|
|
684
760
|
g.window = mockWindow;
|
|
@@ -686,17 +762,45 @@ function withMountedWidget(
|
|
|
686
762
|
|
|
687
763
|
const shadowRoot = new MockDomElement("shadow-root");
|
|
688
764
|
const widget = new ContextDropWidgetElement();
|
|
765
|
+
const widgetListeners: Map<string, Array<(ev: unknown) => void>> = new Map();
|
|
766
|
+
const hostAttrsMap = new Map<string, string>(Object.entries(hostAttrs));
|
|
689
767
|
const hostShim = widget as unknown as {
|
|
690
768
|
attachShadow: () => ShadowRoot;
|
|
691
769
|
getAttribute: (name: string) => string | null;
|
|
770
|
+
setAttribute: (name: string, value: string) => void;
|
|
771
|
+
hasAttribute: (name: string) => boolean;
|
|
772
|
+
addEventListener: (type: string, listener: (ev: unknown) => void) => void;
|
|
773
|
+
removeEventListener: (type: string, listener: (ev: unknown) => void) => void;
|
|
774
|
+
dispatchEvent: (event: { type: string }) => boolean;
|
|
692
775
|
};
|
|
693
776
|
hostShim.attachShadow = () => shadowRoot as unknown as ShadowRoot;
|
|
694
|
-
hostShim.getAttribute = () => null;
|
|
777
|
+
hostShim.getAttribute = (name: string) => hostAttrsMap.get(name) ?? null;
|
|
778
|
+
hostShim.setAttribute = (name: string, value: string) => {
|
|
779
|
+
hostAttrsMap.set(name, value);
|
|
780
|
+
};
|
|
781
|
+
hostShim.hasAttribute = (name: string) => hostAttrsMap.has(name);
|
|
782
|
+
hostShim.addEventListener = (type: string, listener: (ev: unknown) => void) => {
|
|
783
|
+
const list = widgetListeners.get(type) || [];
|
|
784
|
+
list.push(listener);
|
|
785
|
+
widgetListeners.set(type, list);
|
|
786
|
+
};
|
|
787
|
+
hostShim.removeEventListener = (type: string, listener: (ev: unknown) => void) => {
|
|
788
|
+
const list = widgetListeners.get(type) || [];
|
|
789
|
+
widgetListeners.set(
|
|
790
|
+
type,
|
|
791
|
+
list.filter((l) => l !== listener)
|
|
792
|
+
);
|
|
793
|
+
};
|
|
794
|
+
hostShim.dispatchEvent = (event: { type: string }) => {
|
|
795
|
+
const list = widgetListeners.get(event.type) || [];
|
|
796
|
+
for (const l of list) l(event);
|
|
797
|
+
return true;
|
|
798
|
+
};
|
|
695
799
|
|
|
696
800
|
widget.connectedCallback();
|
|
697
801
|
|
|
698
802
|
return Promise.resolve()
|
|
699
|
-
.then(() => fn({ widget, shadowRoot, mockBody, mockDocument, mockWindow }))
|
|
803
|
+
.then(() => fn({ widget, shadowRoot, mockBody, mockHtml, mockDocument, mockWindow }))
|
|
700
804
|
.finally(() => {
|
|
701
805
|
widget.disconnectedCallback();
|
|
702
806
|
if (prevWindow === undefined) {
|
|
@@ -712,126 +816,323 @@ function withMountedWidget(
|
|
|
712
816
|
});
|
|
713
817
|
}
|
|
714
818
|
|
|
715
|
-
describe("ContextDrop
|
|
716
|
-
it("
|
|
819
|
+
describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
|
|
820
|
+
it("opens standard feedback chatbox when book corner is clicked or keyboard-activated", async () => {
|
|
717
821
|
await withMountedWidget(({ shadowRoot, mockWindow }) => {
|
|
718
|
-
const
|
|
719
|
-
const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
|
|
720
|
-
const triggerBtn = shadowRoot.querySelector(".cd-trigger");
|
|
822
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
721
823
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
824
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
722
825
|
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
723
826
|
|
|
724
|
-
assert.ok(
|
|
827
|
+
assert.ok(bookCorner && composer && sidebar && compactBar);
|
|
828
|
+
assert.equal(bookCorner.hidden, false);
|
|
829
|
+
assert.equal(bookCorner.classList.contains("corner-bottom_right"), true);
|
|
725
830
|
assert.equal(composer.hidden, true);
|
|
831
|
+
assert.equal(sidebar.hidden, true);
|
|
726
832
|
assert.equal(compactBar.hidden, true);
|
|
727
|
-
assert.equal(pinDock.hidden, false);
|
|
728
833
|
|
|
729
|
-
//
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
triggerSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 40, clientY: 30 }));
|
|
834
|
+
// Pointer click without drag opens normal floating feedback composer
|
|
835
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 16, clientY: 16 }));
|
|
836
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 18, clientY: 18 }));
|
|
837
|
+
bookCorner.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 18, clientY: 18 }));
|
|
734
838
|
|
|
735
839
|
assert.equal(composer.hidden, false);
|
|
736
|
-
assert.equal(
|
|
737
|
-
assert.equal(
|
|
840
|
+
assert.equal(bookCorner.hidden, true);
|
|
841
|
+
assert.equal(bookCorner.getAttribute("aria-expanded"), "true");
|
|
738
842
|
|
|
739
|
-
// Close composer to
|
|
843
|
+
// Close composer returns to flush book corner
|
|
740
844
|
const closeBtn = shadowRoot.querySelector("[aria-label='Close feedback composer']");
|
|
741
845
|
assert.ok(closeBtn);
|
|
742
846
|
closeBtn.dispatchEvent(new MockUiEvent("click"));
|
|
743
847
|
assert.equal(composer.hidden, true);
|
|
744
|
-
assert.equal(
|
|
745
|
-
|
|
746
|
-
// Click nested <span>Pin</span> inside .cd-floating-pin-btn
|
|
747
|
-
const pinSpan = floatingPinBtn.querySelector("span") ?? floatingPinBtn;
|
|
748
|
-
pinSpan.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 30, clientY: 30 }));
|
|
749
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 30, clientY: 30 }));
|
|
750
|
-
pinSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 30, clientY: 30 }));
|
|
848
|
+
assert.equal(bookCorner.hidden, false);
|
|
751
849
|
|
|
752
|
-
|
|
753
|
-
|
|
850
|
+
// Keyboard activation (click without pointerdown/pointerup) also opens composer
|
|
851
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
852
|
+
assert.equal(composer.hidden, false);
|
|
754
853
|
});
|
|
755
854
|
});
|
|
756
855
|
|
|
757
|
-
it("
|
|
758
|
-
await withMountedWidget(({ shadowRoot, mockWindow }) => {
|
|
759
|
-
const
|
|
760
|
-
const
|
|
761
|
-
const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
|
|
762
|
-
const triggerBtn = shadowRoot.querySelector(".cd-trigger");
|
|
856
|
+
it("morphs book corner into a pushpin when dragged and pins DOM element directly on drop", async () => {
|
|
857
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
858
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
859
|
+
const dragPin = shadowRoot.querySelector(".cd-drag-pin");
|
|
763
860
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
764
|
-
const
|
|
861
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
862
|
+
assert.ok(bookCorner && dragPin && composer && tray);
|
|
765
863
|
|
|
766
|
-
|
|
864
|
+
const checkoutBtn = new MockDomElement("button");
|
|
865
|
+
checkoutBtn.setAttribute("id", "checkout-btn");
|
|
866
|
+
checkoutBtn.textContent = "Complete Order";
|
|
867
|
+
checkoutBtn.setRect({ left: 220, top: 180, width: 180, height: 44 });
|
|
868
|
+
mockBody.appendChild(checkoutBtn);
|
|
767
869
|
|
|
768
|
-
|
|
769
|
-
floatingPinBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 50, clientY: 50 }));
|
|
770
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 150, clientY: 120 }));
|
|
771
|
-
assert.equal(pinDock.classList.contains("is-dragging"), true);
|
|
772
|
-
assert.equal(root.classList.contains("is-free-positioned"), true);
|
|
773
|
-
assert.equal(root.style.left, "120px");
|
|
774
|
-
assert.equal(root.style.top, "90px");
|
|
870
|
+
mockDocument.elementsFromPoint = () => [checkoutBtn];
|
|
775
871
|
|
|
776
|
-
|
|
777
|
-
|
|
872
|
+
// Start peeling from top-left book corner
|
|
873
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 14, clientY: 14 }));
|
|
874
|
+
assert.equal(dragPin.hidden, true);
|
|
778
875
|
|
|
779
|
-
//
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
assert.equal(
|
|
783
|
-
assert.equal(
|
|
784
|
-
assert.equal(composer.hidden, true);
|
|
876
|
+
// Drag >6px over #checkout-btn: book corner peels away & morphs into live pushpin
|
|
877
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 260, clientY: 200 }));
|
|
878
|
+
assert.equal(bookCorner.classList.contains("is-peeled"), true);
|
|
879
|
+
assert.equal(dragPin.hidden, false);
|
|
880
|
+
assert.equal(dragPin.classList.contains("has-target"), true);
|
|
785
881
|
|
|
786
|
-
//
|
|
787
|
-
|
|
788
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 210, clientY: 180 }));
|
|
789
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 210, clientY: 180 }));
|
|
790
|
-
const triggerSyntheticClick = new MockUiEvent("click", { clientX: 210, clientY: 180 });
|
|
791
|
-
triggerBtn.dispatchEvent(triggerSyntheticClick);
|
|
792
|
-
assert.equal(triggerSyntheticClick.defaultPrevented, true);
|
|
793
|
-
assert.equal(composer.hidden, true);
|
|
794
|
-
assert.equal(root.style.left, "180px");
|
|
795
|
-
assert.equal(root.style.top, "150px");
|
|
882
|
+
// Release pointer over #checkout-btn: commits pin and opens composer with chip attached
|
|
883
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 260, clientY: 200 }));
|
|
796
884
|
|
|
797
|
-
//
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
885
|
+
// Trailing synthetic click from browser is suppressed cleanly
|
|
886
|
+
const trailingClick = new MockUiEvent("click", { clientX: 260, clientY: 200 });
|
|
887
|
+
bookCorner.dispatchEvent(trailingClick);
|
|
888
|
+
assert.equal(trailingClick.defaultPrevented, true);
|
|
889
|
+
|
|
890
|
+
assert.equal(dragPin.hidden, true);
|
|
891
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
892
|
+
assert.equal(widget.getElementReferences()[0].selector, "#checkout-btn");
|
|
801
893
|
assert.equal(composer.hidden, false);
|
|
894
|
+
assert.ok(tray.querySelector(".cd-chip"));
|
|
802
895
|
});
|
|
803
896
|
});
|
|
804
897
|
|
|
805
|
-
it("
|
|
806
|
-
await withMountedWidget(
|
|
807
|
-
const
|
|
808
|
-
const
|
|
898
|
+
it("snaps and re-docks book corner when dragged into another viewport corner", async () => {
|
|
899
|
+
await withMountedWidget(({ widget, shadowRoot, mockWindow }) => {
|
|
900
|
+
const root = shadowRoot.querySelector(".cd-root");
|
|
901
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
902
|
+
const snapGhost = shadowRoot.querySelector(".cd-corner-snap-ghost");
|
|
809
903
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
810
|
-
|
|
904
|
+
assert.ok(root && bookCorner && snapGhost && composer);
|
|
905
|
+
|
|
906
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 12, clientY: 12 }));
|
|
907
|
+
// Move across page first
|
|
908
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 420, clientY: 340 }));
|
|
909
|
+
assert.equal(snapGhost.hidden, true);
|
|
910
|
+
|
|
911
|
+
// Enter bottom-right snap zone (viewport is 1280x800)
|
|
912
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 1250, clientY: 775 }));
|
|
913
|
+
assert.equal(snapGhost.hidden, false);
|
|
914
|
+
assert.equal(snapGhost.classList.contains("corner-bottom_right"), true);
|
|
915
|
+
|
|
916
|
+
// Release inside bottom-right snap zone: re-docks corner and stays closed
|
|
917
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 1250, clientY: 775 }));
|
|
918
|
+
assert.equal(snapGhost.hidden, true);
|
|
919
|
+
assert.equal(widget.getConfig().position, "bottom_right");
|
|
920
|
+
assert.equal(bookCorner.classList.contains("corner-bottom_right"), true);
|
|
921
|
+
assert.equal(root.classList.contains("pos-bottom_right"), true);
|
|
922
|
+
assert.equal(composer.hidden, true);
|
|
923
|
+
assert.equal(bookCorner.hidden, false);
|
|
924
|
+
});
|
|
925
|
+
});
|
|
811
926
|
|
|
812
|
-
|
|
927
|
+
it("transforms into local BYOK agentic sidebar in development, switches modes, saves keys safely, and applies staged diffs", async () => {
|
|
928
|
+
const g = globalThis as Record<string, unknown>;
|
|
929
|
+
const prevFetch = g.fetch;
|
|
930
|
+
const apiCalls: Array<{ url: string; method: string; body?: unknown }> = [];
|
|
931
|
+
|
|
932
|
+
g.fetch = async (input: string | URL, init?: RequestInit) => {
|
|
933
|
+
const url = String(input);
|
|
934
|
+
const method = (init?.method || "GET").toUpperCase();
|
|
935
|
+
const parsedBody =
|
|
936
|
+
typeof init?.body === "string" && init.body.length > 0 ? JSON.parse(init.body) : undefined;
|
|
937
|
+
apiCalls.push({ url, method, body: parsedBody });
|
|
938
|
+
|
|
939
|
+
if (url.endsWith("/agent/status")) {
|
|
940
|
+
return new Response(
|
|
941
|
+
JSON.stringify({
|
|
942
|
+
enabled: true,
|
|
943
|
+
environment: "development",
|
|
944
|
+
workspace_name: "demo-shop",
|
|
945
|
+
mcp_environments: [
|
|
946
|
+
{ name: "local", type: "local", host_env: "development" },
|
|
947
|
+
{ name: "staging", type: "remote_http" },
|
|
948
|
+
{ name: "production", type: "remote_http" }
|
|
949
|
+
],
|
|
950
|
+
active_provider: "anthropic",
|
|
951
|
+
providers: [
|
|
952
|
+
{
|
|
953
|
+
id: "anthropic",
|
|
954
|
+
label: "Anthropic Claude",
|
|
955
|
+
configured: true,
|
|
956
|
+
source: "env",
|
|
957
|
+
env_var_hint: "ANTHROPIC_API_KEY",
|
|
958
|
+
masked_key: "••••9876",
|
|
959
|
+
model: "claude-sonnet-4-20250514",
|
|
960
|
+
default_model: "claude-sonnet-4-20250514",
|
|
961
|
+
models: ["claude-sonnet-4-20250514"],
|
|
962
|
+
supports_base_url: false
|
|
963
|
+
}
|
|
964
|
+
]
|
|
965
|
+
}),
|
|
966
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
967
|
+
);
|
|
968
|
+
}
|
|
813
969
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
970
|
+
if (url.endsWith("/agent/keys") && method === "POST") {
|
|
971
|
+
return new Response(
|
|
972
|
+
JSON.stringify({
|
|
973
|
+
active_provider: "anthropic",
|
|
974
|
+
providers: [
|
|
975
|
+
{
|
|
976
|
+
id: "anthropic",
|
|
977
|
+
label: "Anthropic Claude",
|
|
978
|
+
configured: true,
|
|
979
|
+
source: "vault",
|
|
980
|
+
env_var_hint: "ANTHROPIC_API_KEY",
|
|
981
|
+
masked_key: "••••4321",
|
|
982
|
+
model: "claude-sonnet-4-20250514",
|
|
983
|
+
default_model: "claude-sonnet-4-20250514",
|
|
984
|
+
models: ["claude-sonnet-4-20250514"],
|
|
985
|
+
supports_base_url: false
|
|
986
|
+
}
|
|
987
|
+
]
|
|
988
|
+
}),
|
|
989
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
990
|
+
);
|
|
991
|
+
}
|
|
817
992
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
993
|
+
if (url.endsWith("/agent/chat") && method === "POST") {
|
|
994
|
+
return new Response(
|
|
995
|
+
JSON.stringify({
|
|
996
|
+
reply: "Found `#hero-cta` in `app/views/home/index.html.erb`. Escaped check: <script>alert(1)</script>",
|
|
997
|
+
provider: "anthropic",
|
|
998
|
+
model: "claude-sonnet-4-20250514",
|
|
999
|
+
tool_calls: [{ name: "read_file", summary: "Read app/views/home/index.html.erb (L1–40)", status: "ok" }],
|
|
1000
|
+
proposed_edits: [
|
|
1001
|
+
{
|
|
1002
|
+
id: "edit_abc123",
|
|
1003
|
+
path: "app/views/home/index.html.erb",
|
|
1004
|
+
summary: "Fix button contrast and padding",
|
|
1005
|
+
is_new_file: false,
|
|
1006
|
+
diff: "@@ -4,1 +4,1 @@\n-<button id=\"hero-cta\">Buy</button>\n+<button id=\"hero-cta\" class=\"btn-primary\">Buy Now</button>",
|
|
1007
|
+
added_lines: 1,
|
|
1008
|
+
removed_lines: 1,
|
|
1009
|
+
status: "pending",
|
|
1010
|
+
created_at: "2026-11-12T10:00:00Z"
|
|
1011
|
+
}
|
|
1012
|
+
]
|
|
1013
|
+
}),
|
|
1014
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1015
|
+
);
|
|
1016
|
+
}
|
|
823
1017
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
1018
|
+
if (url.endsWith("/agent/edits/edit_abc123/apply") && method === "POST") {
|
|
1019
|
+
return new Response(
|
|
1020
|
+
JSON.stringify({
|
|
1021
|
+
edit: {
|
|
1022
|
+
id: "edit_abc123",
|
|
1023
|
+
path: "app/views/home/index.html.erb",
|
|
1024
|
+
summary: "Fix button contrast and padding",
|
|
1025
|
+
is_new_file: false,
|
|
1026
|
+
diff: "@@ -4,1 +4,1 @@",
|
|
1027
|
+
added_lines: 1,
|
|
1028
|
+
removed_lines: 1,
|
|
1029
|
+
status: "applied",
|
|
1030
|
+
created_at: "2026-11-12T10:00:00Z"
|
|
1031
|
+
}
|
|
1032
|
+
}),
|
|
1033
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1034
|
+
);
|
|
1035
|
+
}
|
|
828
1036
|
|
|
829
|
-
|
|
1037
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
1038
|
+
};
|
|
830
1039
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
1040
|
+
try {
|
|
1041
|
+
await withMountedWidget(
|
|
1042
|
+
async ({ widget, shadowRoot, mockHtml }) => {
|
|
1043
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1044
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1045
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1046
|
+
assert.ok(bookCorner && sidebar && composer);
|
|
1047
|
+
|
|
1048
|
+
// Clicking book corner in local dev opens Agentic Sidebar, not floating composer
|
|
1049
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1050
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1051
|
+
|
|
1052
|
+
assert.equal(widget.getSurfaceMode(), "agent");
|
|
1053
|
+
assert.equal(sidebar.hidden, false);
|
|
1054
|
+
assert.equal(composer.hidden, true);
|
|
1055
|
+
|
|
1056
|
+
// Push page layout toggle sets and clears marginRight on <html>
|
|
1057
|
+
const pushBtn = shadowRoot.querySelector("[aria-label='Toggle push page layout']");
|
|
1058
|
+
assert.ok(pushBtn);
|
|
1059
|
+
pushBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1060
|
+
assert.equal(mockHtml.getAttribute("data-context-drop-pushed"), "true");
|
|
1061
|
+
assert.equal(mockHtml.style.marginRight, "560px");
|
|
1062
|
+
|
|
1063
|
+
// Switching mode to "feedback" switches cleanly to floating composer and restores page layout
|
|
1064
|
+
widget.setSurfaceMode("feedback");
|
|
1065
|
+
assert.equal(sidebar.hidden, true);
|
|
1066
|
+
assert.equal(composer.hidden, false);
|
|
1067
|
+
assert.equal(mockHtml.style.marginRight, "");
|
|
1068
|
+
|
|
1069
|
+
// Switch back to "agent" mode
|
|
1070
|
+
widget.setSurfaceMode("agent");
|
|
1071
|
+
assert.equal(sidebar.hidden, false);
|
|
1072
|
+
|
|
1073
|
+
// Save BYOK key via inline vault drawer: clears password input immediately after save
|
|
1074
|
+
const byokBtn = shadowRoot.querySelector("[aria-label='Open BYOK API key settings']");
|
|
1075
|
+
const keyInput = shadowRoot.querySelector("[aria-label='Provider API Key']");
|
|
1076
|
+
assert.ok(byokBtn && keyInput);
|
|
1077
|
+
byokBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1078
|
+
keyInput.value = "sk-ant-test-secret-4321";
|
|
1079
|
+
|
|
1080
|
+
const allButtons: MockDomElement[] = [];
|
|
1081
|
+
const collectBtns = (node: MockDomElement): void => {
|
|
1082
|
+
if (node.tagName === "BUTTON") allButtons.push(node);
|
|
1083
|
+
for (const c of node.childNodes) collectBtns(c);
|
|
1084
|
+
};
|
|
1085
|
+
collectBtns(shadowRoot);
|
|
1086
|
+
const saveBtn = allButtons.find((b) => b.textContent === "Use & Save");
|
|
1087
|
+
assert.ok(saveBtn);
|
|
1088
|
+
saveBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1089
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1090
|
+
assert.equal(keyInput.value, "", "Expected API key input to be wiped from DOM after vault save");
|
|
1091
|
+
|
|
1092
|
+
// Send an agent prompt and verify XSS-safe Markdown + interactive diff approval
|
|
1093
|
+
const agentTextarea = shadowRoot.querySelector("[aria-label='Agent prompt']");
|
|
1094
|
+
assert.ok(agentTextarea);
|
|
1095
|
+
agentTextarea.value = "Fix #hero-cta contrast";
|
|
1096
|
+
await widget.handleAgentSubmit();
|
|
1097
|
+
|
|
1098
|
+
const messages = widget.getAgentMessages();
|
|
1099
|
+
assert.equal(messages.length, 2);
|
|
1100
|
+
const mdBody = shadowRoot.querySelector(".cd-md-body");
|
|
1101
|
+
assert.ok(mdBody);
|
|
1102
|
+
assert.equal(mdBody.innerHTML.includes("<script>"), false, "Raw <script> must be HTML-escaped");
|
|
1103
|
+
assert.equal(mdBody.innerHTML.includes("<script>"), true);
|
|
1104
|
+
|
|
1105
|
+
const diffCard = shadowRoot.querySelector(".cd-diff-card");
|
|
1106
|
+
assert.ok(diffCard);
|
|
1107
|
+
const applyBtn = diffCard.querySelector(".cd-btn-apply");
|
|
1108
|
+
assert.ok(applyBtn);
|
|
1109
|
+
|
|
1110
|
+
applyBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1111
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1112
|
+
|
|
1113
|
+
assert.equal(messages[1].proposedEdits?.[0].status, "applied");
|
|
1114
|
+
assert.equal(
|
|
1115
|
+
apiCalls.some((c) => c.url.endsWith("/agent/edits/edit_abc123/apply")),
|
|
1116
|
+
true
|
|
1117
|
+
);
|
|
1118
|
+
},
|
|
1119
|
+
{
|
|
1120
|
+
"data-config": JSON.stringify({
|
|
1121
|
+
enabled: true,
|
|
1122
|
+
environment: "development",
|
|
1123
|
+
position: "top_left",
|
|
1124
|
+
csrf_token: "dev_csrf_123",
|
|
1125
|
+
agent: { enabled: true }
|
|
1126
|
+
})
|
|
1127
|
+
}
|
|
1128
|
+
);
|
|
1129
|
+
} finally {
|
|
1130
|
+
if (prevFetch === undefined) {
|
|
1131
|
+
delete g.fetch;
|
|
1132
|
+
} else {
|
|
1133
|
+
g.fetch = prevFetch;
|
|
1134
|
+
}
|
|
1135
|
+
}
|
|
835
1136
|
});
|
|
836
1137
|
|
|
837
1138
|
it("ignores nested buttons inside container drag bars (.cd-composer-header, .cd-compact-bar)", async () => {
|
|
@@ -1037,4 +1338,629 @@ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
|
|
|
1037
1338
|
assert.equal(composer.hidden, false);
|
|
1038
1339
|
});
|
|
1039
1340
|
});
|
|
1341
|
+
|
|
1342
|
+
it("uses jargon-free smart component selection, auto surrounding screenshot, and compact UI in production", async () => {
|
|
1343
|
+
await withMountedWidget(
|
|
1344
|
+
async ({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
1345
|
+
// Provide a lightweight mock <canvas> 2D context so surrounding-context auto-screenshot succeeds
|
|
1346
|
+
const origCreateElement = mockDocument.createElement;
|
|
1347
|
+
mockDocument.createElement = (tag: string) => {
|
|
1348
|
+
const el = origCreateElement(tag);
|
|
1349
|
+
if (tag.toLowerCase() === "canvas") {
|
|
1350
|
+
const canvasShim = el as unknown as Record<string, unknown>;
|
|
1351
|
+
canvasShim.width = 0;
|
|
1352
|
+
canvasShim.height = 0;
|
|
1353
|
+
canvasShim.getContext = () => ({
|
|
1354
|
+
scale: () => {},
|
|
1355
|
+
fillRect: () => {},
|
|
1356
|
+
strokeRect: () => {},
|
|
1357
|
+
fillText: () => {},
|
|
1358
|
+
setLineDash: () => {},
|
|
1359
|
+
fillStyle: "",
|
|
1360
|
+
strokeStyle: "",
|
|
1361
|
+
lineWidth: 1,
|
|
1362
|
+
font: ""
|
|
1363
|
+
});
|
|
1364
|
+
canvasShim.toDataURL = () =>
|
|
1365
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
1366
|
+
}
|
|
1367
|
+
return el;
|
|
1368
|
+
};
|
|
1369
|
+
|
|
1370
|
+
assert.equal(widget.isSmartSelectionMode(), true);
|
|
1371
|
+
|
|
1372
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1373
|
+
const title = shadowRoot.querySelector(".cd-composer-title");
|
|
1374
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
1375
|
+
const chatThread = shadowRoot.querySelector(".cd-chat-thread");
|
|
1376
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1377
|
+
assert.ok(composer && title && tray && chatThread && bookCorner);
|
|
1378
|
+
|
|
1379
|
+
// Production UI uses compact smart-mode layout & friendly copy
|
|
1380
|
+
assert.equal(composer.classList.contains("is-smart-mode"), true);
|
|
1381
|
+
assert.equal(title.textContent, "Send Feedback");
|
|
1382
|
+
|
|
1383
|
+
// Build host DOM: div.pricing-card > (h3 "Enterprise Plan", button#checkout-btn > span.inner-label "Complete Order")
|
|
1384
|
+
const card = new MockDomElement("div");
|
|
1385
|
+
card.setAttribute("class", "pricing-card");
|
|
1386
|
+
card.setRect({ left: 80, top: 90, width: 340, height: 210 });
|
|
1387
|
+
|
|
1388
|
+
const heading = new MockDomElement("h3");
|
|
1389
|
+
heading.textContent = "Enterprise Plan";
|
|
1390
|
+
heading.setRect({ left: 100, top: 108, width: 180, height: 26 });
|
|
1391
|
+
|
|
1392
|
+
const button = new MockDomElement("button");
|
|
1393
|
+
button.setAttribute("id", "checkout-btn");
|
|
1394
|
+
button.setRect({ left: 100, top: 220, width: 170, height: 42 });
|
|
1395
|
+
|
|
1396
|
+
const innerSpan = new MockDomElement("span");
|
|
1397
|
+
innerSpan.setAttribute("class", "inner-label");
|
|
1398
|
+
innerSpan.textContent = "Complete Order";
|
|
1399
|
+
innerSpan.setRect({ left: 116, top: 230, width: 120, height: 20 });
|
|
1400
|
+
|
|
1401
|
+
button.appendChild(innerSpan);
|
|
1402
|
+
card.appendChild(heading);
|
|
1403
|
+
card.appendChild(button);
|
|
1404
|
+
mockBody.appendChild(card);
|
|
1405
|
+
|
|
1406
|
+
mockDocument.elementsFromPoint = () => [innerSpan, button, card];
|
|
1407
|
+
|
|
1408
|
+
// Start selection from compact composer ("Select area")
|
|
1409
|
+
widget.startPinSelection();
|
|
1410
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 140, clientY: 236 }));
|
|
1411
|
+
|
|
1412
|
+
const hud = mockBody.querySelector("[data-context-drop-ui='label']");
|
|
1413
|
+
assert.ok(hud);
|
|
1414
|
+
const readAllText = (node: MockDomElement): string =>
|
|
1415
|
+
[node.textContent, ...node.childNodes.map((c) => readAllText(c))].join(" ").trim();
|
|
1416
|
+
const hudText = readAllText(hud);
|
|
1417
|
+
assert.equal(hudText.includes("“Complete Order” button"), true);
|
|
1418
|
+
assert.equal(hudText.includes("#checkout-btn"), false, "Smart HUD must omit CSS selectors");
|
|
1419
|
+
assert.equal(hud.querySelector("[data-context-drop-ui='hud-layer-list']"), null);
|
|
1420
|
+
|
|
1421
|
+
// Mouse wheel is NOT hijacked in production smart mode
|
|
1422
|
+
const wheelEv = new MockUiEvent("wheel", { clientX: 140, clientY: 236, deltaY: 40, deltaMode: 0 });
|
|
1423
|
+
mockWindow.dispatchEvent(wheelEv);
|
|
1424
|
+
assert.equal(wheelEv.defaultPrevented, false);
|
|
1425
|
+
|
|
1426
|
+
// Single click selects promoted button, exits picker immediately, and reopens compact feedback form
|
|
1427
|
+
const clickEv = new MockUiEvent("click", { clientX: 140, clientY: 236 });
|
|
1428
|
+
mockWindow.dispatchEvent(clickEv);
|
|
1429
|
+
assert.equal(clickEv.defaultPrevented, true);
|
|
1430
|
+
assert.equal(composer.hidden, false);
|
|
1431
|
+
|
|
1432
|
+
// Wait a tick for async surrounding-context screenshot capture
|
|
1433
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1434
|
+
|
|
1435
|
+
const refs = widget.getElementReferences();
|
|
1436
|
+
assert.equal(refs.length, 1);
|
|
1437
|
+
assert.equal(refs[0].selector, "#checkout-btn");
|
|
1438
|
+
assert.equal(refs[0].metadata.friendly_label, "“Complete Order” button");
|
|
1439
|
+
assert.equal(refs[0].metadata.original_target_selector, "span.inner-label");
|
|
1440
|
+
|
|
1441
|
+
const shots = widget.getAttachments();
|
|
1442
|
+
assert.equal(shots.length, 1);
|
|
1443
|
+
assert.equal(shots[0].element_reference_ref, refs[0].client_ref);
|
|
1444
|
+
assert.equal(shots[0].metadata?.capture_type, "surrounding_context");
|
|
1445
|
+
assert.equal(shots[0].metadata?.auto_smart_context, true);
|
|
1446
|
+
|
|
1447
|
+
// Tray renders a single merged .cd-smart-card (not separate technical .cd-chip items)
|
|
1448
|
+
assert.ok(tray.querySelector(".cd-smart-card"));
|
|
1449
|
+
assert.equal(tray.querySelector(".cd-chip"), null);
|
|
1450
|
+
// Empty-state chat thread hides once context is attached so composer stays ultra-compact
|
|
1451
|
+
assert.equal(chatThread.hidden, true);
|
|
1452
|
+
|
|
1453
|
+
// Removing the smart card removes BOTH the element reference and its auto-captured screenshot
|
|
1454
|
+
widget.removeElementReference(refs[0].client_ref);
|
|
1455
|
+
assert.equal(widget.getElementReferences().length, 0);
|
|
1456
|
+
assert.equal(widget.getAttachments().length, 0);
|
|
1457
|
+
assert.equal(chatThread.hidden, false);
|
|
1458
|
+
},
|
|
1459
|
+
{
|
|
1460
|
+
"data-config": JSON.stringify({
|
|
1461
|
+
enabled: true,
|
|
1462
|
+
environment: "production",
|
|
1463
|
+
position: "top_left",
|
|
1464
|
+
agent: { enabled: false }
|
|
1465
|
+
})
|
|
1466
|
+
}
|
|
1467
|
+
);
|
|
1468
|
+
});
|
|
1469
|
+
|
|
1470
|
+
it("supports dark theme toggle on top bar strictly scoped to widget without altering host page theme", async () => {
|
|
1471
|
+
await withMountedWidget(
|
|
1472
|
+
({ widget, shadowRoot, mockHtml, mockBody }) => {
|
|
1473
|
+
// Initially light theme
|
|
1474
|
+
assert.equal(widget.getTheme(), "light");
|
|
1475
|
+
|
|
1476
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1477
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1478
|
+
assert.ok(composer && sidebar);
|
|
1479
|
+
|
|
1480
|
+
const composerThemeToggle = composer.querySelector(".cd-theme-toggle");
|
|
1481
|
+
const sidebarThemeToggle = sidebar.querySelector(".cd-theme-toggle");
|
|
1482
|
+
assert.ok(composerThemeToggle, "Composer top bar has theme toggle button");
|
|
1483
|
+
assert.ok(sidebarThemeToggle, "Agent sidebar top bar has theme toggle button");
|
|
1484
|
+
|
|
1485
|
+
const themeChangeEvents: string[] = [];
|
|
1486
|
+
const onThemeChange = (ev: Event) => {
|
|
1487
|
+
const detail = (ev as CustomEvent).detail;
|
|
1488
|
+
if (detail?.theme) themeChangeEvents.push(detail.theme);
|
|
1489
|
+
};
|
|
1490
|
+
widget.addEventListener("contextdrop:themechange", onThemeChange);
|
|
1491
|
+
|
|
1492
|
+
const leakedWindowEvents: string[] = [];
|
|
1493
|
+
const onWindowThemeChange = (ev: Event) => {
|
|
1494
|
+
const detail = (ev as CustomEvent).detail;
|
|
1495
|
+
if (detail?.theme) leakedWindowEvents.push(detail.theme);
|
|
1496
|
+
};
|
|
1497
|
+
window.addEventListener("contextdrop:themechange", onWindowThemeChange);
|
|
1498
|
+
|
|
1499
|
+
// Click theme toggle in composer
|
|
1500
|
+
composerThemeToggle.dispatchEvent(new MockUiEvent("click"));
|
|
1501
|
+
|
|
1502
|
+
assert.equal(widget.getTheme(), "dark");
|
|
1503
|
+
assert.equal(widget.getAttribute("data-cd-theme"), "dark");
|
|
1504
|
+
assert.equal(widget.getAttribute("data-theme"), null, "Does not set generic data-theme on light-DOM host");
|
|
1505
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null, "Never alters host <html> theme");
|
|
1506
|
+
assert.equal(mockBody.getAttribute("data-theme"), null, "Never alters host <body> theme");
|
|
1507
|
+
assert.equal(shadowRoot.querySelector(".cd-root")?.getAttribute("data-theme"), "dark");
|
|
1508
|
+
assert.equal(shadowRoot.querySelector(".cd-composer")?.getAttribute("data-theme"), "dark");
|
|
1509
|
+
assert.equal(shadowRoot.querySelector(".cd-agent-sidebar")?.getAttribute("data-theme"), "dark");
|
|
1510
|
+
assert.equal(shadowRoot.querySelector(".cd-compact-bar")?.getAttribute("data-theme"), "dark");
|
|
1511
|
+
assert.equal(shadowRoot.querySelector(".cd-book-corner")?.getAttribute("data-theme"), "dark");
|
|
1512
|
+
assert.equal(shadowRoot.querySelector(".cd-drag-pin")?.getAttribute("data-theme"), "dark");
|
|
1513
|
+
assert.equal(composerThemeToggle.getAttribute("aria-label"), "Switch to light theme");
|
|
1514
|
+
assert.equal(themeChangeEvents.length, 1);
|
|
1515
|
+
assert.equal(themeChangeEvents[0], "dark");
|
|
1516
|
+
assert.equal(leakedWindowEvents.length, 0, "Theme change event stays scoped to widget element");
|
|
1517
|
+
|
|
1518
|
+
// Click theme toggle in sidebar to toggle back
|
|
1519
|
+
sidebarThemeToggle.dispatchEvent(new MockUiEvent("click"));
|
|
1520
|
+
|
|
1521
|
+
assert.equal(widget.getTheme(), "light");
|
|
1522
|
+
assert.equal(widget.getAttribute("data-cd-theme"), "light");
|
|
1523
|
+
assert.equal(widget.getAttribute("data-theme"), null);
|
|
1524
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null);
|
|
1525
|
+
assert.equal(mockBody.getAttribute("data-theme"), null);
|
|
1526
|
+
assert.equal(composerThemeToggle.getAttribute("aria-label"), "Switch to dark theme");
|
|
1527
|
+
assert.equal(themeChangeEvents.length, 2);
|
|
1528
|
+
assert.equal(themeChangeEvents[1], "light");
|
|
1529
|
+
|
|
1530
|
+
// Programmatic setTheme
|
|
1531
|
+
widget.setTheme("dark");
|
|
1532
|
+
assert.equal(widget.getTheme(), "dark");
|
|
1533
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null);
|
|
1534
|
+
assert.equal(mockBody.getAttribute("data-theme"), null);
|
|
1535
|
+
assert.equal(themeChangeEvents.length, 3);
|
|
1536
|
+
assert.equal(themeChangeEvents[2], "dark");
|
|
1537
|
+
|
|
1538
|
+
widget.removeEventListener("contextdrop:themechange", onThemeChange);
|
|
1539
|
+
window.removeEventListener("contextdrop:themechange", onWindowThemeChange);
|
|
1540
|
+
},
|
|
1541
|
+
{
|
|
1542
|
+
"data-config": JSON.stringify({
|
|
1543
|
+
enabled: true,
|
|
1544
|
+
environment: "development",
|
|
1545
|
+
position: "bottom_right",
|
|
1546
|
+
agent: { enabled: true }
|
|
1547
|
+
})
|
|
1548
|
+
}
|
|
1549
|
+
);
|
|
1550
|
+
});
|
|
1551
|
+
|
|
1552
|
+
it("defaults sidebar width to 560px for full container item layout without crowding", async () => {
|
|
1553
|
+
await withMountedWidget(
|
|
1554
|
+
async ({ shadowRoot, mockHtml }) => {
|
|
1555
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1556
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1557
|
+
assert.ok(sidebar && bookCorner);
|
|
1558
|
+
assert.equal(sidebar.style.width, "560px");
|
|
1559
|
+
|
|
1560
|
+
// Open widget in agent mode so push layout can engage
|
|
1561
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1562
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1563
|
+
|
|
1564
|
+
const pushBtn = shadowRoot.querySelector("[aria-label='Toggle push page layout']");
|
|
1565
|
+
assert.ok(pushBtn);
|
|
1566
|
+
pushBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1567
|
+
assert.equal(mockHtml.style.marginRight, "560px");
|
|
1568
|
+
},
|
|
1569
|
+
{
|
|
1570
|
+
"data-config": JSON.stringify({
|
|
1571
|
+
enabled: true,
|
|
1572
|
+
environment: "development",
|
|
1573
|
+
position: "bottom_right",
|
|
1574
|
+
agent: { enabled: true }
|
|
1575
|
+
})
|
|
1576
|
+
}
|
|
1577
|
+
);
|
|
1578
|
+
});
|
|
1579
|
+
|
|
1580
|
+
it("defaults local development to staging/verbose mode when agent is disabled", async () => {
|
|
1581
|
+
await withMountedWidget(
|
|
1582
|
+
async ({ widget, shadowRoot }) => {
|
|
1583
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1584
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1585
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1586
|
+
const modeSwitch = composer ? composer.querySelector(".cd-composer-mode-switch-wrap") : null;
|
|
1587
|
+
assert.ok(bookCorner && composer && sidebar && modeSwitch);
|
|
1588
|
+
|
|
1589
|
+
// When agent is disabled for local development:
|
|
1590
|
+
assert.equal(widget.isAgentModeActive(), false);
|
|
1591
|
+
assert.equal(widget.isSmartSelectionMode(), false); // verbose mode
|
|
1592
|
+
assert.equal(modeSwitch.hidden, true);
|
|
1593
|
+
|
|
1594
|
+
// Clicking the book corner opens the floating verbose composer
|
|
1595
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1596
|
+
assert.equal(composer.hidden, false);
|
|
1597
|
+
assert.equal(sidebar.hidden, true);
|
|
1598
|
+
|
|
1599
|
+
// Opting into agent enables agent mode
|
|
1600
|
+
widget.setWidgetConfig({ agent: { enabled: true } });
|
|
1601
|
+
assert.equal(widget.isAgentModeActive(), true);
|
|
1602
|
+
assert.equal(sidebar.hidden, false);
|
|
1603
|
+
assert.equal(composer.hidden, true);
|
|
1604
|
+
},
|
|
1605
|
+
{
|
|
1606
|
+
"data-config": JSON.stringify({
|
|
1607
|
+
enabled: true,
|
|
1608
|
+
environment: "development",
|
|
1609
|
+
position: "bottom_right",
|
|
1610
|
+
agent: { enabled: false }
|
|
1611
|
+
})
|
|
1612
|
+
}
|
|
1613
|
+
);
|
|
1614
|
+
});
|
|
1615
|
+
|
|
1616
|
+
it("loads own feedbacks on open, edits message + context inline with draft restoration, and emits context-drop:update", async () => {
|
|
1617
|
+
const g = globalThis as Record<string, unknown>;
|
|
1618
|
+
const prevFetch = g.fetch;
|
|
1619
|
+
const apiCalls: Array<{ url: string; method: string; headers: Record<string, string>; body?: unknown }> = [];
|
|
1620
|
+
|
|
1621
|
+
g.fetch = async (input: string | URL, init?: RequestInit) => {
|
|
1622
|
+
const url = String(input);
|
|
1623
|
+
const method = (init?.method || "GET").toUpperCase();
|
|
1624
|
+
const headers = (init?.headers as Record<string, string>) || {};
|
|
1625
|
+
const body =
|
|
1626
|
+
typeof init?.body === "string" && init.body.length > 0 ? JSON.parse(init.body) : undefined;
|
|
1627
|
+
apiCalls.push({ url, method, headers, body });
|
|
1628
|
+
|
|
1629
|
+
if (url.includes("/feedback?") && method === "GET") {
|
|
1630
|
+
return new Response(
|
|
1631
|
+
JSON.stringify({
|
|
1632
|
+
total_count: 1,
|
|
1633
|
+
feedbacks: [
|
|
1634
|
+
{
|
|
1635
|
+
id: 501,
|
|
1636
|
+
status: "new",
|
|
1637
|
+
message: "Initial checkout button misalignment",
|
|
1638
|
+
page_url: "http://localhost:3000/orders",
|
|
1639
|
+
created_at: "2026-11-13T04:00:00Z",
|
|
1640
|
+
updated_at: "2026-11-13T04:00:00Z",
|
|
1641
|
+
ownership_token: "501.nonceA.sigA",
|
|
1642
|
+
element_references: [
|
|
1643
|
+
{
|
|
1644
|
+
id: 11,
|
|
1645
|
+
client_ref: "el_orig_1",
|
|
1646
|
+
tag_name: "button",
|
|
1647
|
+
selector: "#submit-order",
|
|
1648
|
+
dom_path: "body > button#submit-order",
|
|
1649
|
+
text_content: "Submit Order",
|
|
1650
|
+
bounding_rect: { x: 20, y: 40, width: 160, height: 42 }
|
|
1651
|
+
}
|
|
1652
|
+
],
|
|
1653
|
+
attachments: [
|
|
1654
|
+
{
|
|
1655
|
+
id: 91,
|
|
1656
|
+
attachment_type: "screenshot",
|
|
1657
|
+
filename: "orig-shot.png",
|
|
1658
|
+
content_type: "image/png",
|
|
1659
|
+
byte_size: 1200,
|
|
1660
|
+
element_reference_id: 11,
|
|
1661
|
+
element_client_ref: "el_orig_1",
|
|
1662
|
+
preview_url: "/context_drop/feedback/501/attachments/91",
|
|
1663
|
+
metadata: { capture_type: "element" }
|
|
1664
|
+
}
|
|
1665
|
+
]
|
|
1666
|
+
}
|
|
1667
|
+
]
|
|
1668
|
+
}),
|
|
1669
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1670
|
+
);
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
if (url.endsWith("/feedback/501") && method === "PATCH") {
|
|
1674
|
+
return new Response(
|
|
1675
|
+
JSON.stringify({
|
|
1676
|
+
id: 501,
|
|
1677
|
+
status: "new",
|
|
1678
|
+
attachments_count: 1,
|
|
1679
|
+
element_references_count: 2,
|
|
1680
|
+
ownership_token: "501.nonceA.sigA",
|
|
1681
|
+
updated_at: "2026-11-13T04:05:00Z",
|
|
1682
|
+
feedback: {
|
|
1683
|
+
id: 501,
|
|
1684
|
+
status: "new",
|
|
1685
|
+
message: "Updated: button + coupon field misaligned on Safari",
|
|
1686
|
+
page_url: "http://localhost:3000/orders",
|
|
1687
|
+
created_at: "2026-11-13T04:00:00Z",
|
|
1688
|
+
updated_at: "2026-11-13T04:05:00Z",
|
|
1689
|
+
ownership_token: "501.nonceA.sigA",
|
|
1690
|
+
element_references: [
|
|
1691
|
+
{
|
|
1692
|
+
id: 12,
|
|
1693
|
+
client_ref: "el_orig_1",
|
|
1694
|
+
tag_name: "button",
|
|
1695
|
+
selector: "#submit-order",
|
|
1696
|
+
dom_path: "body > button#submit-order"
|
|
1697
|
+
},
|
|
1698
|
+
{
|
|
1699
|
+
id: 13,
|
|
1700
|
+
client_ref: "el_added_2",
|
|
1701
|
+
tag_name: "input",
|
|
1702
|
+
selector: "#coupon-code",
|
|
1703
|
+
dom_path: "body > input#coupon-code"
|
|
1704
|
+
}
|
|
1705
|
+
],
|
|
1706
|
+
attachments: [
|
|
1707
|
+
{
|
|
1708
|
+
id: 91,
|
|
1709
|
+
attachment_type: "screenshot",
|
|
1710
|
+
filename: "orig-shot.png",
|
|
1711
|
+
content_type: "image/png",
|
|
1712
|
+
byte_size: 1200,
|
|
1713
|
+
element_reference_id: 12,
|
|
1714
|
+
element_client_ref: "el_orig_1",
|
|
1715
|
+
preview_url: "/context_drop/feedback/501/attachments/91"
|
|
1716
|
+
}
|
|
1717
|
+
]
|
|
1718
|
+
}
|
|
1719
|
+
}),
|
|
1720
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1721
|
+
);
|
|
1722
|
+
}
|
|
1723
|
+
|
|
1724
|
+
throw new Error(`Unexpected fetch ${method} ${url}`);
|
|
1725
|
+
};
|
|
1726
|
+
|
|
1727
|
+
try {
|
|
1728
|
+
await withMountedWidget(
|
|
1729
|
+
async ({ widget, shadowRoot, mockBody, mockWindow }) => {
|
|
1730
|
+
const updateEvents: unknown[] = [];
|
|
1731
|
+
widget.addEventListener("context-drop:update", (ev: unknown) => {
|
|
1732
|
+
updateEvents.push((ev as { detail?: unknown }).detail);
|
|
1733
|
+
});
|
|
1734
|
+
|
|
1735
|
+
// Open composer -> triggers lazy GET /feedback sync
|
|
1736
|
+
widget.openComposer();
|
|
1737
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1738
|
+
|
|
1739
|
+
const chatThread = shadowRoot.querySelector(".cd-chat-thread");
|
|
1740
|
+
const editBanner = shadowRoot.querySelector(".cd-edit-banner");
|
|
1741
|
+
const textarea = shadowRoot.querySelector("[aria-label='Feedback description']");
|
|
1742
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
1743
|
+
assert.ok(chatThread && editBanner && textarea && tray);
|
|
1744
|
+
assert.equal(chatThread.hidden, false);
|
|
1745
|
+
assert.equal(editBanner.hidden, true);
|
|
1746
|
+
|
|
1747
|
+
const msgCard = chatThread.querySelector(".cd-chat-msg");
|
|
1748
|
+
assert.ok(msgCard, "Synced own feedback card is rendered in composer thread");
|
|
1749
|
+
|
|
1750
|
+
// Type an unsent draft before clicking Edit so draft restoration can be verified
|
|
1751
|
+
textarea.value = "Unsent new draft note";
|
|
1752
|
+
textarea.dispatchEvent(new MockUiEvent("input"));
|
|
1753
|
+
|
|
1754
|
+
const editBtn = msgCard.querySelector("[aria-label='Edit feedback']");
|
|
1755
|
+
assert.ok(editBtn);
|
|
1756
|
+
editBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1757
|
+
|
|
1758
|
+
assert.equal(editBanner.hidden, false);
|
|
1759
|
+
assert.equal(textarea.value, "Initial checkout button misalignment");
|
|
1760
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
1761
|
+
assert.equal(widget.getElementReferences()[0].selector, "#submit-order");
|
|
1762
|
+
assert.equal(widget.getAttachments().length, 1);
|
|
1763
|
+
assert.equal(widget.getAttachments()[0].existing_attachment_id, 91);
|
|
1764
|
+
|
|
1765
|
+
const saveBtn = shadowRoot.querySelector("[aria-label='Save feedback changes']");
|
|
1766
|
+
assert.ok(saveBtn, "Submit button switches aria-label to Save feedback changes");
|
|
1767
|
+
|
|
1768
|
+
// Pressing Escape while editing cancels edit and restores the unsent draft!
|
|
1769
|
+
mockWindow.dispatchEvent(new MockUiEvent("keydown", { key: "Escape" }));
|
|
1770
|
+
assert.equal(editBanner.hidden, true);
|
|
1771
|
+
assert.equal(textarea.value, "Unsent new draft note");
|
|
1772
|
+
assert.equal(widget.getElementReferences().length, 0);
|
|
1773
|
+
assert.equal(widget.getAttachments().length, 0);
|
|
1774
|
+
|
|
1775
|
+
// Re-enter edit mode on #501, pin an additional element, edit text, and click Save
|
|
1776
|
+
const editBtnAgain = shadowRoot.querySelector("[aria-label='Edit feedback']");
|
|
1777
|
+
assert.ok(editBtnAgain);
|
|
1778
|
+
editBtnAgain.dispatchEvent(new MockUiEvent("click"));
|
|
1779
|
+
|
|
1780
|
+
const couponInput = new MockDomElement("input");
|
|
1781
|
+
couponInput.setAttribute("id", "coupon-code");
|
|
1782
|
+
couponInput.setRect({ left: 30, top: 90, width: 200, height: 36 });
|
|
1783
|
+
mockBody.appendChild(couponInput);
|
|
1784
|
+
widget.addElementReference({
|
|
1785
|
+
client_ref: "el_added_2",
|
|
1786
|
+
tag_name: "input",
|
|
1787
|
+
selector: "#coupon-code",
|
|
1788
|
+
dom_path: "body > input#coupon-code",
|
|
1789
|
+
text_content: null,
|
|
1790
|
+
attributes_snapshot: { id: "coupon-code" },
|
|
1791
|
+
bounding_rect: { x: 30, y: 90, width: 200, height: 36 },
|
|
1792
|
+
viewport: { width: 1280, height: 800 },
|
|
1793
|
+
metadata: {},
|
|
1794
|
+
captured_at: "2026-11-13T04:04:00Z"
|
|
1795
|
+
});
|
|
1796
|
+
|
|
1797
|
+
textarea.value = "Updated: button + coupon field misaligned on Safari";
|
|
1798
|
+
textarea.dispatchEvent(new MockUiEvent("input"));
|
|
1799
|
+
|
|
1800
|
+
const activeSaveBtn = shadowRoot.querySelector("[aria-label='Save feedback changes']");
|
|
1801
|
+
assert.ok(activeSaveBtn);
|
|
1802
|
+
activeSaveBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1803
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1804
|
+
|
|
1805
|
+
const patchCall = apiCalls.find((c) => c.method === "PATCH");
|
|
1806
|
+
assert.ok(patchCall, "PATCH /feedback/501 was sent");
|
|
1807
|
+
assert.equal(patchCall.headers["X-Context-Drop-Ownership-Token"], "501.nonceA.sigA");
|
|
1808
|
+
const patchPayload = (patchCall.body as { feedback: Record<string, unknown> }).feedback;
|
|
1809
|
+
assert.equal(patchPayload.message, "Updated: button + coupon field misaligned on Safari");
|
|
1810
|
+
assert.equal((patchPayload.element_references as unknown[]).length, 2);
|
|
1811
|
+
const sentAtts = patchPayload.attachments as Array<Record<string, unknown>>;
|
|
1812
|
+
assert.equal(sentAtts.length, 1);
|
|
1813
|
+
assert.equal(sentAtts[0].existing_id, 91);
|
|
1814
|
+
|
|
1815
|
+
// Edit mode exited, unsent draft restored, card updated with · edited indicator, event emitted
|
|
1816
|
+
assert.equal(editBanner.hidden, true);
|
|
1817
|
+
assert.equal(textarea.value, "Unsent new draft note");
|
|
1818
|
+
assert.equal(updateEvents.length, 1);
|
|
1819
|
+
const updatedMetaInfo = shadowRoot.querySelector(".cd-chat-msg-meta-info");
|
|
1820
|
+
assert.ok(
|
|
1821
|
+
updatedMetaInfo &&
|
|
1822
|
+
updatedMetaInfo.childNodes.some((n) => n.textContent.includes("edited"))
|
|
1823
|
+
);
|
|
1824
|
+
},
|
|
1825
|
+
{
|
|
1826
|
+
"data-config": JSON.stringify({
|
|
1827
|
+
enabled: true,
|
|
1828
|
+
environment: "staging",
|
|
1829
|
+
position: "bottom_right",
|
|
1830
|
+
csrf_token: "test_csrf_999",
|
|
1831
|
+
agent: { enabled: false }
|
|
1832
|
+
})
|
|
1833
|
+
}
|
|
1834
|
+
);
|
|
1835
|
+
} finally {
|
|
1836
|
+
if (prevFetch === undefined) {
|
|
1837
|
+
delete g.fetch;
|
|
1838
|
+
} else {
|
|
1839
|
+
g.fetch = prevFetch;
|
|
1840
|
+
}
|
|
1841
|
+
}
|
|
1842
|
+
});
|
|
1843
|
+
|
|
1844
|
+
it("soft-deletes own feedback via inline confirmation bar in smart mode without modals and emits context-drop:delete", async () => {
|
|
1845
|
+
const g = globalThis as Record<string, unknown>;
|
|
1846
|
+
const prevFetch = g.fetch;
|
|
1847
|
+
const apiCalls: Array<{ url: string; method: string; headers: Record<string, string> }> = [];
|
|
1848
|
+
|
|
1849
|
+
g.fetch = async (input: string | URL, init?: RequestInit) => {
|
|
1850
|
+
const url = String(input);
|
|
1851
|
+
const method = (init?.method || "GET").toUpperCase();
|
|
1852
|
+
const headers = (init?.headers as Record<string, string>) || {};
|
|
1853
|
+
apiCalls.push({ url, method, headers });
|
|
1854
|
+
|
|
1855
|
+
if (url.includes("/feedback?") && method === "GET") {
|
|
1856
|
+
return new Response(
|
|
1857
|
+
JSON.stringify({
|
|
1858
|
+
total_count: 1,
|
|
1859
|
+
feedbacks: [
|
|
1860
|
+
{
|
|
1861
|
+
id: 808,
|
|
1862
|
+
status: "new",
|
|
1863
|
+
message: "Accidental duplicate report",
|
|
1864
|
+
page_url: "http://localhost:3000/orders",
|
|
1865
|
+
created_at: "2026-11-13T05:00:00Z",
|
|
1866
|
+
updated_at: "2026-11-13T05:00:00Z",
|
|
1867
|
+
ownership_token: "808.nonceB.sigB",
|
|
1868
|
+
element_references: [],
|
|
1869
|
+
attachments: []
|
|
1870
|
+
}
|
|
1871
|
+
]
|
|
1872
|
+
}),
|
|
1873
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1874
|
+
);
|
|
1875
|
+
}
|
|
1876
|
+
|
|
1877
|
+
if (url.endsWith("/feedback/808") && method === "DELETE") {
|
|
1878
|
+
return new Response(
|
|
1879
|
+
JSON.stringify({
|
|
1880
|
+
id: 808,
|
|
1881
|
+
deleted: true,
|
|
1882
|
+
deleted_at: "2026-11-13T05:01:00Z"
|
|
1883
|
+
}),
|
|
1884
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1885
|
+
);
|
|
1886
|
+
}
|
|
1887
|
+
|
|
1888
|
+
throw new Error(`Unexpected fetch ${method} ${url}`);
|
|
1889
|
+
};
|
|
1890
|
+
|
|
1891
|
+
try {
|
|
1892
|
+
await withMountedWidget(
|
|
1893
|
+
async ({ widget, shadowRoot }) => {
|
|
1894
|
+
const deleteEvents: unknown[] = [];
|
|
1895
|
+
widget.addEventListener("context-drop:delete", (ev: unknown) => {
|
|
1896
|
+
deleteEvents.push((ev as { detail?: unknown }).detail);
|
|
1897
|
+
});
|
|
1898
|
+
|
|
1899
|
+
widget.openComposer();
|
|
1900
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1901
|
+
|
|
1902
|
+
const chatThread = shadowRoot.querySelector(".cd-chat-thread");
|
|
1903
|
+
const editBanner = shadowRoot.querySelector(".cd-edit-banner");
|
|
1904
|
+
assert.ok(chatThread && editBanner);
|
|
1905
|
+
assert.equal(chatThread.hidden, false);
|
|
1906
|
+
|
|
1907
|
+
// Start editing #808 first, then trigger Delete to verify deleting cancels active edit cleanly
|
|
1908
|
+
const editBtn = chatThread.querySelector("[aria-label='Edit feedback']");
|
|
1909
|
+
assert.ok(editBtn);
|
|
1910
|
+
editBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1911
|
+
assert.equal(editBanner.hidden, false);
|
|
1912
|
+
|
|
1913
|
+
const deleteBtn = chatThread.querySelector("[aria-label='Delete feedback']");
|
|
1914
|
+
assert.ok(deleteBtn);
|
|
1915
|
+
deleteBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1916
|
+
|
|
1917
|
+
// Inline confirmation bar appears (no browser confirm / modal)
|
|
1918
|
+
let confirmBar = chatThread.querySelector(".cd-msg-delete-confirm");
|
|
1919
|
+
assert.ok(confirmBar, "Inline delete confirmation bar renders inside feedback card");
|
|
1920
|
+
|
|
1921
|
+
// Clicking Cancel dismisses inline confirmation without calling DELETE
|
|
1922
|
+
const cancelDelBtn = confirmBar.querySelector("[aria-label='Cancel delete']");
|
|
1923
|
+
assert.ok(cancelDelBtn);
|
|
1924
|
+
cancelDelBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1925
|
+
assert.equal(chatThread.querySelector(".cd-msg-delete-confirm"), null);
|
|
1926
|
+
assert.equal(apiCalls.some((c) => c.method === "DELETE"), false);
|
|
1927
|
+
|
|
1928
|
+
// Click Delete again, then Confirm delete feedback
|
|
1929
|
+
const deleteBtnAgain = chatThread.querySelector("[aria-label='Delete feedback']");
|
|
1930
|
+
assert.ok(deleteBtnAgain);
|
|
1931
|
+
deleteBtnAgain.dispatchEvent(new MockUiEvent("click"));
|
|
1932
|
+
|
|
1933
|
+
confirmBar = chatThread.querySelector(".cd-msg-delete-confirm");
|
|
1934
|
+
assert.ok(confirmBar);
|
|
1935
|
+
const confirmDelBtn = confirmBar.querySelector("[aria-label='Confirm delete feedback']");
|
|
1936
|
+
assert.ok(confirmDelBtn);
|
|
1937
|
+
confirmDelBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1938
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1939
|
+
|
|
1940
|
+
const delCall = apiCalls.find((c) => c.method === "DELETE");
|
|
1941
|
+
assert.ok(delCall, "DELETE /feedback/808 was sent");
|
|
1942
|
+
assert.equal(delCall.headers["X-Context-Drop-Ownership-Token"], "808.nonceB.sigB");
|
|
1943
|
+
assert.equal(editBanner.hidden, true, "Active edit banner closes when edited feedback is deleted");
|
|
1944
|
+
assert.equal(chatThread.querySelector(".cd-chat-msg"), null, "Deleted card is removed from thread");
|
|
1945
|
+
assert.ok(chatThread.querySelector(".cd-chat-empty"), "Empty state prompt renders cleanly after delete");
|
|
1946
|
+
assert.equal(deleteEvents.length, 1);
|
|
1947
|
+
},
|
|
1948
|
+
{
|
|
1949
|
+
"data-config": JSON.stringify({
|
|
1950
|
+
enabled: true,
|
|
1951
|
+
environment: "production",
|
|
1952
|
+
position: "bottom_right",
|
|
1953
|
+
csrf_token: "prod_csrf_123",
|
|
1954
|
+
agent: { enabled: false }
|
|
1955
|
+
})
|
|
1956
|
+
}
|
|
1957
|
+
);
|
|
1958
|
+
} finally {
|
|
1959
|
+
if (prevFetch === undefined) {
|
|
1960
|
+
delete g.fetch;
|
|
1961
|
+
} else {
|
|
1962
|
+
g.fetch = prevFetch;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1965
|
+
});
|
|
1040
1966
|
});
|