@@ -274,6 +274,72 @@ describe('GitPanel', () => {
274
274
expect ( commitSpy ) . toHaveBeenCalledWith ( commitSummary , false , null ) ;
275
275
} ) ;
276
276
277
+ it ( 'should prompt for user identity if user.name is not set when pathRepository is empty string' , async ( ) => {
278
+ props . model . pathRepository = '' ;
279
+ renderResult . rerender ( < GitPanel { ...props } /> ) ;
280
+
281
+ configSpy . mockImplementation ( mockConfigImplementation ( 'user.email' ) ) ;
282
+ mockUtils . showDialog . mockResolvedValue ( dialogValue ) ;
283
+
284
+ await userEvent . type ( screen . getAllByRole ( 'textbox' ) [ 0 ] , commitSummary ) ;
285
+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Commit' } ) ) ;
286
+
287
+ await waitFor ( ( ) => {
288
+ expect ( configSpy ) . toHaveBeenCalledTimes ( 2 ) ;
289
+ } ) ;
290
+ expect ( configSpy . mock . calls [ 0 ] ) . toHaveLength ( 0 ) ;
291
+ expect ( configSpy . mock . calls [ 1 ] ) . toEqual ( [ commitUser ] ) ;
292
+ expect ( commitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
293
+ expect ( commitSpy ) . toHaveBeenCalledWith ( commitSummary , false , null ) ;
294
+ } ) ;
295
+
296
+ it ( 'should prompt for user identity if user.email is not set when pathRepository is empty string' , async ( ) => {
297
+ props . model . pathRepository = '' ;
298
+ renderResult . rerender ( < GitPanel { ...props } /> ) ;
299
+ configSpy . mockImplementation ( mockConfigImplementation ( 'user.name' ) ) ;
300
+ mockUtils . showDialog . mockResolvedValue ( dialogValue ) ;
301
+
302
+ await userEvent . type ( screen . getAllByRole ( 'textbox' ) [ 0 ] , commitSummary ) ;
303
+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Commit' } ) ) ;
304
+
305
+ await waitFor ( ( ) => {
306
+ expect ( configSpy ) . toHaveBeenCalledTimes ( 2 ) ;
307
+ } ) ;
308
+ expect ( configSpy . mock . calls [ 0 ] ) . toHaveLength ( 0 ) ;
309
+ expect ( configSpy . mock . calls [ 1 ] ) . toEqual ( [ commitUser ] ) ;
310
+ expect ( commitSpy ) . toHaveBeenCalledTimes ( 1 ) ;
311
+ expect ( commitSpy ) . toHaveBeenCalledWith ( commitSummary , false , null ) ;
312
+ } ) ;
313
+
314
+ it ( 'should not commit if no user identity is set and the user rejects the dialog when pathRepository is empty string' , async ( ) => {
315
+ props . model . pathRepository = '' ;
316
+ renderResult . rerender ( < GitPanel { ...props } /> ) ;
317
+ configSpy . mockResolvedValue ( { options : { } } ) ;
318
+ mockUtils . showDialog . mockResolvedValue ( {
319
+ button : {
320
+ ...dialogValue . button ,
321
+ accept : false
322
+ } ,
323
+ isChecked : null ,
324
+ value : null
325
+ } ) ;
326
+
327
+ await userEvent . type ( screen . getAllByRole ( 'textbox' ) [ 0 ] , commitSummary ) ;
328
+ await userEvent . type (
329
+ screen . getAllByRole ( 'textbox' ) [ 1 ] ,
330
+ commitDescription
331
+ ) ;
332
+ await userEvent . click ( screen . getByRole ( 'button' , { name : 'Commit' } ) ) ;
333
+
334
+ await waitFor ( ( ) => expect ( configSpy ) . toHaveBeenCalledTimes ( 1 ) ) ;
335
+ expect ( configSpy ) . toHaveBeenCalledWith ( ) ;
336
+ expect ( commitSpy ) . not . toHaveBeenCalled ( ) ;
337
+
338
+ // Should not erase commit message
339
+ expect ( screen . getAllByRole ( 'textbox' ) [ 0 ] ) . toHaveValue ( commitSummary ) ;
340
+ expect ( screen . getAllByRole ( 'textbox' ) [ 1 ] ) . toHaveValue ( commitDescription ) ;
341
+ } ) ;
342
+
277
343
it ( 'should not commit if no user identity is set and the user rejects the dialog' , async ( ) => {
278
344
configSpy . mockResolvedValue ( { options : { } } ) ;
279
345
mockUtils . showDialog . mockResolvedValue ( {
0 commit comments