|
| 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 | +) |
0 commit comments