11import { QuickPickItemKind } from 'vscode'
22import { pickPlotConfiguration } from './quickPick'
3+ import { getInput } from '../vscode/inputBox'
34import { pickFiles } from '../vscode/resourcePicker'
45import { quickPickOne , quickPickValue } from '../vscode/quickPick'
56import { getFileExtension , loadDataFiles } from '../fileSystem'
@@ -9,13 +10,15 @@ import { Toast } from '../vscode/toast'
910const mockedPickFiles = jest . mocked ( pickFiles )
1011const mockedLoadDataFiles = jest . mocked ( loadDataFiles )
1112const mockedGetFileExt = jest . mocked ( getFileExtension )
13+ const mockedGetInput = jest . mocked ( getInput )
1214const mockedQuickPickOne = jest . mocked ( quickPickOne )
1315const mockedQuickPickValue = jest . mocked ( quickPickValue )
1416const mockedToast = jest . mocked ( Toast )
1517const mockedShowError = jest . fn ( )
1618mockedToast . showError = mockedShowError
1719
1820jest . mock ( '../fileSystem' )
21+ jest . mock ( '../vscode/inputBox' )
1922jest . mock ( '../vscode/resourcePicker' )
2023jest . mock ( '../vscode/quickPick' )
2124
@@ -250,7 +253,7 @@ describe('pickPlotConfiguration', () => {
250253 expect ( mockedShowError ) . not . toHaveBeenCalled ( )
251254 } )
252255
253- it ( 'should let the user pick a template, x field, and y field' , async ( ) => {
256+ it ( 'should let the user pick a template, x field, y field and title ' , async ( ) => {
254257 mockedPickFiles . mockResolvedValueOnce ( [ '/file.json' ] )
255258 mockedLoadDataFiles . mockResolvedValueOnce ( [
256259 { data : mockValidData , file : '/file.json' }
@@ -259,6 +262,7 @@ describe('pickPlotConfiguration', () => {
259262 mockedQuickPickValue
260263 . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
261264 . mockResolvedValueOnce ( { file : 'file.json' , key : 'prob' } )
265+ mockedGetInput . mockResolvedValueOnce ( 'Simple Plot' )
262266
263267 const result = await pickPlotConfiguration ( '/' )
264268
@@ -304,8 +308,13 @@ describe('pickPlotConfiguration', () => {
304308 title : Title . SELECT_PLOT_Y_METRIC
305309 }
306310 )
311+ expect ( mockedGetInput ) . toHaveBeenCalledWith (
312+ Title . ENTER_PLOT_TITLE ,
313+ 'actual vs prob'
314+ )
307315 expect ( result ) . toStrictEqual ( {
308316 template : 'simple' ,
317+ title : 'Simple Plot' ,
309318 x : { file : 'file.json' , key : 'actual' } ,
310319 y : { file : 'file.json' , key : 'prob' }
311320 } )
@@ -318,6 +327,7 @@ describe('pickPlotConfiguration', () => {
318327 { data : mockValidData , file : '/file2.json' }
319328 ] )
320329 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
330+ mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
321331 mockedQuickPickValue
322332 . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
323333 . mockResolvedValueOnce ( { file : 'file2.json' , key : 'prob' } )
@@ -367,6 +377,7 @@ describe('pickPlotConfiguration', () => {
367377 )
368378 expect ( result ) . toStrictEqual ( {
369379 template : 'simple' ,
380+ title : 'simple_plot' ,
370381 x : { file : 'file.json' , key : 'actual' } ,
371382 y : { file : 'file2.json' , key : 'prob' }
372383 } )
@@ -392,6 +403,7 @@ describe('pickPlotConfiguration', () => {
392403 { data : mockValidData , file : 'file.json' }
393404 ] )
394405 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
406+ mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
395407 mockedQuickPickValue . mockResolvedValueOnce ( undefined )
396408
397409 const result = await pickPlotConfiguration ( '/' )
@@ -406,6 +418,7 @@ describe('pickPlotConfiguration', () => {
406418 { data : mockValidData , file : 'file.json' }
407419 ] )
408420 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
421+ mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
409422 mockedQuickPickValue
410423 . mockResolvedValueOnce ( 'actual' )
411424 . mockResolvedValueOnce ( undefined )
@@ -415,4 +428,21 @@ describe('pickPlotConfiguration', () => {
415428 expect ( mockedQuickPickValue ) . toHaveBeenCalledTimes ( 2 )
416429 expect ( result ) . toStrictEqual ( undefined )
417430 } )
431+
432+ it ( 'should return early if the user does not pick a title' , async ( ) => {
433+ mockedPickFiles . mockResolvedValueOnce ( [ '/file.json' ] )
434+ mockedLoadDataFiles . mockResolvedValueOnce ( [
435+ { data : mockValidData , file : 'file.json' }
436+ ] )
437+ mockedQuickPickOne . mockResolvedValueOnce ( 'linear' )
438+ mockedQuickPickValue
439+ . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
440+ . mockResolvedValueOnce ( { file : 'file.json' , key : 'prob' } )
441+ mockedGetInput . mockResolvedValueOnce ( undefined )
442+
443+ const result = await pickPlotConfiguration ( '/' )
444+
445+ expect ( mockedGetInput ) . toHaveBeenCalledTimes ( 1 )
446+ expect ( result ) . toStrictEqual ( undefined )
447+ } )
418448} )
0 commit comments