Skip to content

Commit 4b85ff3

Browse files
committed
test: cover all announcement links and apply review fixes
1 parent 5140541 commit 4b85ff3

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix terminal startup failures that leave commands unresolved (PR #1351 by @app/zoomote)
1313
- Fix background service failures that surface as unhandled rejections (PR #1352 by @app/zoomote)
1414
- Keep rendered content legible across IDE themes (PR #1344 by @app/zoomote)
15+
- Fix announcement links opening twice in the VS Code webview (PR #1432 by @edelauna)
1516

1617
## [3.80.0]
1718

‎src/CHANGELOG.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix terminal startup failures that leave commands unresolved (PR #1351 by @app/zoomote)
1313
- Fix background service failures that surface as unhandled rejections (PR #1352 by @app/zoomote)
1414
- Keep rendered content legible across IDE themes (PR #1344 by @app/zoomote)
15+
- Fix announcement links opening twice in the VS Code webview (PR #1432 by @edelauna)
1516

1617
## [3.80.0]
1718

‎webview-ui/src/components/chat/Announcement.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ const openExternal = (url: string) => (event: MouseEvent<HTMLAnchorElement>) =>
9797
const SocialLink = ({ icon, label, href }: { icon: ReactNode; label: string; href: string }) => (
9898
<a
9999
href={href}
100-
className="inline-flex items-center gap-1 text-vscode-textLink-foreground underline"
100+
className="inline-flex items-center gap-1 text-vscode-textLink-foreground"
101101
onClick={openExternal(href)}>
102102
{icon}
103103
<span className="sr-only">{label}</span>

‎webview-ui/src/components/chat/__tests__/Announcement.links.visual.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ test("announcement links open exactly once through the extension host", async ({
4141
const w = window as unknown as { __interceptedLinks: string[] }
4242
w.__interceptedLinks = []
4343
document.addEventListener("click", (event) => {
44+
// Real Playwright clicks arrive as trusted events; skip synthetic
45+
// dispatches so the mirror only records genuine user clicks.
4446
if (!event.isTrusted) {
4547
return
4648
}
@@ -57,6 +59,8 @@ test("announcement links open exactly once through the extension host", async ({
5759
await page.getByRole("link", { name: /zoocode\.dev\/models/ }).click()
5860
await page.getByRole("link", { name: "GitHub" }).click()
5961
await page.getByRole("link", { name: "X", exact: true }).click()
62+
await page.getByRole("link", { name: "Discord" }).click()
63+
await page.getByRole("link", { name: "Reddit" }).click()
6064

6165
// The modal overlay blocks the control link behind it; close the dialog
6266
// (which also exercises hideAnnouncement) before clicking it.
@@ -68,6 +72,8 @@ test("announcement links open exactly once through the extension host", async ({
6872
{ type: "openExternal", url: "https://zoocode.dev/models" },
6973
{ type: "openExternal", url: "https://github.com/Zoo-Code-Org/Zoo-Code" },
7074
{ type: "openExternal", url: "https://x.com/ZooCodeDev" },
75+
{ type: "openExternal", url: "https://discord.gg/VxfP4Vx3gX" },
76+
{ type: "openExternal", url: "https://www.reddit.com/r/ZooCode/" },
7177
])
7278

7379
// Only the control anchor reaches VS Code's click interception.

‎webview-ui/src/components/chat/__tests__/Announcement.spec.tsx‎

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react"
22

3-
import { render, screen } from "@/utils/test-utils"
3+
import { fireEvent, render, screen } from "@/utils/test-utils"
44
import { EXTERNAL_LINKS } from "@/constants/externalLinks"
5+
import { vscode } from "@/utils/vscode"
56

67
import Announcement from "../Announcement"
78

@@ -83,4 +84,61 @@ describe("Announcement", () => {
8384
EXTERNAL_LINKS.MODELS,
8485
)
8586
})
87+
88+
it("posts each announcement link to the extension host exactly once", () => {
89+
render(<Announcement hideAnnouncement={vi.fn()} />)
90+
91+
fireEvent.click(screen.getByRole("link", { name: "https://zoocode.dev/models" }))
92+
fireEvent.click(screen.getByRole("link", { name: "GitHub" }))
93+
fireEvent.click(screen.getByRole("link", { name: "X" }))
94+
fireEvent.click(screen.getByRole("link", { name: "Discord" }))
95+
fireEvent.click(screen.getByRole("link", { name: "Reddit" }))
96+
97+
expect(vscode.postMessage).toHaveBeenCalledTimes(5)
98+
expect(vscode.postMessage).toHaveBeenNthCalledWith(1, { type: "openExternal", url: EXTERNAL_LINKS.MODELS })
99+
expect(vscode.postMessage).toHaveBeenNthCalledWith(2, { type: "openExternal", url: EXTERNAL_LINKS.GITHUB_REPO })
100+
expect(vscode.postMessage).toHaveBeenNthCalledWith(3, { type: "openExternal", url: "https://x.com/ZooCodeDev" })
101+
expect(vscode.postMessage).toHaveBeenNthCalledWith(4, {
102+
type: "openExternal",
103+
url: "https://discord.gg/VxfP4Vx3gX",
104+
})
105+
expect(vscode.postMessage).toHaveBeenNthCalledWith(5, {
106+
type: "openExternal",
107+
url: "https://www.reddit.com/r/ZooCode/",
108+
})
109+
})
110+
111+
// VS Code's webview bootstrap intercepts clicks on any anchor with an href
112+
// at the document level and never checks defaultPrevented, so the
113+
// announcement links must stop propagation to avoid opening twice.
114+
it("keeps announcement link clicks from reaching the document level", () => {
115+
const documentClick = vi.fn()
116+
document.addEventListener("click", documentClick)
117+
118+
try {
119+
render(
120+
<div>
121+
<a href="#control">control</a>
122+
<Announcement hideAnnouncement={vi.fn()} />
123+
</div>,
124+
)
125+
126+
fireEvent.click(screen.getByRole("link", { name: "GitHub" }))
127+
expect(documentClick).not.toHaveBeenCalled()
128+
129+
fireEvent.click(screen.getByText("control"))
130+
expect(documentClick).toHaveBeenCalledTimes(1)
131+
} finally {
132+
document.removeEventListener("click", documentClick)
133+
}
134+
})
135+
136+
it("hides the announcement when the dialog closes", () => {
137+
const hideAnnouncement = vi.fn()
138+
render(<Announcement hideAnnouncement={hideAnnouncement} />)
139+
140+
fireEvent.keyDown(document.body, { key: "Escape" })
141+
142+
expect(hideAnnouncement).toHaveBeenCalledTimes(1)
143+
})
86144
})

0 commit comments

Comments
 (0)