@@ -534,31 +534,77 @@ suite('Experiments Test Suite', () => {
534534 } ) . timeout ( WEBVIEW_TEST_TIMEOUT )
535535
536536 it ( 'should be able to handle a message to create a branch from an experiment' , async ( ) => {
537- const { mockMessageReceived } =
538- await stubWorkspaceGettersWebview ( disposable )
539-
540- const mockBranch = 'mock-branch-input'
541- const inputEvent = getInputBoxEvent ( mockBranch )
537+ const {
538+ mockMessageReceived ,
539+ experimentsModel ,
540+ mockUpdateExperimentsData
541+ } = await stubWorkspaceGettersWebview ( disposable )
542542
543- const mockExperimentBranch = stub (
544- DvcExecutor . prototype ,
545- 'expBranch'
546- ) . resolves ( 'undefined' )
543+ stub ( Setup . prototype , 'getCliVersion' ) . resolves ( '3.22.0' )
547544
548545 const mockExperimentId = 'exp-e7a67'
546+ const mockBranch = 'mock-branch-input'
547+ const mockExperimentBranch = stub ( DvcExecutor . prototype , 'expBranch' )
548+ const mockSetSelectedBranches = stub (
549+ experimentsModel ,
550+ 'setSelectedBranches'
551+ )
552+ stub ( window , 'showInputBox' ) . resolves ( mockBranch )
553+
554+ const failedExperimentBranchEvent = new Promise ( resolve =>
555+ mockExperimentBranch . onFirstCall ( ) . callsFake ( ( ) => {
556+ resolve ( undefined )
557+ return Promise . resolve ( '' )
558+ } )
559+ )
549560
550561 mockMessageReceived . fire ( {
551562 payload : mockExperimentId ,
552563 type : MessageFromWebviewType . CREATE_BRANCH_FROM_EXPERIMENT
553564 } )
554565
555- await inputEvent
566+ await failedExperimentBranchEvent
567+
556568 expect ( mockExperimentBranch ) . to . be . calledOnce
557569 expect ( mockExperimentBranch ) . to . be . calledWithExactly (
558570 dvcDemoPath ,
559571 mockExperimentId ,
560572 mockBranch
561573 )
574+ expect ( mockSetSelectedBranches ) . not . to . be . called
575+ expect ( mockUpdateExperimentsData ) . not . to . be . called
576+
577+ const selectedBranches = [ 'main' , 'other' ]
578+ const selectedBranchesWithNewBranch = [
579+ 'main' ,
580+ 'mock-branch-input' ,
581+ 'other'
582+ ]
583+ mockExperimentBranch . onSecondCall ( ) . resolves ( 'branch created' )
584+ stub ( experimentsModel , 'getSelectedBranches' )
585+ . onFirstCall ( )
586+ . returns ( selectedBranches )
587+ const waitForBranchesToBeSelected = new Promise ( resolve =>
588+ mockSetSelectedBranches . callsFake ( ( ) => resolve ( undefined ) )
589+ )
590+
591+ mockMessageReceived . fire ( {
592+ payload : mockExperimentId ,
593+ type : MessageFromWebviewType . CREATE_BRANCH_FROM_EXPERIMENT
594+ } )
595+
596+ await waitForBranchesToBeSelected
597+
598+ expect ( mockExperimentBranch ) . to . be . calledTwice
599+ expect ( mockExperimentBranch ) . to . be . calledWithExactly (
600+ dvcDemoPath ,
601+ mockExperimentId ,
602+ mockBranch
603+ )
604+ expect ( mockSetSelectedBranches ) . to . be . calledWithExactly (
605+ selectedBranchesWithNewBranch
606+ )
607+ expect ( mockUpdateExperimentsData ) . to . be . calledOnce
562608 } ) . timeout ( WEBVIEW_TEST_TIMEOUT )
563609
564610 it ( 'should be able to handle a message to rename an experiment' , async ( ) => {
0 commit comments