1
1
import { expect } from 'chai' ;
2
2
import {
3
3
createBoardList ,
4
+ EditBoardsConfigActionParams ,
4
5
isInferredBoardListItem ,
5
6
isMultiBoardsBoardListItem ,
6
7
SelectBoardsConfigActionParams ,
@@ -329,21 +330,19 @@ describe('board-list', () => {
329
330
} ) ;
330
331
331
332
describe ( 'defaultAction' , ( ) => {
332
- it ( "should be a 'select' default action for identifier boards" , ( ) => {
333
+ it ( "'select' should be the default action for identifier boards" , ( ) => {
333
334
const { items } = createBoardList ( {
334
335
...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
335
336
} ) ;
336
337
const item = items [ 0 ] ;
337
- expect ( item ) . to . be . not . undefined ;
338
338
expect ( item . defaultAction . type ) . to . be . equal ( 'select-boards-config' ) ;
339
- const params = < SelectBoardsConfigActionParams > (
340
- item . defaultAction . params
341
- ) ;
342
- expect ( params . selectedBoard ) . deep . equal ( mkr1000 ) ;
343
- expect ( params . selectedPort ) . deep . equal ( mkr1000SerialPort ) ;
339
+ expect ( item . defaultAction . params ) . to . be . deep . equal ( {
340
+ selectedPort : mkr1000SerialPort ,
341
+ selectedBoard : mkr1000 ,
342
+ } ) ;
344
343
} ) ;
345
344
346
- it ( "should be a 'select' default action for manually selected items (no discovered boards)" , ( ) => {
345
+ it ( "'select' should be the default action for manually selected items (no discovered boards)" , ( ) => {
347
346
const { items } = createBoardList (
348
347
{
349
348
...detectedPort ( undiscoveredSerialPort ) ,
@@ -354,16 +353,14 @@ describe('board-list', () => {
354
353
}
355
354
) ;
356
355
const item = items [ 0 ] ;
357
- expect ( item ) . to . be . not . undefined ;
358
356
expect ( item . defaultAction . type ) . to . be . equal ( 'select-boards-config' ) ;
359
- const params = < SelectBoardsConfigActionParams > (
360
- item . defaultAction . params
361
- ) ;
362
- expect ( params . selectedBoard ) . deep . equal ( uno ) ;
363
- expect ( params . selectedPort ) . deep . equal ( undiscoveredSerialPort ) ;
357
+ expect ( item . defaultAction . params ) . to . be . deep . equal ( {
358
+ selectedPort : undiscoveredSerialPort ,
359
+ selectedBoard : uno ,
360
+ } ) ;
364
361
} ) ;
365
362
366
- it ( "should be a 'select' default action for manually selected items (ambiguous boards)" , ( ) => {
363
+ it ( "'select' should be the default action for manually selected items (ambiguous boards)" , ( ) => {
367
364
const { items } = createBoardList (
368
365
{
369
366
...detectedPort (
@@ -378,13 +375,220 @@ describe('board-list', () => {
378
375
}
379
376
) ;
380
377
const item = items [ 0 ] ;
381
- expect ( item ) . to . be . not . undefined ;
382
378
expect ( item . defaultAction . type ) . to . be . equal ( 'select-boards-config' ) ;
383
- const params = < SelectBoardsConfigActionParams > (
384
- item . defaultAction . params
379
+ expect ( item . defaultAction . params ) . to . be . deep . equal ( {
380
+ selectedBoard : mkr1000 ,
381
+ selectedPort : nanoEsp32SerialPort ,
382
+ } ) ;
383
+ } ) ;
384
+
385
+ it ( "'edit' should be the default action for ports with no boards" , ( ) => {
386
+ const { items } = createBoardList ( {
387
+ ...detectedPort ( undiscoveredSerialPort ) ,
388
+ } ) ;
389
+ const item = items [ 0 ] ;
390
+ expect ( item ) . to . be . not . undefined ;
391
+ expect ( item . defaultAction . type ) . to . be . equal ( 'edit-boards-config' ) ;
392
+ const params = < EditBoardsConfigActionParams > item . defaultAction . params ;
393
+ const expectedParams : EditBoardsConfigActionParams = {
394
+ query : '' ,
395
+ portToSelect : undiscoveredSerialPort ,
396
+ } ;
397
+ expect ( params ) . to . be . deep . equal ( expectedParams ) ;
398
+ } ) ;
399
+
400
+ it ( "'edit' should be the default action for ports with multiple boards (unique board name)" , ( ) => {
401
+ const { items } = createBoardList ( {
402
+ ...detectedPort (
403
+ nanoEsp32SerialPort ,
404
+ arduinoNanoEsp32 ,
405
+ esp32NanoEsp32
406
+ ) ,
407
+ } ) ;
408
+ const item = items [ 0 ] ;
409
+ expect ( item ) . to . be . not . undefined ;
410
+ expect ( item . defaultAction . type ) . to . be . equal ( 'edit-boards-config' ) ;
411
+ const params = < EditBoardsConfigActionParams > item . defaultAction . params ;
412
+ const expectedParams : EditBoardsConfigActionParams = {
413
+ query : arduinoNanoEsp32 . name ,
414
+ portToSelect : nanoEsp32SerialPort ,
415
+ searchSet : [ arduinoNanoEsp32 , esp32NanoEsp32 ] ,
416
+ } ;
417
+ expect ( params ) . to . be . deep . equal ( expectedParams ) ;
418
+ } ) ;
419
+
420
+ it ( "'edit' should be the default action for ports with multiple boards (no unique board name)" , ( ) => {
421
+ const { items } = createBoardList ( {
422
+ ...detectedPort (
423
+ nanoEsp32DetectsMultipleEsp32BoardsSerialPort ,
424
+ esp32S3DevModule ,
425
+ esp32S3Box
426
+ ) ,
427
+ } ) ;
428
+ const item = items [ 0 ] ;
429
+ expect ( item ) . to . be . not . undefined ;
430
+ expect ( item . defaultAction . type ) . to . be . equal ( 'edit-boards-config' ) ;
431
+ const params = < EditBoardsConfigActionParams > item . defaultAction . params ;
432
+ const expectedParams : EditBoardsConfigActionParams = {
433
+ query : '' ,
434
+ portToSelect : nanoEsp32DetectsMultipleEsp32BoardsSerialPort ,
435
+ searchSet : [ esp32S3Box , esp32S3DevModule ] ,
436
+ } ;
437
+ expect ( params ) . to . be . deep . equal ( expectedParams ) ;
438
+ } ) ;
439
+ } ) ;
440
+
441
+ describe ( 'otherActions' , ( ) => {
442
+ it ( 'should provide no other actions for identified board' , ( ) => {
443
+ const { items } = createBoardList ( {
444
+ ...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
445
+ } ) ;
446
+ const item = items [ 0 ] ;
447
+ expect ( item . otherActions ) . to . be . empty ;
448
+ } ) ;
449
+
450
+ it ( 'should provide no other actions for identified board (when historical revision is self)' , ( ) => {
451
+ const { items } = createBoardList (
452
+ {
453
+ ...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
454
+ } ,
455
+ emptyBoardsConfig ( ) ,
456
+ {
457
+ ...history ( mkr1000SerialPort , mkr1000 ) ,
458
+ }
459
+ ) ;
460
+ const item = items [ 0 ] ;
461
+ expect ( item . otherActions ) . to . be . empty ;
462
+ } ) ;
463
+
464
+ it ( 'should provide no other actions for unknown boards' , ( ) => {
465
+ const { items } = createBoardList ( {
466
+ ...detectedPort ( undiscoveredSerialPort ) ,
467
+ } ) ;
468
+ const item = items [ 0 ] ;
469
+ expect ( item . otherActions ) . to . be . empty ;
470
+ } ) ;
471
+
472
+ it ( 'should provide no other actions for ambiguous boards' , ( ) => {
473
+ const { items } = createBoardList ( {
474
+ ...detectedPort (
475
+ nanoEsp32SerialPort ,
476
+ arduinoNanoEsp32 ,
477
+ esp32NanoEsp32
478
+ ) ,
479
+ } ) ;
480
+ const item = items [ 0 ] ;
481
+ expect ( item . otherActions ) . to . be . empty ;
482
+ } ) ;
483
+
484
+ it ( "should provide 'edit' action for unidentified items with manually selected board" , ( ) => {
485
+ const { items } = createBoardList (
486
+ {
487
+ ...detectedPort ( undiscoveredSerialPort ) ,
488
+ } ,
489
+ emptyBoardsConfig ( ) ,
490
+ {
491
+ ...history ( undiscoveredSerialPort , uno ) ,
492
+ }
493
+ ) ;
494
+ const item = items [ 0 ] ;
495
+ const expectedParams : EditBoardsConfigActionParams = {
496
+ query : uno . name ,
497
+ portToSelect : undiscoveredSerialPort ,
498
+ } ;
499
+ expect ( item . otherActions ) . to . be . deep . equal ( {
500
+ edit : {
501
+ params : expectedParams ,
502
+ type : 'edit-boards-config' ,
503
+ } ,
504
+ } ) ;
505
+ } ) ;
506
+
507
+ it ( "should provide 'edit' action for ambiguous items with manually selected board (unique board name)" , ( ) => {
508
+ const { items } = createBoardList (
509
+ {
510
+ ...detectedPort (
511
+ nanoEsp32SerialPort ,
512
+ esp32NanoEsp32 ,
513
+ arduinoNanoEsp32
514
+ ) ,
515
+ } ,
516
+ emptyBoardsConfig ( ) ,
517
+ {
518
+ ...history ( nanoEsp32SerialPort , arduinoNanoEsp32 ) ,
519
+ }
520
+ ) ;
521
+ const item = items [ 0 ] ;
522
+ const expectedParams : EditBoardsConfigActionParams = {
523
+ query : arduinoNanoEsp32 . name ,
524
+ portToSelect : nanoEsp32SerialPort ,
525
+ searchSet : [ arduinoNanoEsp32 , esp32NanoEsp32 ] ,
526
+ } ;
527
+ expect ( item . otherActions ) . to . be . deep . equal ( {
528
+ edit : {
529
+ params : expectedParams ,
530
+ type : 'edit-boards-config' ,
531
+ } ,
532
+ } ) ;
533
+ } ) ;
534
+
535
+ it ( "should provide 'edit' action for ambiguous items with manually selected board (no unique board name)" , ( ) => {
536
+ const { items } = createBoardList (
537
+ {
538
+ ...detectedPort (
539
+ nanoEsp32DetectsMultipleEsp32BoardsSerialPort ,
540
+ esp32S3Box ,
541
+ esp32S3DevModule
542
+ ) ,
543
+ } ,
544
+ emptyBoardsConfig ( ) ,
545
+ {
546
+ ...history ( nanoEsp32DetectsMultipleEsp32BoardsSerialPort , uno ) ,
547
+ }
385
548
) ;
386
- expect ( params . selectedBoard ) . deep . equal ( mkr1000 ) ;
387
- expect ( params . selectedPort ) . deep . equal ( nanoEsp32SerialPort ) ;
549
+ const item = items [ 0 ] ;
550
+ const expectedParams : EditBoardsConfigActionParams = {
551
+ query : '' ,
552
+ portToSelect : nanoEsp32DetectsMultipleEsp32BoardsSerialPort ,
553
+ searchSet : [ esp32S3Box , esp32S3DevModule ] ,
554
+ } ;
555
+ expect ( item . otherActions ) . to . be . deep . equal ( {
556
+ edit : {
557
+ params : expectedParams ,
558
+ type : 'edit-boards-config' ,
559
+ } ,
560
+ } ) ;
561
+ } ) ;
562
+
563
+ it ( "should provide 'edit' and 'revert' actions for identified items with a manually overridden board" , ( ) => {
564
+ const { items } = createBoardList (
565
+ {
566
+ ...detectedPort ( mkr1000SerialPort , mkr1000 ) ,
567
+ } ,
568
+ emptyBoardsConfig ( ) ,
569
+ {
570
+ ...history ( mkr1000SerialPort , uno ) ,
571
+ }
572
+ ) ;
573
+ const item = items [ 0 ] ;
574
+ const expectedEditParams : EditBoardsConfigActionParams = {
575
+ query : uno . name ,
576
+ portToSelect : mkr1000SerialPort ,
577
+ } ;
578
+ const expectedRevertParams : SelectBoardsConfigActionParams = {
579
+ selectedBoard : mkr1000 ,
580
+ selectedPort : item . port ,
581
+ } ;
582
+ expect ( item . otherActions ) . to . be . deep . equal ( {
583
+ edit : {
584
+ params : expectedEditParams ,
585
+ type : 'edit-boards-config' ,
586
+ } ,
587
+ revert : {
588
+ params : expectedRevertParams ,
589
+ type : 'select-boards-config' ,
590
+ } ,
591
+ } ) ;
388
592
} ) ;
389
593
} ) ;
390
594
} ) ;
0 commit comments