11import { afterEach , beforeEach , describe , it , suite } from 'mocha'
22import { expect } from 'chai'
3- import { stub , restore , SinonStub , match } from 'sinon'
3+ import { stub , restore , SinonStub , match , spy } from 'sinon'
44import { window , commands , QuickPickItem , Uri } from 'vscode'
55import {
66 buildExperiments ,
@@ -19,7 +19,10 @@ import {
1919 mockDuration
2020} from '../util'
2121import { dvcDemoPath } from '../../util'
22- import { RegisteredCliCommands } from '../../../commands/external'
22+ import {
23+ RegisteredCliCommands ,
24+ RegisteredCommands
25+ } from '../../../commands/external'
2326import * as Telemetry from '../../../telemetry'
2427import { DvcRunner } from '../../../cli/dvc/runner'
2528import { Param } from '../../../experiments/model/modify/collect'
@@ -35,6 +38,8 @@ import { GitExecutor } from '../../../cli/git/executor'
3538import { EXPERIMENT_WORKSPACE_ID } from '../../../cli/dvc/contract'
3639import { formatDate } from '../../../util/date'
3740import { DvcReader } from '../../../cli/dvc/reader'
41+ import { Setup } from '../../../setup'
42+ import { WorkspaceExperiments } from '../../../experiments/workspace'
3843
3944suite ( 'Workspace Experiments Test Suite' , ( ) => {
4045 const disposable = getTimeSafeDisposer ( )
@@ -932,4 +937,52 @@ suite('Workspace Experiments Test Suite', () => {
932937 expect ( mockExperimentRemove ) . to . be . calledWith ( dvcDemoPath , '--queue' )
933938 } )
934939 } )
940+
941+ describe ( 'dvc.showExperiments' , ( ) => {
942+ it ( 'should show the setup if it should be shown' , async ( ) => {
943+ const executeCommandSpy = spy ( commands , 'executeCommand' )
944+
945+ stub ( Setup . prototype , 'shouldBeShown' ) . returns ( true )
946+
947+ await commands . executeCommand ( RegisteredCommands . EXPERIMENT_SHOW )
948+
949+ expect ( executeCommandSpy ) . to . have . been . calledWithMatch ( 'dvc.showSetup' )
950+ } )
951+
952+ it ( 'should not show the experiments webview if the setup should be shown' , async ( ) => {
953+ const showPlotsWebviewSpy = stub (
954+ WorkspaceExperiments . prototype ,
955+ 'showWebview'
956+ )
957+ stub ( Setup . prototype , 'shouldBeShown' ) . returns ( true )
958+
959+ await commands . executeCommand ( RegisteredCommands . EXPERIMENT_SHOW )
960+
961+ expect ( showPlotsWebviewSpy ) . not . to . be . called
962+ } )
963+
964+ it ( 'should not show the setup if it should not be shown' , async ( ) => {
965+ const executeCommandSpy = spy ( commands , 'executeCommand' )
966+
967+ stub ( WorkspaceExperiments . prototype , 'showWebview' ) . resolves ( )
968+
969+ stub ( Setup . prototype , 'shouldBeShown' ) . returns ( false )
970+
971+ await commands . executeCommand ( RegisteredCommands . EXPERIMENT_SHOW )
972+
973+ expect ( executeCommandSpy ) . not . to . be . calledWith ( 'dvc.showSetup' )
974+ } )
975+
976+ it ( 'should show the experiments webview if the setup should not be shown' , async ( ) => {
977+ const showPlotsWebviewSpy = stub (
978+ WorkspaceExperiments . prototype ,
979+ 'showWebview'
980+ ) . resolves ( )
981+ stub ( Setup . prototype , 'shouldBeShown' ) . returns ( false )
982+
983+ await commands . executeCommand ( RegisteredCommands . EXPERIMENT_SHOW )
984+
985+ expect ( showPlotsWebviewSpy ) . to . be . called
986+ } )
987+ } )
935988} )
0 commit comments