@@ -40,14 +40,37 @@ describe('AddThemeDialog component', () => {
4040 ( { state : store } = window . app ) ;
4141 } ) ;
4242
43- // TODO(dsanders11): Update this test to be accurate
4443 it ( 'renders' , ( ) => {
4544 store . isThemeDialogShowing = true ;
4645 render ( < AddThemeDialog appState = { store } /> ) ;
4746
4847 expect ( screen . getByText ( 'Add theme' ) ) . toBeInTheDocument ( ) ;
4948 expect ( screen . getByText ( 'Add' ) ) . toBeInTheDocument ( ) ;
5049 expect ( screen . getByText ( 'Cancel' ) ) . toBeInTheDocument ( ) ;
50+ // Add button should be disabled when no file is selected
51+ expect ( screen . getByRole ( 'button' , { name : 'Add' } ) ) . toBeDisabled ( ) ;
52+ } ) ;
53+
54+ it ( 'renders with a file selected' , ( ) => {
55+ store . isThemeDialogShowing = true ;
56+ const { instance } = renderClassComponentWithInstanceRef ( AddThemeDialog , {
57+ appState : store ,
58+ } ) ;
59+
60+ act ( ( ) => {
61+ instance . setState ( {
62+ file : new FileMock (
63+ [ '{}' ] ,
64+ 'theme.json' ,
65+ '/test/theme.json' ,
66+ 'application/json' ,
67+ ) ,
68+ } ) ;
69+ } ) ;
70+
71+ // File name should be displayed and Add button should be enabled
72+ expect ( screen . getByText ( 'theme.json' ) ) . toBeInTheDocument ( ) ;
73+ expect ( screen . getByRole ( 'button' , { name : 'Add' } ) ) . not . toBeDisabled ( ) ;
5174 } ) ;
5275
5376 describe ( 'createNewThemeFromMonaco()' , ( ) => {
@@ -58,10 +81,7 @@ describe('AddThemeDialog component', () => {
5881 } ) ;
5982
6083 try {
61- await ( instance as any ) . createNewThemeFromMonaco (
62- '' ,
63- { } as LoadedFiddleTheme ,
64- ) ;
84+ await instance . createNewThemeFromMonaco ( '' , { } as LoadedFiddleTheme ) ;
6585 } catch ( err : any ) {
6686 expect ( err . message ) . toEqual ( `Filename not found` ) ;
6787 expect ( window . ElectronFiddle . createThemeFile ) . toHaveBeenCalledTimes ( 0 ) ;
@@ -76,7 +96,7 @@ describe('AddThemeDialog component', () => {
7696 } ) ;
7797
7898 act ( ( ) => {
79- ( instance as any ) . setState ( {
99+ instance . setState ( {
80100 file : new FileMock (
81101 [ JSON . stringify ( defaultLight . editor ) ] ,
82102 'file.json' ,
@@ -91,10 +111,7 @@ describe('AddThemeDialog component', () => {
91111 file : themePath ,
92112 } as LoadedFiddleTheme ) ;
93113
94- await ( instance as any ) . createNewThemeFromMonaco (
95- 'testingLight' ,
96- defaultLight ,
97- ) ;
114+ await instance . createNewThemeFromMonaco ( 'testingLight' , defaultLight ) ;
98115
99116 expect ( window . ElectronFiddle . createThemeFile ) . toHaveBeenCalledWith (
100117 expect . objectContaining ( {
@@ -115,15 +132,13 @@ describe('AddThemeDialog component', () => {
115132 appState : store ,
116133 } ) ;
117134
118- ( instance as any ) . createNewThemeFromMonaco = vi . fn ( ) ;
119- ( instance as any ) . onClose = vi . fn ( ) ;
135+ instance . createNewThemeFromMonaco = vi . fn ( ) ;
136+ instance . onClose = vi . fn ( ) ;
120137
121- await ( instance as any ) . onSubmit ( ) ;
138+ await instance . onSubmit ( ) ;
122139
123- expect ( ( instance as any ) . createNewThemeFromMonaco ) . toHaveBeenCalledTimes (
124- 0 ,
125- ) ;
126- expect ( ( instance as any ) . onClose ) . toHaveBeenCalledTimes ( 0 ) ;
140+ expect ( instance . createNewThemeFromMonaco ) . toHaveBeenCalledTimes ( 0 ) ;
141+ expect ( instance . onClose ) . toHaveBeenCalledTimes ( 0 ) ;
127142 } ) ;
128143
129144 it ( 'loads a theme if a file is currently set' , async ( ) => {
@@ -140,19 +155,17 @@ describe('AddThemeDialog component', () => {
140155 ) ;
141156 const spy = vi . spyOn ( file , 'text' ) ;
142157 act ( ( ) => {
143- ( instance as any ) . setState ( { file } ) ;
158+ instance . setState ( { file } ) ;
144159 } ) ;
145160
146- ( instance as any ) . createNewThemeFromMonaco = vi . fn ( ) ;
147- ( instance as any ) . onClose = vi . fn ( ) ;
161+ instance . createNewThemeFromMonaco = vi . fn ( ) ;
162+ instance . onClose = vi . fn ( ) ;
148163
149- await ( instance as any ) . onSubmit ( ) ;
164+ await instance . onSubmit ( ) ;
150165
151166 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
152- expect ( ( instance as any ) . createNewThemeFromMonaco ) . toHaveBeenCalledTimes (
153- 1 ,
154- ) ;
155- expect ( ( instance as any ) . onClose ) . toHaveBeenCalledTimes ( 1 ) ;
167+ expect ( instance . createNewThemeFromMonaco ) . toHaveBeenCalledTimes ( 1 ) ;
168+ expect ( instance . onClose ) . toHaveBeenCalledTimes ( 1 ) ;
156169 } ) ;
157170
158171 it ( 'shows an error dialog for a malformed theme' , async ( ) => {
@@ -170,12 +183,12 @@ describe('AddThemeDialog component', () => {
170183 ) ;
171184 const spy = vi . spyOn ( file , 'text' ) . mockResolvedValue ( '{}' ) ;
172185 act ( ( ) => {
173- ( instance as any ) . setState ( { file } ) ;
186+ instance . setState ( { file } ) ;
174187 } ) ;
175188
176- ( instance as any ) . onClose = vi . fn ( ) ;
189+ instance . onClose = vi . fn ( ) ;
177190
178- await ( instance as any ) . onSubmit ( ) ;
191+ await instance . onSubmit ( ) ;
179192
180193 expect ( spy ) . toHaveBeenCalledTimes ( 1 ) ;
181194 expect ( store . showErrorDialog ) . toHaveBeenCalledWith (
@@ -193,11 +206,11 @@ describe('AddThemeDialog component', () => {
193206
194207 const files = [ 'one' , 'two' ] ;
195208 act ( ( ) => {
196- ( instance as any ) . onChangeFile ( {
209+ instance . onChangeFile ( {
197210 target : { files } as unknown as EventTarget ,
198211 } as React . FormEvent < HTMLInputElement > ) ;
199212 } ) ;
200- expect ( ( instance as any ) . state . file ) . toBe ( files [ 0 ] ) ;
213+ expect ( instance . state . file ) . toBe ( files [ 0 ] ) ;
201214 } ) ;
202215
203216 it ( 'handles no input' , ( ) => {
@@ -206,12 +219,10 @@ describe('AddThemeDialog component', () => {
206219 appState : store ,
207220 } ) ;
208221
209- act ( ( ) => {
210- ( instance as any ) . onChangeFile ( {
211- target : { files : null } as unknown as EventTarget ,
212- } as React . FormEvent < HTMLInputElement > ) ;
213- } ) ;
214- expect ( ( instance as any ) . state . file ) . toBeUndefined ( ) ;
222+ instance . onChangeFile ( {
223+ target : { files : null } as unknown as EventTarget ,
224+ } as React . FormEvent < HTMLInputElement > ) ;
225+ expect ( instance . state . file ) . toBeUndefined ( ) ;
215226 } ) ;
216227 } ) ;
217228} ) ;
0 commit comments