11import { Key } from 'webdriverio'
22import { $$ , browser } from '@wdio/globals'
3- import { ViewControl } from 'wdio-vscode-service'
3+ import { ViewControl , Workbench } from 'wdio-vscode-service'
44import { PlotsWebview } from './pageObjects/plotsWebview.js'
55
66const findProgressBars = ( ) => $$ ( '.monaco-progress-container' )
@@ -17,8 +17,8 @@ export const dismissAllNotifications = async (): Promise<void> => {
1717 await browser . waitUntil ( async ( ) => {
1818 const workbench = await browser . getWorkbench ( )
1919 const notifications = await workbench . getNotifications ( )
20- for ( const n of notifications ) {
21- await n . dismiss ( )
20+ for ( const notification of notifications ) {
21+ await notification . dismiss ( )
2222 }
2323 const openNotifications = await workbench . getNotifications ( )
2424 return openNotifications . length === 0
@@ -35,6 +35,50 @@ const dvcIsWorking = async (): Promise<boolean> => {
3535 )
3636}
3737
38+ const notificationShown = async (
39+ workbench : Workbench ,
40+ message : string
41+ ) : Promise < boolean > => {
42+ const notifications = await workbench . getNotifications ( )
43+ return notifications . some (
44+ async notification => ( await notification . elem . getText ( ) ) === message
45+ )
46+ }
47+
48+ const runDeleteCommand = async (
49+ command : string ,
50+ nothingToDeleteMessage : string
51+ ) : Promise < void > => {
52+ const workbench = await browser . getWorkbench ( )
53+ const commandPalette = await workbench . executeCommand ( command )
54+
55+ let nothingToDelete = false
56+
57+ await browser . waitUntil ( async ( ) => {
58+ if ( await notificationShown ( workbench , nothingToDeleteMessage ) ) {
59+ nothingToDelete = true
60+ return true
61+ }
62+
63+ return commandPalette . elem . isDisplayed ( )
64+ } )
65+
66+ if ( nothingToDelete ) {
67+ return
68+ }
69+ await browser
70+ . action ( 'key' )
71+ . down ( Key . Shift )
72+ . down ( Key . Tab )
73+ . up ( Key . Tab )
74+ . up ( Key . Shift )
75+ . perform ( )
76+
77+ await browser . keys ( 'Space' )
78+
79+ return browser . keys ( 'Enter' )
80+ }
81+
3882export const waitForDvcToFinish = async ( timeout = 60000 ) : Promise < void > => {
3983 await browser . waitUntil ( async ( ) => ! ( await dvcIsWorking ( ) ) , {
4084 timeout
@@ -100,32 +144,12 @@ export const waitForViewContainerToLoad = async (): Promise<void> => {
100144 )
101145}
102146
103- export const deleteAllExistingExperiments = async ( ) => {
104- const workbench = await browser . getWorkbench ( )
105-
106- const deleteNonWorkspaceExperiments = await workbench . executeCommand (
107- 'DVC: Remove Experiment(s)'
147+ export const deleteAllExistingExperiments = ( ) : Promise < void > =>
148+ runDeleteCommand (
149+ 'DVC: Remove Experiment(s)' ,
150+ 'There are no experiments to select.'
108151 )
109152
110- try {
111- await browser . waitUntil ( ( ) =>
112- deleteNonWorkspaceExperiments . elem . isDisplayed ( )
113- )
114-
115- await browser
116- . action ( 'key' )
117- . down ( Key . Shift )
118- . down ( Key . Tab )
119- . up ( Key . Tab )
120- . up ( Key . Shift )
121- . perform ( )
122-
123- await browser . keys ( 'Space' )
124-
125- return browser . keys ( 'Enter' )
126- } catch { }
127- }
128-
129153export const runModifiedExperiment = async ( ) => {
130154 const workbench = await browser . getWorkbench ( )
131155 const options = await workbench . executeCommand (
@@ -142,7 +166,10 @@ export const runModifiedExperiment = async () => {
142166 . up ( Key . Enter )
143167 . pause ( 100 )
144168 . perform ( )
145- await browser . keys ( [ ...'0.005' , 'Enter' ] )
169+
170+ const nonCachedParam = `0.00${ Date . now ( ) } `
171+
172+ await browser . keys ( [ ...nonCachedParam , 'Enter' ] )
146173 return workbench . executeCommand ( 'DVC: Show Experiments' )
147174}
148175
@@ -161,16 +188,11 @@ export const createCustomPlot = async (): Promise<void> => {
161188 return browser . keys ( 'Enter' )
162189}
163190
164- export const deleteCustomPlot = async ( ) : Promise < void > => {
165- const workbench = await browser . getWorkbench ( )
166- const removeCustomPlot = await workbench . executeCommand (
167- 'DVC: Remove Custom Plot(s) '
191+ export const deleteCustomPlots = ( ) : Promise < void > =>
192+ runDeleteCommand (
193+ 'DVC: Remove Custom Plot(s)' ,
194+ 'There are no plots to remove. '
168195 )
169- await browser . waitUntil ( ( ) => removeCustomPlot . elem . isDisplayed ( ) )
170- await browser . keys ( 'ArrowDown' )
171- await browser . keys ( 'Space' )
172- return browser . keys ( 'Enter' )
173- }
174196
175197export const waitForAllPlotsToRender = (
176198 webview : PlotsWebview ,
@@ -193,11 +215,19 @@ export const expectAllPlotsToBeFilled = async (webview: PlotsWebview) => {
193215}
194216
195217export const findScmTreeItems = async ( ) => {
196- const workspace = await browser . getWorkbench ( )
197- const activityBar = workspace . getActivityBar ( )
218+ const workbench = await browser . getWorkbench ( )
219+ const activityBar = workbench . getActivityBar ( )
198220 const sourceControlIcon = await activityBar . getViewControl ( 'Source Control' )
199221
200222 await sourceControlIcon ?. openView ( )
201223
224+ const visibleItems = await findCurrentTreeItems ( )
225+
226+ await visibleItems [ visibleItems . length - 1 ] . click ( )
227+
228+ for ( let i = 0 ; i < 20 ; i ++ ) {
229+ await browser . keys ( 'ArrowDown' )
230+ }
231+
202232 return findCurrentTreeItems ( )
203233}
0 commit comments