@@ -3,6 +3,14 @@ import { describe, expect, it, vi } from "vite-plus/test";
33import { page , userEvent } from "vite-plus/test/browser" ;
44
55import { render } from "../../../test/render" ;
6+ import {
7+ CUSTOM_THEMES_STORAGE_KEY ,
8+ getCustomThemes ,
9+ installCustomTheme ,
10+ invalidateCustomThemes ,
11+ parseThemeFile ,
12+ THEME_FILE_VERSION ,
13+ } from "../../themePalette" ;
614import type { OpenVsxThemeExtension } from "../../openVsxThemes" ;
715import { ThemeImportDialog } from "./ThemeImportDialog" ;
816
@@ -54,3 +62,53 @@ describe("ThemeImportDialog", () => {
5462 ) ;
5563 } ) ;
5664} ) ;
65+
66+ const theme = ( name : string , accent = "#3b82f6" ) => ( {
67+ version : THEME_FILE_VERSION ,
68+ name,
69+ appearance : "dark" ,
70+ colors : { accent } ,
71+ } ) ;
72+
73+ const themeFile = ( name : string , accent ?: string ) =>
74+ new File ( [ JSON . stringify ( theme ( name , accent ) ) ] , `${ name } .json` , { type : "application/json" } ) ;
75+
76+ it . each ( [ "Update existing" , "Keep both" ] ) (
77+ "keeps batch failures visible after %s" ,
78+ async ( choice ) => {
79+ using _themes = {
80+ [ Symbol . dispose ] ( ) {
81+ window . localStorage . removeItem ( CUSTOM_THEMES_STORAGE_KEY ) ;
82+ invalidateCustomThemes ( ) ;
83+ } ,
84+ } ;
85+ installCustomTheme ( parseThemeFile ( theme ( "Dusk" ) ) ) ;
86+ const onOpenChange = vi . fn ( ) ;
87+ await using _screen = await render (
88+ < ThemeImportDialog
89+ open
90+ onOpenChange = { onOpenChange }
91+ onImported = { ( ) => true }
92+ onImportedMany = { ( ) => { } }
93+ /> ,
94+ ) ;
95+ const input = document . querySelector < HTMLInputElement > ( 'input[type="file"]' ) ! ;
96+ await userEvent . upload ( input , [
97+ themeFile ( "Dawn" ) ,
98+ themeFile ( "Dusk" , "#f97316" ) ,
99+ new File ( [ "{" ] , "broken.json" , { type : "application/json" } ) ,
100+ ] ) ;
101+
102+ await expect . element ( page . getByText ( "Already installed" ) ) . toBeVisible ( ) ;
103+ await expect . element ( page . getByText ( / ^ b r o k e n \. j s o n : / ) ) . toBeVisible ( ) ;
104+ expect ( getCustomThemes ( ) . map ( ( theme ) => theme . label ) ) . toContain ( "Dawn" ) ;
105+ await page . getByRole ( "button" , { name : choice } ) . click ( ) ;
106+ invalidateCustomThemes ( ) ;
107+ const label = choice === "Update existing" ? "Dusk" : "Dusk (1)" ;
108+ expect ( getCustomThemes ( ) . find ( ( theme ) => theme . label === label ) ?. colors ) . toEqual (
109+ parseThemeFile ( theme ( "Dusk" , "#f97316" ) ) . colors ,
110+ ) ;
111+ await expect . element ( page . getByText ( / ^ b r o k e n \. j s o n : / ) ) . toBeVisible ( ) ;
112+ expect ( onOpenChange ) . not . toHaveBeenCalledWith ( false ) ;
113+ } ,
114+ ) ;
0 commit comments