Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThemeImportDialog.browser.test.tsx

56 lines1.7 KB

1import { StrictMode } from "react";
2import { describe, expect, it, vi } from "vite-plus/test";
3import { page, userEvent } from "vite-plus/test/browser";
4​
5import { render } from "../../../test/render";
6import type { OpenVsxThemeExtension } from "../../openVsxThemes";
7import { ThemeImportDialog } from "./ThemeImportDialog";
8​
9const searchOpenVsxThemes = vi.hoisted(() => vi.fn());
10​
11vi.mock("../../openVsxThemes", () => ({
12 searchOpenVsxThemes,
13 importOpenVsxThemeExtension: vi.fn(),
14}));
15​
16const extension: OpenVsxThemeExtension = {
17 id: "acme.nightfall",
18 collectionId: "acme.nightfall",
19 name: "Nightfall",
20 publisher: "acme",
21 description: "A dark theme",
22 downloadCount: 10,
23 iconUrl: null,
24 sourceUrl: null,
25 manifestUrl: "https://example.test/manifest",
26 sha256Url: "https://example.test/sha256",
27 vsixUrl: "https://example.test/vsix",
28 version: "1.0.0",
29 license: "MIT",
30};
31​
32describe("ThemeImportDialog", () => {
33 // StrictMode replays ref attach/detach on mount, which must not end the session.
34 it("searches Open VSX under StrictMode", async () => {
35 searchOpenVsxThemes.mockReset();
36 searchOpenVsxThemes.mockResolvedValue([extension]);
37 await using _screen = await render(
38 <StrictMode>
39 <ThemeImportDialog
40 open
41 onOpenChange={() => {}}
42 onImported={() => true}
43 onImportedMany={() => {}}
44 />
45 </StrictMode>,
46 );
47​
48 await userEvent.type(page.getByLabelText("Search Open VSX themes"), "night");
49​
50 await expect.element(page.getByRole("heading", { name: "Nightfall" })).toBeVisible();
51 expect(searchOpenVsxThemes).toHaveBeenCalledWith(
52 "night",
53 expect.objectContaining({ sortBy: "downloadCount" }),
54 );
55 });
56});