@@ -50,6 +50,22 @@ function click(anchor: HTMLAnchorElement, init: MouseEventInit = {}) {
5050 return event;
5151}
5252
53+ function clickWithoutNavigation(anchor: HTMLAnchorElement, init: MouseEventInit = {}) {
54+ let defaultPrevented: boolean | undefined;
55+ const preventNavigation = (event: MouseEvent) => {
56+ defaultPrevented = event.defaultPrevented;
57+ event.preventDefault();
58+ };
59+ // Observe after the native router, then suppress jsdom's default navigation.
60+ window.addEventListener("click", preventNavigation, { once: true });
61+ try {
62+ click(anchor, init);
63+ return defaultPrevented;
64+ } finally {
65+ window.removeEventListener("click", preventNavigation);
66+ }
67+ }
68+
5369function contextMenu(anchor: HTMLAnchorElement) {
5470 const event = new MouseEvent("contextmenu", {
5571 bubbles: true,
@@ -192,7 +208,7 @@ describe("native link routing", () => {
192208 ]);
193209 });
194210
195- it("preserves modifiers , local/ file/download links , and non-web schemes ", () => {
211+ it("preserves modified , local, file, download , and untrusted app-link clicks ", () => {
196212 const bridge = installBridge();
197213 routing = startNativeLinkRouting();
198214 const links = [
@@ -202,15 +218,11 @@ describe("native link routing", () => {
202218 appendLink("mailto:
[email protected] "),
203219 ];
204220 for (const anchor of links) {
205- anchor.addEventListener("click", (event) => event.preventDefault());
206- click(anchor);
221+ expect(clickWithoutNavigation(anchor)).toBe(false);
207222 }
208223 const modified = appendLink("https://example.com/modified");
209- const bubbleHandler = vi.fn((event: Event) => event.preventDefault());
210- modified.addEventListener("click", bubbleHandler);
211- click(modified, { metaKey: true });
224+ expect(clickWithoutNavigation(modified, { metaKey: true })).toBe(false);
212225
213- expect(bubbleHandler).toHaveBeenCalledOnce();
214226 expect(bridge.messages).toEqual([]);
215227 });
216228
@@ -317,9 +329,10 @@ describe("native link routing", () => {
317329
318330 routing.dispose();
319331 routing = undefined;
320- anchor.addEventListener("click", (event) => event.preventDefault());
321- click(anchor);
322332
333+ expect(document.querySelector("openclaw-native-link-menu")).toBeNull();
334+ expect(clickWithoutNavigation(anchor)).toBe(false);
335+ expect(contextMenu(anchor).defaultPrevented).toBe(false);
323336 expect(document.querySelector("openclaw-native-link-menu")).toBeNull();
324337 expect(bridge.messages).toEqual([]);
325338 });
0 commit comments