@@ -2,7 +2,11 @@ import { QuickPickItemKind } from 'vscode'
2
2
import { pickPlotConfiguration } from './quickPick'
3
3
import { getInput } from '../vscode/inputBox'
4
4
import { pickFiles } from '../vscode/resourcePicker'
5
- import { quickPickOne , quickPickValue } from '../vscode/quickPick'
5
+ import {
6
+ quickPickOne ,
7
+ quickPickValue ,
8
+ quickPickManyValues
9
+ } from '../vscode/quickPick'
6
10
import { getFileExtension , loadDataFiles } from '../fileSystem'
7
11
import { Title } from '../vscode/title'
8
12
import { Toast } from '../vscode/toast'
@@ -13,6 +17,7 @@ const mockedGetFileExt = jest.mocked(getFileExtension)
13
17
const mockedGetInput = jest . mocked ( getInput )
14
18
const mockedQuickPickOne = jest . mocked ( quickPickOne )
15
19
const mockedQuickPickValue = jest . mocked ( quickPickValue )
20
+ const mockedQuickPickValues = jest . mocked ( quickPickManyValues )
16
21
const mockedToast = jest . mocked ( Toast )
17
22
const mockedShowError = jest . fn ( )
18
23
mockedToast . showError = mockedShowError
@@ -259,9 +264,13 @@ describe('pickPlotConfiguration', () => {
259
264
{ data : mockValidData , file : '/file.json' }
260
265
] )
261
266
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
+ ] )
265
274
mockedGetInput . mockResolvedValueOnce ( 'Simple Plot' )
266
275
267
276
const result = await pickPlotConfiguration ( '/' )
@@ -281,8 +290,7 @@ describe('pickPlotConfiguration', () => {
281
290
] ,
282
291
'Pick a Plot Template'
283
292
)
284
- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
285
- 1 ,
293
+ expect ( mockedQuickPickValue ) . toHaveBeenCalledWith (
286
294
[
287
295
{
288
296
kind : QuickPickItemKind . Separator ,
@@ -294,8 +302,7 @@ describe('pickPlotConfiguration', () => {
294
302
] ,
295
303
{ title : Title . SELECT_PLOT_X_METRIC }
296
304
)
297
- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
298
- 2 ,
305
+ expect ( mockedQuickPickValues ) . toHaveBeenCalledWith (
299
306
[
300
307
{
301
308
kind : QuickPickItemKind . Separator ,
@@ -315,27 +322,33 @@ describe('pickPlotConfiguration', () => {
315
322
expect ( result ) . toStrictEqual ( {
316
323
template : 'simple' ,
317
324
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' }
320
327
} )
321
328
} )
322
329
323
330
it ( 'should let the user pick a x field and y field from multiple files' , async ( ) => {
324
331
mockedPickFiles . mockResolvedValueOnce ( [ '/file.json' , '/file2.json' ] )
325
332
mockedLoadDataFiles . mockResolvedValueOnce ( [
326
333
{ data : mockValidData , file : '/file.json' } ,
327
- { data : mockValidData , file : '/file2.json' }
334
+ {
335
+ data : mockValidData ,
336
+ file : '/file2.json'
337
+ }
328
338
] )
329
339
mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
330
340
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
+ ] )
334
348
335
349
const result = await pickPlotConfiguration ( '/' )
336
350
337
- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
338
- 1 ,
351
+ expect ( mockedQuickPickValue ) . toHaveBeenCalledWith (
339
352
[
340
353
{
341
354
kind : QuickPickItemKind . Separator ,
@@ -354,8 +367,7 @@ describe('pickPlotConfiguration', () => {
354
367
] ,
355
368
{ title : Title . SELECT_PLOT_X_METRIC }
356
369
)
357
- expect ( mockedQuickPickValue ) . toHaveBeenNthCalledWith (
358
- 2 ,
370
+ expect ( mockedQuickPickValues ) . toHaveBeenCalledWith (
359
371
[
360
372
{
361
373
kind : QuickPickItemKind . Separator ,
@@ -378,8 +390,80 @@ describe('pickPlotConfiguration', () => {
378
390
expect ( result ) . toStrictEqual ( {
379
391
template : 'simple' ,
380
392
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' ] }
383
467
} )
384
468
} )
385
469
@@ -419,13 +503,12 @@ describe('pickPlotConfiguration', () => {
419
503
] )
420
504
mockedQuickPickOne . mockResolvedValueOnce ( 'simple' )
421
505
mockedGetInput . mockResolvedValueOnce ( 'simple_plot' )
422
- mockedQuickPickValue
423
- . mockResolvedValueOnce ( 'actual' )
424
- . mockResolvedValueOnce ( undefined )
506
+ mockedQuickPickValue . mockResolvedValueOnce ( 'actual' )
507
+ mockedQuickPickValues . mockResolvedValueOnce ( undefined )
425
508
426
509
const result = await pickPlotConfiguration ( '/' )
427
510
428
- expect ( mockedQuickPickValue ) . toHaveBeenCalledTimes ( 2 )
511
+ expect ( mockedQuickPickValues ) . toHaveBeenCalledTimes ( 1 )
429
512
expect ( result ) . toStrictEqual ( undefined )
430
513
} )
431
514
@@ -435,9 +518,16 @@ describe('pickPlotConfiguration', () => {
435
518
{ data : mockValidData , file : 'file.json' }
436
519
] )
437
520
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
+ ] )
441
531
mockedGetInput . mockResolvedValueOnce ( undefined )
442
532
443
533
const result = await pickPlotConfiguration ( '/' )
0 commit comments