context_drop 0.1.3 → 0.2.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 +218 -49
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +5227 -652
- data/app/controllers/context_drop/agent_controller.rb +170 -0
- data/app/controllers/context_drop/configs_controller.rb +2 -1
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +62 -2
- data/app/controllers/context_drop/feedbacks_controller.rb +13 -3
- data/app/controllers/context_drop/mcp_controller.rb +2 -1
- data/app/helpers/context_drop/dashboard_helper.rb +52 -0
- data/app/helpers/context_drop/widget_helper.rb +11 -1
- data/app/javascript/context_drop/__tests__/widget.test.ts +731 -92
- data/app/javascript/context_drop/api-client.ts +130 -11
- data/app/javascript/context_drop/element-picker.ts +247 -30
- data/app/javascript/context_drop/icons.ts +24 -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 +102 -8
- data/app/javascript/context_drop/styles.ts +1528 -252
- data/app/javascript/context_drop/types.ts +147 -0
- data/app/javascript/context_drop/widget.ts +2629 -288
- data/app/models/context_drop/feedback.rb +34 -5
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +166 -60
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +178 -47
- data/app/views/layouts/context_drop/application.html.erb +416 -70
- data/config/routes.rb +11 -0
- data/db/migrate/20261112000004_add_environment_to_context_drop_feedbacks.rb +10 -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 +216 -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 +87 -8
- 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 +50 -4
- data/lib/context_drop/mcp/tools/get_feedback_attachment.rb +26 -4
- data/lib/context_drop/mcp/tools/list_environments.rb +60 -0
- data/lib/context_drop/mcp/tools/list_feedbacks.rb +174 -22
- data/lib/context_drop/mcp/tools/update_feedback_status.rb +45 -4
- 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 +13 -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 {
|
|
@@ -349,7 +402,11 @@ class MockUiEvent {
|
|
|
349
402
|
deltaY?: number;
|
|
350
403
|
deltaMode?: number;
|
|
351
404
|
key?: string;
|
|
405
|
+
code?: string;
|
|
352
406
|
shiftKey?: boolean;
|
|
407
|
+
altKey?: boolean;
|
|
408
|
+
ctrlKey?: boolean;
|
|
409
|
+
metaKey?: boolean;
|
|
353
410
|
} = {}
|
|
354
411
|
) {
|
|
355
412
|
this.type = type;
|
|
@@ -359,10 +416,11 @@ class MockUiEvent {
|
|
|
359
416
|
this.deltaY = init.deltaY ?? 0;
|
|
360
417
|
this.deltaMode = init.deltaMode ?? 0;
|
|
361
418
|
this.key = init.key ?? "";
|
|
419
|
+
this.code = init.code ?? "";
|
|
362
420
|
this.shiftKey = init.shiftKey ?? false;
|
|
363
|
-
this.altKey = false;
|
|
364
|
-
this.ctrlKey = false;
|
|
365
|
-
this.metaKey = false;
|
|
421
|
+
this.altKey = init.altKey ?? false;
|
|
422
|
+
this.ctrlKey = init.ctrlKey ?? false;
|
|
423
|
+
this.metaKey = init.metaKey ?? false;
|
|
366
424
|
}
|
|
367
425
|
|
|
368
426
|
public preventDefault(): void {
|
|
@@ -434,6 +492,8 @@ class MockDomElement {
|
|
|
434
492
|
public placeholder: string = "";
|
|
435
493
|
public value: string = "";
|
|
436
494
|
public disabled: boolean = false;
|
|
495
|
+
public selected: boolean = false;
|
|
496
|
+
public autocomplete: string = "";
|
|
437
497
|
public multiple: boolean = false;
|
|
438
498
|
public accept: string = "";
|
|
439
499
|
public scrollTop: number = 0;
|
|
@@ -649,13 +709,24 @@ function withMountedWidget(
|
|
|
649
709
|
widget: ContextDropWidgetElement;
|
|
650
710
|
shadowRoot: MockDomElement;
|
|
651
711
|
mockBody: MockDomElement;
|
|
712
|
+
mockHtml: MockDomElement;
|
|
652
713
|
mockDocument: {
|
|
653
714
|
body: MockDomElement;
|
|
715
|
+
documentElement: MockDomElement;
|
|
654
716
|
createElement: (tag: string) => MockDomElement;
|
|
717
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
655
718
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
656
719
|
};
|
|
657
720
|
mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
|
|
658
|
-
}) => void | Promise<void
|
|
721
|
+
}) => void | Promise<void>,
|
|
722
|
+
hostAttrs: Record<string, string> = {
|
|
723
|
+
"data-config": JSON.stringify({
|
|
724
|
+
enabled: true,
|
|
725
|
+
environment: "staging",
|
|
726
|
+
position: "bottom_right",
|
|
727
|
+
agent: { enabled: false }
|
|
728
|
+
})
|
|
729
|
+
}
|
|
659
730
|
): Promise<void> {
|
|
660
731
|
const g = globalThis as Record<string, unknown>;
|
|
661
732
|
const prevWindow = g.window;
|
|
@@ -666,14 +737,21 @@ function withMountedWidget(
|
|
|
666
737
|
innerHeight: 800,
|
|
667
738
|
location: { href: "http://localhost:3000/orders" }
|
|
668
739
|
});
|
|
740
|
+
const mockHtml = new MockDomElement("html");
|
|
669
741
|
const mockBody = new MockDomElement("body");
|
|
742
|
+
mockHtml.appendChild(mockBody);
|
|
743
|
+
|
|
670
744
|
const mockDocument: {
|
|
671
745
|
body: MockDomElement;
|
|
746
|
+
documentElement: MockDomElement;
|
|
672
747
|
createElement: (tag: string) => MockDomElement;
|
|
748
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
673
749
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
674
750
|
} = {
|
|
675
751
|
body: mockBody,
|
|
676
|
-
|
|
752
|
+
documentElement: mockHtml,
|
|
753
|
+
createElement: (tag: string) => new MockDomElement(tag),
|
|
754
|
+
querySelector: () => null
|
|
677
755
|
};
|
|
678
756
|
|
|
679
757
|
g.window = mockWindow;
|
|
@@ -681,17 +759,45 @@ function withMountedWidget(
|
|
|
681
759
|
|
|
682
760
|
const shadowRoot = new MockDomElement("shadow-root");
|
|
683
761
|
const widget = new ContextDropWidgetElement();
|
|
762
|
+
const widgetListeners: Map<string, Array<(ev: unknown) => void>> = new Map();
|
|
763
|
+
const hostAttrsMap = new Map<string, string>(Object.entries(hostAttrs));
|
|
684
764
|
const hostShim = widget as unknown as {
|
|
685
765
|
attachShadow: () => ShadowRoot;
|
|
686
766
|
getAttribute: (name: string) => string | null;
|
|
767
|
+
setAttribute: (name: string, value: string) => void;
|
|
768
|
+
hasAttribute: (name: string) => boolean;
|
|
769
|
+
addEventListener: (type: string, listener: (ev: unknown) => void) => void;
|
|
770
|
+
removeEventListener: (type: string, listener: (ev: unknown) => void) => void;
|
|
771
|
+
dispatchEvent: (event: { type: string }) => boolean;
|
|
687
772
|
};
|
|
688
773
|
hostShim.attachShadow = () => shadowRoot as unknown as ShadowRoot;
|
|
689
|
-
hostShim.getAttribute = () => null;
|
|
774
|
+
hostShim.getAttribute = (name: string) => hostAttrsMap.get(name) ?? null;
|
|
775
|
+
hostShim.setAttribute = (name: string, value: string) => {
|
|
776
|
+
hostAttrsMap.set(name, value);
|
|
777
|
+
};
|
|
778
|
+
hostShim.hasAttribute = (name: string) => hostAttrsMap.has(name);
|
|
779
|
+
hostShim.addEventListener = (type: string, listener: (ev: unknown) => void) => {
|
|
780
|
+
const list = widgetListeners.get(type) || [];
|
|
781
|
+
list.push(listener);
|
|
782
|
+
widgetListeners.set(type, list);
|
|
783
|
+
};
|
|
784
|
+
hostShim.removeEventListener = (type: string, listener: (ev: unknown) => void) => {
|
|
785
|
+
const list = widgetListeners.get(type) || [];
|
|
786
|
+
widgetListeners.set(
|
|
787
|
+
type,
|
|
788
|
+
list.filter((l) => l !== listener)
|
|
789
|
+
);
|
|
790
|
+
};
|
|
791
|
+
hostShim.dispatchEvent = (event: { type: string }) => {
|
|
792
|
+
const list = widgetListeners.get(event.type) || [];
|
|
793
|
+
for (const l of list) l(event);
|
|
794
|
+
return true;
|
|
795
|
+
};
|
|
690
796
|
|
|
691
797
|
widget.connectedCallback();
|
|
692
798
|
|
|
693
799
|
return Promise.resolve()
|
|
694
|
-
.then(() => fn({ widget, shadowRoot, mockBody, mockDocument, mockWindow }))
|
|
800
|
+
.then(() => fn({ widget, shadowRoot, mockBody, mockHtml, mockDocument, mockWindow }))
|
|
695
801
|
.finally(() => {
|
|
696
802
|
widget.disconnectedCallback();
|
|
697
803
|
if (prevWindow === undefined) {
|
|
@@ -707,126 +813,323 @@ function withMountedWidget(
|
|
|
707
813
|
});
|
|
708
814
|
}
|
|
709
815
|
|
|
710
|
-
describe("ContextDrop
|
|
711
|
-
it("
|
|
816
|
+
describe("ContextDrop v0.2 Book-Corner Peel-to-Pin & Agentic Sidebar", () => {
|
|
817
|
+
it("opens standard feedback chatbox when book corner is clicked or keyboard-activated", async () => {
|
|
712
818
|
await withMountedWidget(({ shadowRoot, mockWindow }) => {
|
|
713
|
-
const
|
|
714
|
-
const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
|
|
715
|
-
const triggerBtn = shadowRoot.querySelector(".cd-trigger");
|
|
819
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
716
820
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
821
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
717
822
|
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
718
823
|
|
|
719
|
-
assert.ok(
|
|
824
|
+
assert.ok(bookCorner && composer && sidebar && compactBar);
|
|
825
|
+
assert.equal(bookCorner.hidden, false);
|
|
826
|
+
assert.equal(bookCorner.classList.contains("corner-bottom_right"), true);
|
|
720
827
|
assert.equal(composer.hidden, true);
|
|
828
|
+
assert.equal(sidebar.hidden, true);
|
|
721
829
|
assert.equal(compactBar.hidden, true);
|
|
722
|
-
assert.equal(pinDock.hidden, false);
|
|
723
830
|
|
|
724
|
-
//
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
triggerSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 40, clientY: 30 }));
|
|
831
|
+
// Pointer click without drag opens normal floating feedback composer
|
|
832
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 16, clientY: 16 }));
|
|
833
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 18, clientY: 18 }));
|
|
834
|
+
bookCorner.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 18, clientY: 18 }));
|
|
729
835
|
|
|
730
836
|
assert.equal(composer.hidden, false);
|
|
731
|
-
assert.equal(
|
|
732
|
-
assert.equal(
|
|
837
|
+
assert.equal(bookCorner.hidden, true);
|
|
838
|
+
assert.equal(bookCorner.getAttribute("aria-expanded"), "true");
|
|
733
839
|
|
|
734
|
-
// Close composer to
|
|
840
|
+
// Close composer returns to flush book corner
|
|
735
841
|
const closeBtn = shadowRoot.querySelector("[aria-label='Close feedback composer']");
|
|
736
842
|
assert.ok(closeBtn);
|
|
737
843
|
closeBtn.dispatchEvent(new MockUiEvent("click"));
|
|
738
844
|
assert.equal(composer.hidden, true);
|
|
739
|
-
assert.equal(
|
|
740
|
-
|
|
741
|
-
// Click nested <span>Pin</span> inside .cd-floating-pin-btn
|
|
742
|
-
const pinSpan = floatingPinBtn.querySelector("span") ?? floatingPinBtn;
|
|
743
|
-
pinSpan.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 30, clientY: 30 }));
|
|
744
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 30, clientY: 30 }));
|
|
745
|
-
pinSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 30, clientY: 30 }));
|
|
845
|
+
assert.equal(bookCorner.hidden, false);
|
|
746
846
|
|
|
747
|
-
|
|
748
|
-
|
|
847
|
+
// Keyboard activation (click without pointerdown/pointerup) also opens composer
|
|
848
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
849
|
+
assert.equal(composer.hidden, false);
|
|
749
850
|
});
|
|
750
851
|
});
|
|
751
852
|
|
|
752
|
-
it("
|
|
753
|
-
await withMountedWidget(({ shadowRoot, mockWindow }) => {
|
|
754
|
-
const
|
|
755
|
-
const
|
|
756
|
-
const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
|
|
757
|
-
const triggerBtn = shadowRoot.querySelector(".cd-trigger");
|
|
853
|
+
it("morphs book corner into a pushpin when dragged and pins DOM element directly on drop", async () => {
|
|
854
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
855
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
856
|
+
const dragPin = shadowRoot.querySelector(".cd-drag-pin");
|
|
758
857
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
759
|
-
const
|
|
858
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
859
|
+
assert.ok(bookCorner && dragPin && composer && tray);
|
|
760
860
|
|
|
761
|
-
|
|
861
|
+
const checkoutBtn = new MockDomElement("button");
|
|
862
|
+
checkoutBtn.setAttribute("id", "checkout-btn");
|
|
863
|
+
checkoutBtn.textContent = "Complete Order";
|
|
864
|
+
checkoutBtn.setRect({ left: 220, top: 180, width: 180, height: 44 });
|
|
865
|
+
mockBody.appendChild(checkoutBtn);
|
|
762
866
|
|
|
763
|
-
|
|
764
|
-
floatingPinBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 50, clientY: 50 }));
|
|
765
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 150, clientY: 120 }));
|
|
766
|
-
assert.equal(pinDock.classList.contains("is-dragging"), true);
|
|
767
|
-
assert.equal(root.classList.contains("is-free-positioned"), true);
|
|
768
|
-
assert.equal(root.style.left, "120px");
|
|
769
|
-
assert.equal(root.style.top, "90px");
|
|
867
|
+
mockDocument.elementsFromPoint = () => [checkoutBtn];
|
|
770
868
|
|
|
771
|
-
|
|
772
|
-
|
|
869
|
+
// Start peeling from top-left book corner
|
|
870
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 14, clientY: 14 }));
|
|
871
|
+
assert.equal(dragPin.hidden, true);
|
|
773
872
|
|
|
774
|
-
//
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
assert.equal(
|
|
778
|
-
assert.equal(
|
|
779
|
-
assert.equal(composer.hidden, true);
|
|
873
|
+
// Drag >6px over #checkout-btn: book corner peels away & morphs into live pushpin
|
|
874
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 260, clientY: 200 }));
|
|
875
|
+
assert.equal(bookCorner.classList.contains("is-peeled"), true);
|
|
876
|
+
assert.equal(dragPin.hidden, false);
|
|
877
|
+
assert.equal(dragPin.classList.contains("has-target"), true);
|
|
780
878
|
|
|
781
|
-
//
|
|
782
|
-
|
|
783
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 210, clientY: 180 }));
|
|
784
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 210, clientY: 180 }));
|
|
785
|
-
const triggerSyntheticClick = new MockUiEvent("click", { clientX: 210, clientY: 180 });
|
|
786
|
-
triggerBtn.dispatchEvent(triggerSyntheticClick);
|
|
787
|
-
assert.equal(triggerSyntheticClick.defaultPrevented, true);
|
|
788
|
-
assert.equal(composer.hidden, true);
|
|
789
|
-
assert.equal(root.style.left, "180px");
|
|
790
|
-
assert.equal(root.style.top, "150px");
|
|
879
|
+
// Release pointer over #checkout-btn: commits pin and opens composer with chip attached
|
|
880
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 260, clientY: 200 }));
|
|
791
881
|
|
|
792
|
-
//
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
882
|
+
// Trailing synthetic click from browser is suppressed cleanly
|
|
883
|
+
const trailingClick = new MockUiEvent("click", { clientX: 260, clientY: 200 });
|
|
884
|
+
bookCorner.dispatchEvent(trailingClick);
|
|
885
|
+
assert.equal(trailingClick.defaultPrevented, true);
|
|
886
|
+
|
|
887
|
+
assert.equal(dragPin.hidden, true);
|
|
888
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
889
|
+
assert.equal(widget.getElementReferences()[0].selector, "#checkout-btn");
|
|
796
890
|
assert.equal(composer.hidden, false);
|
|
891
|
+
assert.ok(tray.querySelector(".cd-chip"));
|
|
797
892
|
});
|
|
798
893
|
});
|
|
799
894
|
|
|
800
|
-
it("
|
|
801
|
-
await withMountedWidget(
|
|
802
|
-
const
|
|
803
|
-
const
|
|
895
|
+
it("snaps and re-docks book corner when dragged into another viewport corner", async () => {
|
|
896
|
+
await withMountedWidget(({ widget, shadowRoot, mockWindow }) => {
|
|
897
|
+
const root = shadowRoot.querySelector(".cd-root");
|
|
898
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
899
|
+
const snapGhost = shadowRoot.querySelector(".cd-corner-snap-ghost");
|
|
804
900
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
805
|
-
|
|
901
|
+
assert.ok(root && bookCorner && snapGhost && composer);
|
|
902
|
+
|
|
903
|
+
bookCorner.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 12, clientY: 12 }));
|
|
904
|
+
// Move across page first
|
|
905
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 420, clientY: 340 }));
|
|
906
|
+
assert.equal(snapGhost.hidden, true);
|
|
907
|
+
|
|
908
|
+
// Enter bottom-right snap zone (viewport is 1280x800)
|
|
909
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 1250, clientY: 775 }));
|
|
910
|
+
assert.equal(snapGhost.hidden, false);
|
|
911
|
+
assert.equal(snapGhost.classList.contains("corner-bottom_right"), true);
|
|
912
|
+
|
|
913
|
+
// Release inside bottom-right snap zone: re-docks corner and stays closed
|
|
914
|
+
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 1250, clientY: 775 }));
|
|
915
|
+
assert.equal(snapGhost.hidden, true);
|
|
916
|
+
assert.equal(widget.getConfig().position, "bottom_right");
|
|
917
|
+
assert.equal(bookCorner.classList.contains("corner-bottom_right"), true);
|
|
918
|
+
assert.equal(root.classList.contains("pos-bottom_right"), true);
|
|
919
|
+
assert.equal(composer.hidden, true);
|
|
920
|
+
assert.equal(bookCorner.hidden, false);
|
|
921
|
+
});
|
|
922
|
+
});
|
|
806
923
|
|
|
807
|
-
|
|
924
|
+
it("transforms into local BYOK agentic sidebar in development, switches modes, saves keys safely, and applies staged diffs", async () => {
|
|
925
|
+
const g = globalThis as Record<string, unknown>;
|
|
926
|
+
const prevFetch = g.fetch;
|
|
927
|
+
const apiCalls: Array<{ url: string; method: string; body?: unknown }> = [];
|
|
928
|
+
|
|
929
|
+
g.fetch = async (input: string | URL, init?: RequestInit) => {
|
|
930
|
+
const url = String(input);
|
|
931
|
+
const method = (init?.method || "GET").toUpperCase();
|
|
932
|
+
const parsedBody =
|
|
933
|
+
typeof init?.body === "string" && init.body.length > 0 ? JSON.parse(init.body) : undefined;
|
|
934
|
+
apiCalls.push({ url, method, body: parsedBody });
|
|
935
|
+
|
|
936
|
+
if (url.endsWith("/agent/status")) {
|
|
937
|
+
return new Response(
|
|
938
|
+
JSON.stringify({
|
|
939
|
+
enabled: true,
|
|
940
|
+
environment: "development",
|
|
941
|
+
workspace_name: "demo-shop",
|
|
942
|
+
mcp_environments: [
|
|
943
|
+
{ name: "local", type: "local", host_env: "development" },
|
|
944
|
+
{ name: "staging", type: "remote_http" },
|
|
945
|
+
{ name: "production", type: "remote_http" }
|
|
946
|
+
],
|
|
947
|
+
active_provider: "anthropic",
|
|
948
|
+
providers: [
|
|
949
|
+
{
|
|
950
|
+
id: "anthropic",
|
|
951
|
+
label: "Anthropic Claude",
|
|
952
|
+
configured: true,
|
|
953
|
+
source: "env",
|
|
954
|
+
env_var_hint: "ANTHROPIC_API_KEY",
|
|
955
|
+
masked_key: "••••9876",
|
|
956
|
+
model: "claude-sonnet-4-20250514",
|
|
957
|
+
default_model: "claude-sonnet-4-20250514",
|
|
958
|
+
models: ["claude-sonnet-4-20250514"],
|
|
959
|
+
supports_base_url: false
|
|
960
|
+
}
|
|
961
|
+
]
|
|
962
|
+
}),
|
|
963
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
964
|
+
);
|
|
965
|
+
}
|
|
808
966
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
967
|
+
if (url.endsWith("/agent/keys") && method === "POST") {
|
|
968
|
+
return new Response(
|
|
969
|
+
JSON.stringify({
|
|
970
|
+
active_provider: "anthropic",
|
|
971
|
+
providers: [
|
|
972
|
+
{
|
|
973
|
+
id: "anthropic",
|
|
974
|
+
label: "Anthropic Claude",
|
|
975
|
+
configured: true,
|
|
976
|
+
source: "vault",
|
|
977
|
+
env_var_hint: "ANTHROPIC_API_KEY",
|
|
978
|
+
masked_key: "••••4321",
|
|
979
|
+
model: "claude-sonnet-4-20250514",
|
|
980
|
+
default_model: "claude-sonnet-4-20250514",
|
|
981
|
+
models: ["claude-sonnet-4-20250514"],
|
|
982
|
+
supports_base_url: false
|
|
983
|
+
}
|
|
984
|
+
]
|
|
985
|
+
}),
|
|
986
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
987
|
+
);
|
|
988
|
+
}
|
|
812
989
|
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
990
|
+
if (url.endsWith("/agent/chat") && method === "POST") {
|
|
991
|
+
return new Response(
|
|
992
|
+
JSON.stringify({
|
|
993
|
+
reply: "Found `#hero-cta` in `app/views/home/index.html.erb`. Escaped check: <script>alert(1)</script>",
|
|
994
|
+
provider: "anthropic",
|
|
995
|
+
model: "claude-sonnet-4-20250514",
|
|
996
|
+
tool_calls: [{ name: "read_file", summary: "Read app/views/home/index.html.erb (L1–40)", status: "ok" }],
|
|
997
|
+
proposed_edits: [
|
|
998
|
+
{
|
|
999
|
+
id: "edit_abc123",
|
|
1000
|
+
path: "app/views/home/index.html.erb",
|
|
1001
|
+
summary: "Fix button contrast and padding",
|
|
1002
|
+
is_new_file: false,
|
|
1003
|
+
diff: "@@ -4,1 +4,1 @@\n-<button id=\"hero-cta\">Buy</button>\n+<button id=\"hero-cta\" class=\"btn-primary\">Buy Now</button>",
|
|
1004
|
+
added_lines: 1,
|
|
1005
|
+
removed_lines: 1,
|
|
1006
|
+
status: "pending",
|
|
1007
|
+
created_at: "2026-11-12T10:00:00Z"
|
|
1008
|
+
}
|
|
1009
|
+
]
|
|
1010
|
+
}),
|
|
1011
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1012
|
+
);
|
|
1013
|
+
}
|
|
818
1014
|
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
1015
|
+
if (url.endsWith("/agent/edits/edit_abc123/apply") && method === "POST") {
|
|
1016
|
+
return new Response(
|
|
1017
|
+
JSON.stringify({
|
|
1018
|
+
edit: {
|
|
1019
|
+
id: "edit_abc123",
|
|
1020
|
+
path: "app/views/home/index.html.erb",
|
|
1021
|
+
summary: "Fix button contrast and padding",
|
|
1022
|
+
is_new_file: false,
|
|
1023
|
+
diff: "@@ -4,1 +4,1 @@",
|
|
1024
|
+
added_lines: 1,
|
|
1025
|
+
removed_lines: 1,
|
|
1026
|
+
status: "applied",
|
|
1027
|
+
created_at: "2026-11-12T10:00:00Z"
|
|
1028
|
+
}
|
|
1029
|
+
}),
|
|
1030
|
+
{ status: 200, headers: { "Content-Type": "application/json" } }
|
|
1031
|
+
);
|
|
1032
|
+
}
|
|
823
1033
|
|
|
824
|
-
|
|
1034
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
1035
|
+
};
|
|
825
1036
|
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
1037
|
+
try {
|
|
1038
|
+
await withMountedWidget(
|
|
1039
|
+
async ({ widget, shadowRoot, mockHtml }) => {
|
|
1040
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1041
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1042
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1043
|
+
assert.ok(bookCorner && sidebar && composer);
|
|
1044
|
+
|
|
1045
|
+
// Clicking book corner in local dev opens Agentic Sidebar, not floating composer
|
|
1046
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1047
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1048
|
+
|
|
1049
|
+
assert.equal(widget.getSurfaceMode(), "agent");
|
|
1050
|
+
assert.equal(sidebar.hidden, false);
|
|
1051
|
+
assert.equal(composer.hidden, true);
|
|
1052
|
+
|
|
1053
|
+
// Push page layout toggle sets and clears marginRight on <html>
|
|
1054
|
+
const pushBtn = shadowRoot.querySelector("[aria-label='Toggle push page layout']");
|
|
1055
|
+
assert.ok(pushBtn);
|
|
1056
|
+
pushBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1057
|
+
assert.equal(mockHtml.getAttribute("data-context-drop-pushed"), "true");
|
|
1058
|
+
assert.equal(mockHtml.style.marginRight, "560px");
|
|
1059
|
+
|
|
1060
|
+
// Switching mode to "feedback" switches cleanly to floating composer and restores page layout
|
|
1061
|
+
widget.setSurfaceMode("feedback");
|
|
1062
|
+
assert.equal(sidebar.hidden, true);
|
|
1063
|
+
assert.equal(composer.hidden, false);
|
|
1064
|
+
assert.equal(mockHtml.style.marginRight, "");
|
|
1065
|
+
|
|
1066
|
+
// Switch back to "agent" mode
|
|
1067
|
+
widget.setSurfaceMode("agent");
|
|
1068
|
+
assert.equal(sidebar.hidden, false);
|
|
1069
|
+
|
|
1070
|
+
// Save BYOK key via inline vault drawer: clears password input immediately after save
|
|
1071
|
+
const byokBtn = shadowRoot.querySelector("[aria-label='Open BYOK API key settings']");
|
|
1072
|
+
const keyInput = shadowRoot.querySelector("[aria-label='Provider API Key']");
|
|
1073
|
+
assert.ok(byokBtn && keyInput);
|
|
1074
|
+
byokBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1075
|
+
keyInput.value = "sk-ant-test-secret-4321";
|
|
1076
|
+
|
|
1077
|
+
const allButtons: MockDomElement[] = [];
|
|
1078
|
+
const collectBtns = (node: MockDomElement): void => {
|
|
1079
|
+
if (node.tagName === "BUTTON") allButtons.push(node);
|
|
1080
|
+
for (const c of node.childNodes) collectBtns(c);
|
|
1081
|
+
};
|
|
1082
|
+
collectBtns(shadowRoot);
|
|
1083
|
+
const saveBtn = allButtons.find((b) => b.textContent === "Use & Save");
|
|
1084
|
+
assert.ok(saveBtn);
|
|
1085
|
+
saveBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1086
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1087
|
+
assert.equal(keyInput.value, "", "Expected API key input to be wiped from DOM after vault save");
|
|
1088
|
+
|
|
1089
|
+
// Send an agent prompt and verify XSS-safe Markdown + interactive diff approval
|
|
1090
|
+
const agentTextarea = shadowRoot.querySelector("[aria-label='Agent prompt']");
|
|
1091
|
+
assert.ok(agentTextarea);
|
|
1092
|
+
agentTextarea.value = "Fix #hero-cta contrast";
|
|
1093
|
+
await widget.handleAgentSubmit();
|
|
1094
|
+
|
|
1095
|
+
const messages = widget.getAgentMessages();
|
|
1096
|
+
assert.equal(messages.length, 2);
|
|
1097
|
+
const mdBody = shadowRoot.querySelector(".cd-md-body");
|
|
1098
|
+
assert.ok(mdBody);
|
|
1099
|
+
assert.equal(mdBody.innerHTML.includes("<script>"), false, "Raw <script> must be HTML-escaped");
|
|
1100
|
+
assert.equal(mdBody.innerHTML.includes("<script>"), true);
|
|
1101
|
+
|
|
1102
|
+
const diffCard = shadowRoot.querySelector(".cd-diff-card");
|
|
1103
|
+
assert.ok(diffCard);
|
|
1104
|
+
const applyBtn = diffCard.querySelector(".cd-btn-apply");
|
|
1105
|
+
assert.ok(applyBtn);
|
|
1106
|
+
|
|
1107
|
+
applyBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1108
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1109
|
+
|
|
1110
|
+
assert.equal(messages[1].proposedEdits?.[0].status, "applied");
|
|
1111
|
+
assert.equal(
|
|
1112
|
+
apiCalls.some((c) => c.url.endsWith("/agent/edits/edit_abc123/apply")),
|
|
1113
|
+
true
|
|
1114
|
+
);
|
|
1115
|
+
},
|
|
1116
|
+
{
|
|
1117
|
+
"data-config": JSON.stringify({
|
|
1118
|
+
enabled: true,
|
|
1119
|
+
environment: "development",
|
|
1120
|
+
position: "top_left",
|
|
1121
|
+
csrf_token: "dev_csrf_123",
|
|
1122
|
+
agent: { enabled: true }
|
|
1123
|
+
})
|
|
1124
|
+
}
|
|
1125
|
+
);
|
|
1126
|
+
} finally {
|
|
1127
|
+
if (prevFetch === undefined) {
|
|
1128
|
+
delete g.fetch;
|
|
1129
|
+
} else {
|
|
1130
|
+
g.fetch = prevFetch;
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
830
1133
|
});
|
|
831
1134
|
|
|
832
1135
|
it("ignores nested buttons inside container drag bars (.cd-composer-header, .cd-compact-bar)", async () => {
|
|
@@ -970,4 +1273,340 @@ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
|
|
|
970
1273
|
assert.equal(mockBody.querySelector("[data-context-drop-ui='pinned-badge']"), null);
|
|
971
1274
|
});
|
|
972
1275
|
});
|
|
1276
|
+
|
|
1277
|
+
it("activates Freeze & Pin via Alt+Shift+P, pins candidate on Space, and suppresses blur events", async () => {
|
|
1278
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
1279
|
+
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
1280
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1281
|
+
assert.ok(compactBar && composer);
|
|
1282
|
+
|
|
1283
|
+
const navMenu = new MockDomElement("nav");
|
|
1284
|
+
navMenu.setAttribute("id", "transient-dropdown");
|
|
1285
|
+
const menuItem = new MockDomElement("a");
|
|
1286
|
+
menuItem.setAttribute("id", "dimensions-link");
|
|
1287
|
+
menuItem.textContent = "Dimensions";
|
|
1288
|
+
menuItem.setRect({ left: 100, top: 60, width: 140, height: 32 });
|
|
1289
|
+
navMenu.appendChild(menuItem);
|
|
1290
|
+
mockBody.appendChild(navMenu);
|
|
1291
|
+
|
|
1292
|
+
const pointNodes = [menuItem, navMenu];
|
|
1293
|
+
mockDocument.elementsFromPoint = () => pointNodes;
|
|
1294
|
+
|
|
1295
|
+
// Track pointer at (150, 80)
|
|
1296
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 150, clientY: 80 }));
|
|
1297
|
+
|
|
1298
|
+
// Press Alt+Shift+P to trigger Freeze & Pin globally
|
|
1299
|
+
const freezeKeyEv = new MockUiEvent("keydown", {
|
|
1300
|
+
key: "p",
|
|
1301
|
+
code: "KeyP",
|
|
1302
|
+
altKey: true,
|
|
1303
|
+
shiftKey: true
|
|
1304
|
+
});
|
|
1305
|
+
mockWindow.dispatchEvent(freezeKeyEv);
|
|
1306
|
+
assert.equal(freezeKeyEv.defaultPrevented, true);
|
|
1307
|
+
assert.equal(compactBar.hidden, false);
|
|
1308
|
+
|
|
1309
|
+
// Verify blur event suppression: blur on host element should be stopped
|
|
1310
|
+
const blurEv = new MockUiEvent("blur", {});
|
|
1311
|
+
mockWindow.dispatchEvent(blurEv);
|
|
1312
|
+
assert.equal(blurEv.propagationStopped, true);
|
|
1313
|
+
|
|
1314
|
+
// Verify Spacebar commits the candidate without firing mouse click
|
|
1315
|
+
const spaceKeyEv = new MockUiEvent("keydown", {
|
|
1316
|
+
key: " ",
|
|
1317
|
+
code: "Space"
|
|
1318
|
+
});
|
|
1319
|
+
mockWindow.dispatchEvent(spaceKeyEv);
|
|
1320
|
+
assert.equal(spaceKeyEv.defaultPrevented, true);
|
|
1321
|
+
|
|
1322
|
+
// Pinned elements list should now contain the candidate
|
|
1323
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
1324
|
+
assert.equal(widget.getElementReferences()[0].selector, "#dimensions-link");
|
|
1325
|
+
|
|
1326
|
+
// Press Alt+Shift+P again to exit Freeze & Pin mode
|
|
1327
|
+
const exitKeyEv = new MockUiEvent("keydown", {
|
|
1328
|
+
key: "p",
|
|
1329
|
+
code: "KeyP",
|
|
1330
|
+
altKey: true,
|
|
1331
|
+
shiftKey: true
|
|
1332
|
+
});
|
|
1333
|
+
mockWindow.dispatchEvent(exitKeyEv);
|
|
1334
|
+
assert.equal(compactBar.hidden, true);
|
|
1335
|
+
assert.equal(composer.hidden, false);
|
|
1336
|
+
});
|
|
1337
|
+
});
|
|
1338
|
+
|
|
1339
|
+
it("uses jargon-free smart component selection, auto surrounding screenshot, and compact UI in production", async () => {
|
|
1340
|
+
await withMountedWidget(
|
|
1341
|
+
async ({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
1342
|
+
// Provide a lightweight mock <canvas> 2D context so surrounding-context auto-screenshot succeeds
|
|
1343
|
+
const origCreateElement = mockDocument.createElement;
|
|
1344
|
+
mockDocument.createElement = (tag: string) => {
|
|
1345
|
+
const el = origCreateElement(tag);
|
|
1346
|
+
if (tag.toLowerCase() === "canvas") {
|
|
1347
|
+
const canvasShim = el as unknown as Record<string, unknown>;
|
|
1348
|
+
canvasShim.width = 0;
|
|
1349
|
+
canvasShim.height = 0;
|
|
1350
|
+
canvasShim.getContext = () => ({
|
|
1351
|
+
scale: () => {},
|
|
1352
|
+
fillRect: () => {},
|
|
1353
|
+
strokeRect: () => {},
|
|
1354
|
+
fillText: () => {},
|
|
1355
|
+
setLineDash: () => {},
|
|
1356
|
+
fillStyle: "",
|
|
1357
|
+
strokeStyle: "",
|
|
1358
|
+
lineWidth: 1,
|
|
1359
|
+
font: ""
|
|
1360
|
+
});
|
|
1361
|
+
canvasShim.toDataURL = () =>
|
|
1362
|
+
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M9QDwADhgGAWjR9awAAAABJRU5ErkJggg==";
|
|
1363
|
+
}
|
|
1364
|
+
return el;
|
|
1365
|
+
};
|
|
1366
|
+
|
|
1367
|
+
assert.equal(widget.isSmartSelectionMode(), true);
|
|
1368
|
+
|
|
1369
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1370
|
+
const title = shadowRoot.querySelector(".cd-composer-title");
|
|
1371
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
1372
|
+
const chatThread = shadowRoot.querySelector(".cd-chat-thread");
|
|
1373
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1374
|
+
assert.ok(composer && title && tray && chatThread && bookCorner);
|
|
1375
|
+
|
|
1376
|
+
// Production UI uses compact smart-mode layout & friendly copy
|
|
1377
|
+
assert.equal(composer.classList.contains("is-smart-mode"), true);
|
|
1378
|
+
assert.equal(title.textContent, "Send Feedback");
|
|
1379
|
+
|
|
1380
|
+
// Build host DOM: div.pricing-card > (h3 "Enterprise Plan", button#checkout-btn > span.inner-label "Complete Order")
|
|
1381
|
+
const card = new MockDomElement("div");
|
|
1382
|
+
card.setAttribute("class", "pricing-card");
|
|
1383
|
+
card.setRect({ left: 80, top: 90, width: 340, height: 210 });
|
|
1384
|
+
|
|
1385
|
+
const heading = new MockDomElement("h3");
|
|
1386
|
+
heading.textContent = "Enterprise Plan";
|
|
1387
|
+
heading.setRect({ left: 100, top: 108, width: 180, height: 26 });
|
|
1388
|
+
|
|
1389
|
+
const button = new MockDomElement("button");
|
|
1390
|
+
button.setAttribute("id", "checkout-btn");
|
|
1391
|
+
button.setRect({ left: 100, top: 220, width: 170, height: 42 });
|
|
1392
|
+
|
|
1393
|
+
const innerSpan = new MockDomElement("span");
|
|
1394
|
+
innerSpan.setAttribute("class", "inner-label");
|
|
1395
|
+
innerSpan.textContent = "Complete Order";
|
|
1396
|
+
innerSpan.setRect({ left: 116, top: 230, width: 120, height: 20 });
|
|
1397
|
+
|
|
1398
|
+
button.appendChild(innerSpan);
|
|
1399
|
+
card.appendChild(heading);
|
|
1400
|
+
card.appendChild(button);
|
|
1401
|
+
mockBody.appendChild(card);
|
|
1402
|
+
|
|
1403
|
+
mockDocument.elementsFromPoint = () => [innerSpan, button, card];
|
|
1404
|
+
|
|
1405
|
+
// Start selection from compact composer ("Select area")
|
|
1406
|
+
widget.startPinSelection();
|
|
1407
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 140, clientY: 236 }));
|
|
1408
|
+
|
|
1409
|
+
const hud = mockBody.querySelector("[data-context-drop-ui='label']");
|
|
1410
|
+
assert.ok(hud);
|
|
1411
|
+
const readAllText = (node: MockDomElement): string =>
|
|
1412
|
+
[node.textContent, ...node.childNodes.map((c) => readAllText(c))].join(" ").trim();
|
|
1413
|
+
const hudText = readAllText(hud);
|
|
1414
|
+
assert.equal(hudText.includes("“Complete Order” button"), true);
|
|
1415
|
+
assert.equal(hudText.includes("#checkout-btn"), false, "Smart HUD must omit CSS selectors");
|
|
1416
|
+
assert.equal(hud.querySelector("[data-context-drop-ui='hud-layer-list']"), null);
|
|
1417
|
+
|
|
1418
|
+
// Mouse wheel is NOT hijacked in production smart mode
|
|
1419
|
+
const wheelEv = new MockUiEvent("wheel", { clientX: 140, clientY: 236, deltaY: 40, deltaMode: 0 });
|
|
1420
|
+
mockWindow.dispatchEvent(wheelEv);
|
|
1421
|
+
assert.equal(wheelEv.defaultPrevented, false);
|
|
1422
|
+
|
|
1423
|
+
// Single click selects promoted button, exits picker immediately, and reopens compact feedback form
|
|
1424
|
+
const clickEv = new MockUiEvent("click", { clientX: 140, clientY: 236 });
|
|
1425
|
+
mockWindow.dispatchEvent(clickEv);
|
|
1426
|
+
assert.equal(clickEv.defaultPrevented, true);
|
|
1427
|
+
assert.equal(composer.hidden, false);
|
|
1428
|
+
|
|
1429
|
+
// Wait a tick for async surrounding-context screenshot capture
|
|
1430
|
+
await new Promise((r) => setTimeout(r, 15));
|
|
1431
|
+
|
|
1432
|
+
const refs = widget.getElementReferences();
|
|
1433
|
+
assert.equal(refs.length, 1);
|
|
1434
|
+
assert.equal(refs[0].selector, "#checkout-btn");
|
|
1435
|
+
assert.equal(refs[0].metadata.friendly_label, "“Complete Order” button");
|
|
1436
|
+
assert.equal(refs[0].metadata.original_target_selector, "span.inner-label");
|
|
1437
|
+
|
|
1438
|
+
const shots = widget.getAttachments();
|
|
1439
|
+
assert.equal(shots.length, 1);
|
|
1440
|
+
assert.equal(shots[0].element_reference_ref, refs[0].client_ref);
|
|
1441
|
+
assert.equal(shots[0].metadata?.capture_type, "surrounding_context");
|
|
1442
|
+
assert.equal(shots[0].metadata?.auto_smart_context, true);
|
|
1443
|
+
|
|
1444
|
+
// Tray renders a single merged .cd-smart-card (not separate technical .cd-chip items)
|
|
1445
|
+
assert.ok(tray.querySelector(".cd-smart-card"));
|
|
1446
|
+
assert.equal(tray.querySelector(".cd-chip"), null);
|
|
1447
|
+
// Empty-state chat thread hides once context is attached so composer stays ultra-compact
|
|
1448
|
+
assert.equal(chatThread.hidden, true);
|
|
1449
|
+
|
|
1450
|
+
// Removing the smart card removes BOTH the element reference and its auto-captured screenshot
|
|
1451
|
+
widget.removeElementReference(refs[0].client_ref);
|
|
1452
|
+
assert.equal(widget.getElementReferences().length, 0);
|
|
1453
|
+
assert.equal(widget.getAttachments().length, 0);
|
|
1454
|
+
assert.equal(chatThread.hidden, false);
|
|
1455
|
+
},
|
|
1456
|
+
{
|
|
1457
|
+
"data-config": JSON.stringify({
|
|
1458
|
+
enabled: true,
|
|
1459
|
+
environment: "production",
|
|
1460
|
+
position: "top_left",
|
|
1461
|
+
agent: { enabled: false }
|
|
1462
|
+
})
|
|
1463
|
+
}
|
|
1464
|
+
);
|
|
1465
|
+
});
|
|
1466
|
+
|
|
1467
|
+
it("supports dark theme toggle on top bar strictly scoped to widget without altering host page theme", async () => {
|
|
1468
|
+
await withMountedWidget(
|
|
1469
|
+
({ widget, shadowRoot, mockHtml, mockBody }) => {
|
|
1470
|
+
// Initially light theme
|
|
1471
|
+
assert.equal(widget.getTheme(), "light");
|
|
1472
|
+
|
|
1473
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1474
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1475
|
+
assert.ok(composer && sidebar);
|
|
1476
|
+
|
|
1477
|
+
const composerThemeToggle = composer.querySelector(".cd-theme-toggle");
|
|
1478
|
+
const sidebarThemeToggle = sidebar.querySelector(".cd-theme-toggle");
|
|
1479
|
+
assert.ok(composerThemeToggle, "Composer top bar has theme toggle button");
|
|
1480
|
+
assert.ok(sidebarThemeToggle, "Agent sidebar top bar has theme toggle button");
|
|
1481
|
+
|
|
1482
|
+
const themeChangeEvents: string[] = [];
|
|
1483
|
+
const onThemeChange = (ev: Event) => {
|
|
1484
|
+
const detail = (ev as CustomEvent).detail;
|
|
1485
|
+
if (detail?.theme) themeChangeEvents.push(detail.theme);
|
|
1486
|
+
};
|
|
1487
|
+
widget.addEventListener("contextdrop:themechange", onThemeChange);
|
|
1488
|
+
|
|
1489
|
+
const leakedWindowEvents: string[] = [];
|
|
1490
|
+
const onWindowThemeChange = (ev: Event) => {
|
|
1491
|
+
const detail = (ev as CustomEvent).detail;
|
|
1492
|
+
if (detail?.theme) leakedWindowEvents.push(detail.theme);
|
|
1493
|
+
};
|
|
1494
|
+
window.addEventListener("contextdrop:themechange", onWindowThemeChange);
|
|
1495
|
+
|
|
1496
|
+
// Click theme toggle in composer
|
|
1497
|
+
composerThemeToggle.dispatchEvent(new MockUiEvent("click"));
|
|
1498
|
+
|
|
1499
|
+
assert.equal(widget.getTheme(), "dark");
|
|
1500
|
+
assert.equal(widget.getAttribute("data-cd-theme"), "dark");
|
|
1501
|
+
assert.equal(widget.getAttribute("data-theme"), null, "Does not set generic data-theme on light-DOM host");
|
|
1502
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null, "Never alters host <html> theme");
|
|
1503
|
+
assert.equal(mockBody.getAttribute("data-theme"), null, "Never alters host <body> theme");
|
|
1504
|
+
assert.equal(shadowRoot.querySelector(".cd-root")?.getAttribute("data-theme"), "dark");
|
|
1505
|
+
assert.equal(shadowRoot.querySelector(".cd-composer")?.getAttribute("data-theme"), "dark");
|
|
1506
|
+
assert.equal(shadowRoot.querySelector(".cd-agent-sidebar")?.getAttribute("data-theme"), "dark");
|
|
1507
|
+
assert.equal(shadowRoot.querySelector(".cd-compact-bar")?.getAttribute("data-theme"), "dark");
|
|
1508
|
+
assert.equal(shadowRoot.querySelector(".cd-book-corner")?.getAttribute("data-theme"), "dark");
|
|
1509
|
+
assert.equal(shadowRoot.querySelector(".cd-drag-pin")?.getAttribute("data-theme"), "dark");
|
|
1510
|
+
assert.equal(composerThemeToggle.getAttribute("aria-label"), "Switch to light theme");
|
|
1511
|
+
assert.equal(themeChangeEvents.length, 1);
|
|
1512
|
+
assert.equal(themeChangeEvents[0], "dark");
|
|
1513
|
+
assert.equal(leakedWindowEvents.length, 0, "Theme change event stays scoped to widget element");
|
|
1514
|
+
|
|
1515
|
+
// Click theme toggle in sidebar to toggle back
|
|
1516
|
+
sidebarThemeToggle.dispatchEvent(new MockUiEvent("click"));
|
|
1517
|
+
|
|
1518
|
+
assert.equal(widget.getTheme(), "light");
|
|
1519
|
+
assert.equal(widget.getAttribute("data-cd-theme"), "light");
|
|
1520
|
+
assert.equal(widget.getAttribute("data-theme"), null);
|
|
1521
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null);
|
|
1522
|
+
assert.equal(mockBody.getAttribute("data-theme"), null);
|
|
1523
|
+
assert.equal(composerThemeToggle.getAttribute("aria-label"), "Switch to dark theme");
|
|
1524
|
+
assert.equal(themeChangeEvents.length, 2);
|
|
1525
|
+
assert.equal(themeChangeEvents[1], "light");
|
|
1526
|
+
|
|
1527
|
+
// Programmatic setTheme
|
|
1528
|
+
widget.setTheme("dark");
|
|
1529
|
+
assert.equal(widget.getTheme(), "dark");
|
|
1530
|
+
assert.equal(mockHtml.getAttribute("data-theme"), null);
|
|
1531
|
+
assert.equal(mockBody.getAttribute("data-theme"), null);
|
|
1532
|
+
assert.equal(themeChangeEvents.length, 3);
|
|
1533
|
+
assert.equal(themeChangeEvents[2], "dark");
|
|
1534
|
+
|
|
1535
|
+
widget.removeEventListener("contextdrop:themechange", onThemeChange);
|
|
1536
|
+
window.removeEventListener("contextdrop:themechange", onWindowThemeChange);
|
|
1537
|
+
},
|
|
1538
|
+
{
|
|
1539
|
+
"data-config": JSON.stringify({
|
|
1540
|
+
enabled: true,
|
|
1541
|
+
environment: "development",
|
|
1542
|
+
position: "bottom_right",
|
|
1543
|
+
agent: { enabled: true }
|
|
1544
|
+
})
|
|
1545
|
+
}
|
|
1546
|
+
);
|
|
1547
|
+
});
|
|
1548
|
+
|
|
1549
|
+
it("defaults sidebar width to 560px for full container item layout without crowding", async () => {
|
|
1550
|
+
await withMountedWidget(
|
|
1551
|
+
async ({ widget, shadowRoot, mockHtml }) => {
|
|
1552
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1553
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1554
|
+
assert.ok(sidebar && bookCorner);
|
|
1555
|
+
assert.equal(sidebar.style.width, "560px");
|
|
1556
|
+
|
|
1557
|
+
// Open widget in agent mode so push layout can engage
|
|
1558
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1559
|
+
await new Promise((r) => setTimeout(r, 10));
|
|
1560
|
+
|
|
1561
|
+
const pushBtn = shadowRoot.querySelector("[aria-label='Toggle push page layout']");
|
|
1562
|
+
assert.ok(pushBtn);
|
|
1563
|
+
pushBtn.dispatchEvent(new MockUiEvent("click"));
|
|
1564
|
+
assert.equal(mockHtml.style.marginRight, "560px");
|
|
1565
|
+
},
|
|
1566
|
+
{
|
|
1567
|
+
"data-config": JSON.stringify({
|
|
1568
|
+
enabled: true,
|
|
1569
|
+
environment: "development",
|
|
1570
|
+
position: "bottom_right",
|
|
1571
|
+
agent: { enabled: true }
|
|
1572
|
+
})
|
|
1573
|
+
}
|
|
1574
|
+
);
|
|
1575
|
+
});
|
|
1576
|
+
|
|
1577
|
+
it("defaults local development to staging/verbose mode when agent is disabled", async () => {
|
|
1578
|
+
await withMountedWidget(
|
|
1579
|
+
async ({ widget, shadowRoot }) => {
|
|
1580
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
1581
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
1582
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
1583
|
+
const modeSwitch = composer ? composer.querySelector(".cd-composer-mode-switch-wrap") : null;
|
|
1584
|
+
assert.ok(bookCorner && composer && sidebar && modeSwitch);
|
|
1585
|
+
|
|
1586
|
+
// When agent is disabled for local development:
|
|
1587
|
+
assert.equal(widget.isAgentModeActive(), false);
|
|
1588
|
+
assert.equal(widget.isSmartSelectionMode(), false); // verbose mode
|
|
1589
|
+
assert.equal(modeSwitch.hidden, true);
|
|
1590
|
+
|
|
1591
|
+
// Clicking the book corner opens the floating verbose composer
|
|
1592
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
1593
|
+
assert.equal(composer.hidden, false);
|
|
1594
|
+
assert.equal(sidebar.hidden, true);
|
|
1595
|
+
|
|
1596
|
+
// Opting into agent enables agent mode
|
|
1597
|
+
widget.setWidgetConfig({ agent: { enabled: true } });
|
|
1598
|
+
assert.equal(widget.isAgentModeActive(), true);
|
|
1599
|
+
assert.equal(sidebar.hidden, false);
|
|
1600
|
+
assert.equal(composer.hidden, true);
|
|
1601
|
+
},
|
|
1602
|
+
{
|
|
1603
|
+
"data-config": JSON.stringify({
|
|
1604
|
+
enabled: true,
|
|
1605
|
+
environment: "development",
|
|
1606
|
+
position: "bottom_right",
|
|
1607
|
+
agent: { enabled: false }
|
|
1608
|
+
})
|
|
1609
|
+
}
|
|
1610
|
+
);
|
|
1611
|
+
});
|
|
973
1612
|
});
|