Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go
1.9 KB
Raw Blame
import { renderToString } from "react-dom/server";
import { render } from "@testing-library/react";
import { afterEach, describe, expect, it, vi } from "vitest";
import type { LocaleBundleProps } from "./i18n/locale-bundle";

const installUserTimingCap = vi.hoisted(() => vi.fn());

vi.mock("@multica/core/diagnostics", () => ({ installUserTimingCap }));
vi.mock("@multica/core/platform", () => ({
  CoreProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
vi.mock("@multica/core/i18n/browser", () => ({
  createBrowserCookieLocaleAdapter: () => ({}),
}));
vi.mock("@/platform/navigation", () => ({
  WebNavigationProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
vi.mock("@/platform/scroll-restoration", () => ({
  WebScrollRestorationProvider: ({ children }: { children: React.ReactNode }) => <>{children}</>,
}));
vi.mock("@/platform/user-locale-sync", () => ({ useUserLocaleSyncEnabled: () => false }));
vi.mock("@/components/i18n/locale-bundle", () => ({
  LocaleBundle: ({ children }: LocaleBundleProps) => children({}),
}));

import { WebProviders } from "./web-providers";

const tree = (
  <WebProviders locale="en">
    <span />
  </WebProviders>
);

afterEach(() => {
  vi.unstubAllEnvs();
  installUserTimingCap.mockClear();
});

describe("WebProviders user timing cap", () => {
  it("installs the cap in development", () => {
    vi.stubEnv("NODE_ENV", "development");
    render(tree);
    expect(installUserTimingCap).toHaveBeenCalledTimes(1);
  });

  it("does not install the cap in production", () => {
    vi.stubEnv("NODE_ENV", "production");
    render(tree);
    expect(installUserTimingCap).not.toHaveBeenCalled();
  });

  it("does not install the cap during server rendering", () => {
    vi.stubEnv("NODE_ENV", "development");
    renderToString(tree);
    expect(installUserTimingCap).not.toHaveBeenCalled();
  });
});