Registry Mirror
Skip to content

File tree

‎apps/web/src/components/settings/ThemeImportDialog.browser.test.tsx‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,24 @@ describe("ThemeImportDialog", () => {
174174
await userEvent.keyboard("{Escape}");
175175
expect(onOpenChange).toHaveBeenCalledWith(false);
176176
});
177+
178+
it("clears a stale import error when Theme JSON is edited", async () => {
179+
await using _screen = await render(
180+
<ThemeImportDialog
181+
open
182+
onOpenChange={() => {}}
183+
onImported={() => true}
184+
onImportedMany={() => {}}
185+
/>,
186+
);
187+
const editor = page.getByRole("textbox", { name: "Theme JSON" });
188+
await userEvent.fill(editor, "{");
189+
await page.getByRole("button", { name: "Add theme", exact: true }).click();
190+
await expect.element(page.getByRole("alert")).toBeVisible();
191+
192+
await userEvent.fill(editor, "{}");
193+
await expect.element(page.getByRole("alert")).not.toBeInTheDocument();
194+
});
177195
});
178196

179197
const theme = (name: string, accent = "#3b82f6", css?: string) => ({

‎apps/web/src/components/settings/ThemeImportDialog.tsx‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,11 @@ function ThemeImportBody({
407407
else if (!error) onClose();
408408
};
409409

410+
const handleJsonChange = (nextJson: string) => {
411+
setJson(nextJson);
412+
setError(null);
413+
};
414+
410415
const handleSubmit = () => {
411416
const oversized = describeOversizedThemeFile(json.length);
412417
if (oversized) {
@@ -495,7 +500,7 @@ function ThemeImportBody({
495500
<T>Theme JSON</T>
496501
</label>
497502
</div>
498-
<ThemeJsonEditor id="theme-json-editor" onChange={setJson} value={json} />
503+
<ThemeJsonEditor id="theme-json-editor" onChange={handleJsonChange} value={json} />
499504
</div>
500505
);
501506
if (conflicts) {

0 commit comments

Comments
 (0)