Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { describe, expect, it, vi } from "vite-plus/test";
import { page, userEvent } from "vite-plus/test/browser";

import { render } from "../../../test/render";
import {
CUSTOM_THEMES_STORAGE_KEY,
getCustomThemes,
installCustomTheme,
invalidateCustomThemes,
parseThemeFile,
THEME_FILE_VERSION,
} from "../../themePalette";
import type { OpenVsxThemeExtension } from "../../openVsxThemes";
import { ThemeImportDialog } from "./ThemeImportDialog";

Expand Down Expand Up @@ -54,3 +62,53 @@ describe("ThemeImportDialog", () => {
);
});
});

const theme = (name: string, accent = "#3b82f6") => ({
version: THEME_FILE_VERSION,
name,
appearance: "dark",
colors: { accent },
});

const themeFile = (name: string, accent?: string) =>
new File([JSON.stringify(theme(name, accent))], `${name}.json`, { type: "application/json" });

it.each(["Update existing", "Keep both"])(
"keeps batch failures visible after %s",
async (choice) => {
using _themes = {
[Symbol.dispose]() {
window.localStorage.removeItem(CUSTOM_THEMES_STORAGE_KEY);
invalidateCustomThemes();
},
};
installCustomTheme(parseThemeFile(theme("Dusk")));
const onOpenChange = vi.fn();
await using _screen = await render(
<ThemeImportDialog
open
onOpenChange={onOpenChange}
onImported={() => true}
onImportedMany={() => {}}
/>,
);
const input = document.querySelector<HTMLInputElement>('input[type="file"]')!;
await userEvent.upload(input, [
themeFile("Dawn"),
themeFile("Dusk", "#f97316"),
new File(["{"], "broken.json", { type: "application/json" }),
]);

await expect.element(page.getByText("Already installed")).toBeVisible();
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
expect(getCustomThemes().map((theme) => theme.label)).toContain("Dawn");
await page.getByRole("button", { name: choice }).click();
invalidateCustomThemes();
const label = choice === "Update existing" ? "Dusk" : "Dusk (1)";
expect(getCustomThemes().find((theme) => theme.label === label)?.colors).toEqual(
parseThemeFile(theme("Dusk", "#f97316")).colors,
);
await expect.element(page.getByText(/^broken\.json:/)).toBeVisible();
expect(onOpenChange).not.toHaveBeenCalledWith(false);
},
);
11 changes: 5 additions & 6 deletions apps/web/src/components/settings/ThemeImportDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,10 @@ function ThemeImportBody({
}
}
if (installed.length > 0) onImportedMany(installed, { updated: false });
if (failures.length > 0) {
setError(failures.join("; "));
} else if (conflicting.length > 0) {
setError(failures.length > 0 ? failures.join("; ") : null);
if (conflicting.length > 0) {
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
setConflicts(conflicting);
} else if (installed.length > 0) {
} else if (installed.length > 0 && failures.length === 0) {
onClose();
}
};
Expand Down Expand Up @@ -387,8 +386,8 @@ function ThemeImportBody({
}
if (resolved.length > 0) onImportedMany(resolved, { updated: mode === "update" });
setConflicts(null);
if (failures.length > 0) setError(failures.join("; "));
else onClose();
if (failures.length > 0) setError([error, ...failures].filter(Boolean).join("; "));
else if (!error) onClose();
};

const handleSubmit = () => {
Expand Down
Loading