@@ -8,6 +8,8 @@ import { EXPERIMENT_WORKSPACE_ID } from '../../cli/dvc/contract'
88import { ErrorsModel } from '../errors/model'
99import { REVISIONS } from '../../test/fixtures/plotsDiff'
1010import { SpecWithTitles } from '../vega/util'
11+ import { PersistenceKey } from '../../persistence/constants'
12+ import { Status } from '../../path/selection/model'
1113
1214describe ( 'PathsModel' , ( ) => {
1315 const mockDvcRoot = 'test'
@@ -502,4 +504,75 @@ describe('PathsModel', () => {
502504
503505 expect ( model . getTerminalNodes ( ) ) . toStrictEqual ( [ ] )
504506 } )
507+
508+ it ( 'should not change hasCustomSelection when checking for if it is already defined' , ( ) => {
509+ const memento = buildMockMemento ( {
510+ [ PersistenceKey . PLOTS_HAS_CUSTOM_SELECTION + mockDvcRoot ] : true
511+ } )
512+ const model = new PathsModel ( mockDvcRoot , buildMockErrorsModel ( ) , memento )
513+ const setHasCustomSelectionSpy = jest . spyOn ( model , 'setHasCustomSelection' )
514+
515+ model . checkIfHasPreviousCustomSelection ( )
516+ expect ( setHasCustomSelectionSpy ) . not . toHaveBeenCalled ( )
517+ } )
518+
519+ it ( 'should set hasCustomSelection to false if there are less than 20 plots' , ( ) => {
520+ const model = new PathsModel (
521+ mockDvcRoot ,
522+ buildMockErrorsModel ( ) ,
523+ buildMockMemento ( )
524+ )
525+ const setHasCustomSelectionSpy = jest . spyOn ( model , 'setHasCustomSelection' )
526+ jest
527+ . spyOn ( model , 'getTerminalNodeStatuses' )
528+ . mockImplementation ( ( ) => [
529+ Status . SELECTED ,
530+ Status . SELECTED ,
531+ Status . SELECTED ,
532+ Status . SELECTED
533+ ] )
534+
535+ model . checkIfHasPreviousCustomSelection ( )
536+ expect ( setHasCustomSelectionSpy ) . toHaveBeenCalledWith ( false )
537+ } )
538+
539+ it ( 'should set hasCustomSelection to false if there are 20 selected plots' , ( ) => {
540+ const model = new PathsModel (
541+ mockDvcRoot ,
542+ buildMockErrorsModel ( ) ,
543+ buildMockMemento ( )
544+ )
545+ const setHasCustomSelectionSpy = jest . spyOn ( model , 'setHasCustomSelection' )
546+ const statuses = [ Status . UNSELECTED ]
547+ for ( let i = 0 ; i < 20 ; i ++ ) {
548+ statuses . push ( Status . SELECTED )
549+ }
550+ statuses . push ( Status . UNSELECTED )
551+ jest
552+ . spyOn ( model , 'getTerminalNodeStatuses' )
553+ . mockImplementation ( ( ) => statuses )
554+
555+ model . checkIfHasPreviousCustomSelection ( )
556+ expect ( setHasCustomSelectionSpy ) . toHaveBeenCalledWith ( false )
557+ } )
558+
559+ it ( 'should set hasCustomSelection to true if there are more than 20 plots and the number of selected plots is not 20' , ( ) => {
560+ const model = new PathsModel (
561+ mockDvcRoot ,
562+ buildMockErrorsModel ( ) ,
563+ buildMockMemento ( )
564+ )
565+ const setHasCustomSelectionSpy = jest . spyOn ( model , 'setHasCustomSelection' )
566+ const statuses = [ Status . UNSELECTED ]
567+ for ( let i = 0 ; i < 19 ; i ++ ) {
568+ statuses . push ( Status . SELECTED )
569+ }
570+ statuses . push ( Status . UNSELECTED )
571+ jest
572+ . spyOn ( model , 'getTerminalNodeStatuses' )
573+ . mockImplementation ( ( ) => statuses )
574+
575+ model . checkIfHasPreviousCustomSelection ( )
576+ expect ( setHasCustomSelectionSpy ) . toHaveBeenCalledWith ( true )
577+ } )
505578} )
0 commit comments