context_drop 0.1.4 → 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 +184 -107
- data/SPEC.md +74 -26
- data/app/assets/javascripts/context_drop/context_drop.js +5121 -651
- 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/feedbacks_controller.rb +13 -3
- 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__/widget.test.ts +661 -89
- data/app/javascript/context_drop/api-client.ts +130 -11
- data/app/javascript/context_drop/element-picker.ts +185 -33
- 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 +2591 -290
- data/app/models/context_drop/feedback.rb +23 -0
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +5 -0
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +10 -0
- data/app/views/layouts/context_drop/application.html.erb +1 -0
- 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 +11 -1
|
@@ -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 {
|
|
@@ -439,6 +492,8 @@ class MockDomElement {
|
|
|
439
492
|
public placeholder: string = "";
|
|
440
493
|
public value: string = "";
|
|
441
494
|
public disabled: boolean = false;
|
|
495
|
+
public selected: boolean = false;
|
|
496
|
+
public autocomplete: string = "";
|
|
442
497
|
public multiple: boolean = false;
|
|
443
498
|
public accept: string = "";
|
|
444
499
|
public scrollTop: number = 0;
|
|
@@ -654,13 +709,24 @@ function withMountedWidget(
|
|
|
654
709
|
widget: ContextDropWidgetElement;
|
|
655
710
|
shadowRoot: MockDomElement;
|
|
656
711
|
mockBody: MockDomElement;
|
|
712
|
+
mockHtml: MockDomElement;
|
|
657
713
|
mockDocument: {
|
|
658
714
|
body: MockDomElement;
|
|
715
|
+
documentElement: MockDomElement;
|
|
659
716
|
createElement: (tag: string) => MockDomElement;
|
|
717
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
660
718
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
661
719
|
};
|
|
662
720
|
mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
|
|
663
|
-
}) => 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
|
+
}
|
|
664
730
|
): Promise<void> {
|
|
665
731
|
const g = globalThis as Record<string, unknown>;
|
|
666
732
|
const prevWindow = g.window;
|
|
@@ -671,14 +737,21 @@ function withMountedWidget(
|
|
|
671
737
|
innerHeight: 800,
|
|
672
738
|
location: { href: "http://localhost:3000/orders" }
|
|
673
739
|
});
|
|
740
|
+
const mockHtml = new MockDomElement("html");
|
|
674
741
|
const mockBody = new MockDomElement("body");
|
|
742
|
+
mockHtml.appendChild(mockBody);
|
|
743
|
+
|
|
675
744
|
const mockDocument: {
|
|
676
745
|
body: MockDomElement;
|
|
746
|
+
documentElement: MockDomElement;
|
|
677
747
|
createElement: (tag: string) => MockDomElement;
|
|
748
|
+
querySelector: (sel: string) => MockDomElement | null;
|
|
678
749
|
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
679
750
|
} = {
|
|
680
751
|
body: mockBody,
|
|
681
|
-
|
|
752
|
+
documentElement: mockHtml,
|
|
753
|
+
createElement: (tag: string) => new MockDomElement(tag),
|
|
754
|
+
querySelector: () => null
|
|
682
755
|
};
|
|
683
756
|
|
|
684
757
|
g.window = mockWindow;
|
|
@@ -686,17 +759,45 @@ function withMountedWidget(
|
|
|
686
759
|
|
|
687
760
|
const shadowRoot = new MockDomElement("shadow-root");
|
|
688
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));
|
|
689
764
|
const hostShim = widget as unknown as {
|
|
690
765
|
attachShadow: () => ShadowRoot;
|
|
691
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;
|
|
692
772
|
};
|
|
693
773
|
hostShim.attachShadow = () => shadowRoot as unknown as ShadowRoot;
|
|
694
|
-
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
|
+
};
|
|
695
796
|
|
|
696
797
|
widget.connectedCallback();
|
|
697
798
|
|
|
698
799
|
return Promise.resolve()
|
|
699
|
-
.then(() => fn({ widget, shadowRoot, mockBody, mockDocument, mockWindow }))
|
|
800
|
+
.then(() => fn({ widget, shadowRoot, mockBody, mockHtml, mockDocument, mockWindow }))
|
|
700
801
|
.finally(() => {
|
|
701
802
|
widget.disconnectedCallback();
|
|
702
803
|
if (prevWindow === undefined) {
|
|
@@ -712,126 +813,323 @@ function withMountedWidget(
|
|
|
712
813
|
});
|
|
713
814
|
}
|
|
714
815
|
|
|
715
|
-
describe("ContextDrop
|
|
716
|
-
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 () => {
|
|
717
818
|
await withMountedWidget(({ shadowRoot, mockWindow }) => {
|
|
718
|
-
const
|
|
719
|
-
const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
|
|
720
|
-
const triggerBtn = shadowRoot.querySelector(".cd-trigger");
|
|
819
|
+
const bookCorner = shadowRoot.querySelector(".cd-book-corner");
|
|
721
820
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
821
|
+
const sidebar = shadowRoot.querySelector(".cd-agent-sidebar");
|
|
722
822
|
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
723
823
|
|
|
724
|
-
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);
|
|
725
827
|
assert.equal(composer.hidden, true);
|
|
828
|
+
assert.equal(sidebar.hidden, true);
|
|
726
829
|
assert.equal(compactBar.hidden, true);
|
|
727
|
-
assert.equal(pinDock.hidden, false);
|
|
728
830
|
|
|
729
|
-
//
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
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 }));
|
|
734
835
|
|
|
735
836
|
assert.equal(composer.hidden, false);
|
|
736
|
-
assert.equal(
|
|
737
|
-
assert.equal(
|
|
837
|
+
assert.equal(bookCorner.hidden, true);
|
|
838
|
+
assert.equal(bookCorner.getAttribute("aria-expanded"), "true");
|
|
738
839
|
|
|
739
|
-
// Close composer to
|
|
840
|
+
// Close composer returns to flush book corner
|
|
740
841
|
const closeBtn = shadowRoot.querySelector("[aria-label='Close feedback composer']");
|
|
741
842
|
assert.ok(closeBtn);
|
|
742
843
|
closeBtn.dispatchEvent(new MockUiEvent("click"));
|
|
743
844
|
assert.equal(composer.hidden, true);
|
|
744
|
-
assert.equal(
|
|
845
|
+
assert.equal(bookCorner.hidden, false);
|
|
745
846
|
|
|
746
|
-
//
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 30, clientY: 30 }));
|
|
750
|
-
pinSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 30, clientY: 30 }));
|
|
751
|
-
|
|
752
|
-
assert.equal(compactBar.hidden, false);
|
|
753
|
-
assert.equal(floatingPinBtn.getAttribute("aria-pressed"), "true");
|
|
847
|
+
// Keyboard activation (click without pointerdown/pointerup) also opens composer
|
|
848
|
+
bookCorner.dispatchEvent(new MockUiEvent("click"));
|
|
849
|
+
assert.equal(composer.hidden, false);
|
|
754
850
|
});
|
|
755
851
|
});
|
|
756
852
|
|
|
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");
|
|
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");
|
|
763
857
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
764
|
-
const
|
|
858
|
+
const tray = shadowRoot.querySelector(".cd-tray");
|
|
859
|
+
assert.ok(bookCorner && dragPin && composer && tray);
|
|
765
860
|
|
|
766
|
-
|
|
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);
|
|
767
866
|
|
|
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");
|
|
867
|
+
mockDocument.elementsFromPoint = () => [checkoutBtn];
|
|
775
868
|
|
|
776
|
-
|
|
777
|
-
|
|
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);
|
|
778
872
|
|
|
779
|
-
//
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
assert.equal(
|
|
783
|
-
assert.equal(
|
|
784
|
-
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);
|
|
785
878
|
|
|
786
|
-
//
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
const
|
|
791
|
-
|
|
792
|
-
assert.equal(
|
|
793
|
-
assert.equal(composer.hidden, true);
|
|
794
|
-
assert.equal(root.style.left, "180px");
|
|
795
|
-
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 }));
|
|
881
|
+
|
|
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);
|
|
796
886
|
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
triggerBtn.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 210, clientY: 180 }));
|
|
887
|
+
assert.equal(dragPin.hidden, true);
|
|
888
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
889
|
+
assert.equal(widget.getElementReferences()[0].selector, "#checkout-btn");
|
|
801
890
|
assert.equal(composer.hidden, false);
|
|
891
|
+
assert.ok(tray.querySelector(".cd-chip"));
|
|
802
892
|
});
|
|
803
893
|
});
|
|
804
894
|
|
|
805
|
-
it("
|
|
806
|
-
await withMountedWidget(
|
|
807
|
-
const
|
|
808
|
-
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");
|
|
809
900
|
const composer = shadowRoot.querySelector(".cd-composer");
|
|
810
|
-
|
|
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
|
+
});
|
|
811
923
|
|
|
812
|
-
|
|
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
|
+
}
|
|
813
966
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
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
|
+
}
|
|
817
989
|
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
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
|
+
}
|
|
823
1014
|
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
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
|
+
}
|
|
828
1033
|
|
|
829
|
-
|
|
1034
|
+
return new Response(JSON.stringify({}), { status: 200 });
|
|
1035
|
+
};
|
|
830
1036
|
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
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
|
+
}
|
|
835
1133
|
});
|
|
836
1134
|
|
|
837
1135
|
it("ignores nested buttons inside container drag bars (.cd-composer-header, .cd-compact-bar)", async () => {
|
|
@@ -1037,4 +1335,278 @@ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
|
|
|
1037
1335
|
assert.equal(composer.hidden, false);
|
|
1038
1336
|
});
|
|
1039
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
|
+
});
|
|
1040
1612
|
});
|