@@ -2,7 +2,11 @@ import { QuickPickItemKind } from 'vscode'
22import { pickPlotConfiguration } from './quickPick'
33import { getInput } from '../vscode/inputBox'
44import { pickFiles } from '../vscode/resourcePicker'
5- import { quickPickOne , quickPickValue } from '../vscode/quickPick'
5+ import {
6+ quickPickOne ,
7+ quickPickValue ,
8+ quickPickManyValues
9+ } from '../vscode/quickPick'
610import { getFileExtension , loadDataFiles } from '../fileSystem'
711import { Title } from '../vscode/title'
812import { Toast } from '../vscode/toast'
@@ -13,6 +17,7 @@ const mockedGetFileExt = jest.mocked(getFileExtension)
1317const mockedGetInput = jest . mocked ( getInput )
1418const mockedQuickPickOne = jest . mocked ( quickPickOne )
1519const mockedQuickPickValue = jest . mocked ( quickPickValue )
20+ const mockedQuickPickValues = jest . mocked ( quickPickManyValues )
1621const mockedToast = jest . mocked ( Toast )
1722const mockedShowError = jest . fn ( )
1823mockedToast . showError = mockedShowError
@@ -259,9 +264,13 @@ describe('pickPlotConfiguration', () => {
259264 { data : mockValidData , file : '/file.json' }
260265 ] )
261266 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
262- mockedQuickPickValue
263- . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
264- . mockResolvedValueOnce ( { file : 'file.json' , key : 'prob' } )
267+ mockedQuickPickValue . mockResolvedValueOnce ( {
268+ file : 'file.json' ,
269+ key : 'actual'
270+ } )
271+ mockedQuickPickValues . mockResolvedValueOnce ( [
272+ { file : 'file.json' , key : 'prob' }
273+ ] )
265274 mockedGetInput . mockResolvedValueOnce ( 'Simple Plot' )
266275
267276 const result = await pickPlotConfiguration ( '/' )
@@ -281,8 +290,7 @@ describe('pickPlotConfiguration', () => {
281290 ] ,
282291 'Pick a Plot Template'
283292 )
284- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
285- 1 ,
293+ expect ( mockedQuickPickValue ) . toHaveBeenCalledWith (
286294 [
287295 {
288296 kind : QuickPickItemKind . Separator ,
@@ -294,8 +302,7 @@ describe('pickPlotConfiguration', () => {
294302 ] ,
295303 { title : Title . SELECT_PLOT_X_METRIC }
296304 )
297- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
298- 2 ,
305+ expect ( mockedQuickPickValues ) . toHaveBeenCalledWith (
299306 [
300307 {
301308 kind : QuickPickItemKind . Separator ,
@@ -315,27 +322,33 @@ describe('pickPlotConfiguration', () => {
315322 expect ( result ) . toStrictEqual ( {
316323 template : 'simple' ,
317324 title : 'Simple Plot' ,
318- x : { file : 'file.json' , key : 'actual' } ,
319- y : { file : 'file.json' , key : 'prob' }
325+ x : { 'file.json' : 'actual' } ,
326+ y : { 'file.json' : 'prob' }
320327 } )
321328 } )
322329
323330 it ( 'should let the user pick a x field and y field from multiple files' , async ( ) => {
324331 mockedPickFiles . mockResolvedValueOnce ( [ '/file.json' , '/file2.json' ] )
325332 mockedLoadDataFiles . mockResolvedValueOnce ( [
326333 { data : mockValidData , file : '/file.json' } ,
327- { data : mockValidData , file : '/file2.json' }
334+ {
335+ data : mockValidData ,
336+ file : '/file2.json'
337+ }
328338 ] )
329339 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
330340 mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
331- mockedQuickPickValue
332- . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
333- . mockResolvedValueOnce ( { file : 'file2.json' , key : 'prob' } )
341+ mockedQuickPickValue . mockResolvedValueOnce ( {
342+ file : 'file.json' ,
343+ key : 'actual'
344+ } )
345+ mockedQuickPickValues . mockResolvedValueOnce ( [
346+ { file : 'file2.json' , key : 'prob' }
347+ ] )
334348
335349 const result = await pickPlotConfiguration ( '/' )
336350
337- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
338- 1 ,
351+ expect ( mockedQuickPickValue ) . toHaveBeenCalledWith (
339352 [
340353 {
341354 kind : QuickPickItemKind . Separator ,
@@ -354,8 +367,7 @@ describe('pickPlotConfiguration', () => {
354367 ] ,
355368 { title : Title . SELECT_PLOT_X_METRIC }
356369 )
357- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
358- 2 ,
370+ expect ( mockedQuickPickValues ) . toHaveBeenCalledWith (
359371 [
360372 {
361373 kind : QuickPickItemKind . Separator ,
@@ -378,8 +390,80 @@ describe('pickPlotConfiguration', () => {
378390 expect ( result ) . toStrictEqual ( {
379391 template : 'simple' ,
380392 title : 'simple_plot' ,
381- x : { file : 'file.json' , key : 'actual' } ,
382- y : { file : 'file2.json' , key : 'prob' }
393+ x : { 'file.json' : 'actual' } ,
394+ y : { 'file2.json' : 'prob' }
395+ } )
396+ } )
397+
398+ it ( 'should let the user pick multiple y fields' , async ( ) => {
399+ mockedPickFiles . mockResolvedValueOnce ( [ '/file.json' , '/file2.json' ] )
400+ mockedLoadDataFiles . mockResolvedValueOnce ( [
401+ { data : mockValidData , file : '/file.json' } ,
402+ {
403+ data : mockValidData . map ( ( value , ind ) => ( { ...value , step : ind } ) ) ,
404+ file : '/file2.json'
405+ }
406+ ] )
407+ mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
408+ mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
409+ mockedQuickPickValue . mockResolvedValueOnce ( {
410+ file : 'file.json' ,
411+ key : 'actual'
412+ } )
413+ mockedQuickPickValues . mockResolvedValueOnce ( [
414+ { file : 'file2.json' , key : 'prob' } ,
415+ { file : 'file2.json' , key : 'actual' } ,
416+ { file : 'file2.json' , key : 'step' }
417+ ] )
418+
419+ const result = await pickPlotConfiguration ( '/' )
420+
421+ expect ( mockedQuickPickValue ) . toHaveBeenCalledWith (
422+ [
423+ {
424+ kind : QuickPickItemKind . Separator ,
425+ label : 'file.json' ,
426+ value : undefined
427+ } ,
428+ { label : 'actual' , value : { file : 'file.json' , key : 'actual' } } ,
429+ { label : 'prob' , value : { file : 'file.json' , key : 'prob' } } ,
430+ {
431+ kind : QuickPickItemKind . Separator ,
432+ label : 'file2.json' ,
433+ value : undefined
434+ } ,
435+ { label : 'actual' , value : { file : 'file2.json' , key : 'actual' } } ,
436+ { label : 'prob' , value : { file : 'file2.json' , key : 'prob' } } ,
437+ { label : 'step' , value : { file : 'file2.json' , key : 'step' } }
438+ ] ,
439+ { title : Title . SELECT_PLOT_X_METRIC }
440+ )
441+ expect ( mockedQuickPickValues ) . toHaveBeenCalledWith (
442+ [
443+ {
444+ kind : QuickPickItemKind . Separator ,
445+ label : 'file.json' ,
446+ value : undefined
447+ } ,
448+ { label : 'prob' , value : { file : 'file.json' , key : 'prob' } } ,
449+ {
450+ kind : QuickPickItemKind . Separator ,
451+ label : 'file2.json' ,
452+ value : undefined
453+ } ,
454+ { label : 'actual' , value : { file : 'file2.json' , key : 'actual' } } ,
455+ { label : 'prob' , value : { file : 'file2.json' , key : 'prob' } } ,
456+ { label : 'step' , value : { file : 'file2.json' , key : 'step' } }
457+ ] ,
458+ {
459+ title : Title . SELECT_PLOT_Y_METRIC
460+ }
461+ )
462+ expect ( result ) . toStrictEqual ( {
463+ template : 'simple' ,
464+ title : 'simple_plot' ,
465+ x : { 'file.json' : 'actual' } ,
466+ y : { 'file2.json' : [ 'prob' , 'actual' , 'step' ] }
383467 } )
384468 } )
385469
@@ -419,13 +503,12 @@ describe('pickPlotConfiguration', () => {
419503 ] )
420504 mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
421505 mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
422- mockedQuickPickValue
423- . mockResolvedValueOnce ( 'actual' )
424- . mockResolvedValueOnce ( undefined )
506+ mockedQuickPickValue . mockResolvedValueOnce ( 'actual' )
507+ mockedQuickPickValues . mockResolvedValueOnce ( undefined )
425508
426509 const result = await pickPlotConfiguration ( '/' )
427510
428- expect ( mockedQuickPickValue ) . toHaveBeenCalledTimes ( 2 )
511+ expect ( mockedQuickPickValues ) . toHaveBeenCalledTimes ( 1 )
429512 expect ( result ) . toStrictEqual ( undefined )
430513 } )
431514
@@ -435,9 +518,16 @@ describe('pickPlotConfiguration', () => {
435518 { data : mockValidData , file : 'file.json' }
436519 ] )
437520 mockedQuickPickOne . mockResolvedValueOnce ( 'linear' )
438- mockedQuickPickValue
439- . mockResolvedValueOnce ( { file : 'file.json' , key : 'actual' } )
440- . mockResolvedValueOnce ( { file : 'file.json' , key : 'prob' } )
521+ mockedQuickPickValue . mockResolvedValueOnce ( {
522+ file : 'file.json' ,
523+ key : 'actual'
524+ } )
525+ mockedQuickPickValues . mockResolvedValueOnce ( [
526+ {
527+ file : 'file.json' ,
528+ key : 'prob'
529+ }
530+ ] )
441531 mockedGetInput . mockResolvedValueOnce ( undefined )
442532
443533 const result = await pickPlotConfiguration ( '/' )
0 commit comments