Skip to content

Commit 2375591

Browse files
committed
test(webview-ui): add visual snapshot for TelemetryBanner
1 parent 2637e20 commit 2375591

4 files changed

Lines changed: 89 additions & 0 deletions

File tree

webview-ui/playwright/vscode-theme-dark.css

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,27 @@ body {
8787
#root {
8888
padding: 16px;
8989
}
90+
91+
/* The @vscode/webview-ui-toolkit/react mock (aliased in for CT, same as Vitest) renders
92+
VSCodeButton as a bare <button appearance="primary|secondary">, since that mock only needs
93+
to be functional for behavior tests. Style it here so button screenshots match VS Code's
94+
real appearance instead of an unstyled browser button. */
95+
button[appearance="primary"],
96+
button[appearance="secondary"] {
97+
border: none;
98+
border-radius: 2px;
99+
padding: 4px 14px;
100+
font-family: var(--vscode-font-family);
101+
font-size: var(--vscode-font-size);
102+
cursor: pointer;
103+
}
104+
105+
button[appearance="primary"] {
106+
color: var(--vscode-button-foreground);
107+
background: var(--vscode-button-background);
108+
}
109+
110+
button[appearance="secondary"] {
111+
color: var(--vscode-button-secondaryForeground);
112+
background: var(--vscode-button-secondaryBackground);
113+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import React from "react"
2+
import i18next from "i18next"
3+
import { I18nextProvider, initReactI18next } from "react-i18next"
4+
5+
import { TranslationContext } from "@src/i18n/TranslationContext"
6+
import TelemetryBanner from "../TelemetryBanner"
7+
8+
const translations: Record<string, string> = {
9+
"welcome:telemetry.helpImprove": "Help Improve Zoo Code",
10+
"welcome:telemetry.helpImproveMessage":
11+
"Zoo Code collects error and usage data, linked to a per-install identifier, to help us fix bugs and improve the extension. This telemetry does not collect your code or prompts. You can turn this off in <settingsLink>settings</settingsLink>.",
12+
"welcome:telemetry.accept": "Accept",
13+
"welcome:telemetry.decline": "Decline",
14+
}
15+
16+
// Trans reads from its own react-i18next instance rather than the useAppTranslation
17+
// context, so it needs a real (if minimal) i18next init to resolve helpImproveMessage
18+
// and the settingsLink interpolation instead of rendering nothing.
19+
const visualTestI18n = i18next.createInstance()
20+
void visualTestI18n.use(initReactI18next).init({
21+
lng: "en",
22+
fallbackLng: "en",
23+
ns: ["welcome"],
24+
defaultNS: "welcome",
25+
resources: {
26+
en: {
27+
welcome: {
28+
telemetry: {
29+
helpImprove: translations["welcome:telemetry.helpImprove"],
30+
helpImproveMessage: translations["welcome:telemetry.helpImproveMessage"],
31+
accept: translations["welcome:telemetry.accept"],
32+
decline: translations["welcome:telemetry.decline"],
33+
},
34+
},
35+
},
36+
},
37+
interpolation: { escapeValue: false },
38+
})
39+
40+
export const TelemetryBannerFixture = () => (
41+
<I18nextProvider i18n={visualTestI18n}>
42+
<TranslationContext.Provider
43+
value={{
44+
t: (key) => translations[key] ?? key,
45+
i18n: null as unknown as typeof import("../../../i18n/setup").default,
46+
}}>
47+
<TelemetryBanner />
48+
</TranslationContext.Provider>
49+
</I18nextProvider>
50+
)
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from "react"
2+
3+
import { expect, test } from "../../../../playwright/coverage-fixture"
4+
import { TelemetryBannerFixture } from "./TelemetryBanner.visual.fixture"
5+
6+
test("renders the telemetry consent banner in the VS Code dark theme", async ({ mount }) => {
7+
const component = await mount(<TelemetryBannerFixture />)
8+
9+
await component.evaluate(async () => {
10+
await document.fonts.ready
11+
await new Promise<void>((resolve) => requestAnimationFrame(() => resolve()))
12+
})
13+
14+
await expect(component).toHaveScreenshot("telemetry-banner-dark.png")
15+
})
12.5 KB
Loading

0 commit comments

Comments
 (0)