@@ -3,6 +3,7 @@ import * as vet from 'vscode-extension-tester'
33import * as path from 'path'
44import * as PollingUtils from '../utils/PollingUtils'
55import { TerminalTester } from './TerminalTester'
6+ import { DebuggerTester } from './DebuggerTester'
67
78/**
89 * VSCodeTester
@@ -13,11 +14,52 @@ export class VSCodeTester {
1314 private readonly workbench : vet . Workbench
1415 private readonly statusbar : vet . StatusBar
1516 public terminal ! : TerminalTester
17+ public debugger ! : DebuggerTester
1618
1719 public constructor ( ) {
1820 this . browser = vet . VSBrowser . instance
1921 this . workbench = new vet . Workbench ( )
2022 this . statusbar = new vet . StatusBar ( )
23+ this . debugger = new DebuggerTester ( this . workbench )
24+ }
25+
26+ /**
27+ * Connects to MATLAB
28+ */
29+ public async connectToMATLAB ( ) : Promise < void > {
30+ const prompt = await this . workbench . openCommandPrompt ( ) as vet . InputBox ;
31+ await prompt . setText ( '>matlab.changeMatlabConnection' )
32+ await this . selectQuickPick ( prompt , 'MATLAB: Change MATLAB Connection' )
33+ await this . selectQuickPick ( prompt , 'Connect to MATLAB' )
34+ return await this . assertMATLABConnected ( )
35+ }
36+
37+ /**
38+ * Disconnects MATLAB
39+ */
40+ public async disconnectFromMATLAB ( ) : Promise < void > {
41+ const prompt = await this . workbench . openCommandPrompt ( ) as vet . InputBox ;
42+ await prompt . setText ( '>matlab.changeMatlabConnection' ) ;
43+ await this . selectQuickPick ( prompt , 'MATLAB: Change MATLAB Connection' )
44+ await this . selectQuickPick ( prompt , 'Disconnect from MATLAB' )
45+ return await this . assertMATLABDisconnected ( )
46+ }
47+
48+ /**
49+ * check for quickpick to contain a label
50+ */
51+ private async checkForQuickPick ( prompt : vet . InputBox , label : string ) : Promise < boolean > {
52+ const quickPicks = await prompt . getQuickPicks ( )
53+ const labels = await Promise . all ( quickPicks . map ( item => item . getLabel ( ) ) ) ;
54+ return labels . includes ( label ) ;
55+ }
56+
57+ /**
58+ * wait for quickpick to contain a label
59+ */
60+ public async selectQuickPick ( prompt : vet . InputBox , label : string ) : Promise < void > {
61+ await PollingUtils . poll ( this . checkForQuickPick . bind ( this , prompt , label ) , true , `Expected quickpick to contain ${ label } ` , 5000 )
62+ return await prompt . selectQuickPick ( label ) ;
2163 }
2264
2365 /**
@@ -26,7 +68,7 @@ export class VSCodeTester {
2668 private async getConnectionStatus ( ) : Promise < string > {
2769 const statusItem = await this . statusbar . findElements ( vet . By . xpath ( '//*[@id="MathWorks.language-matlab"]' ) )
2870 const status = await statusItem [ 0 ] ?. getAttribute ( 'aria-label' )
29- return status ;
71+ return status
3072 }
3173
3274 /**
@@ -40,70 +82,69 @@ export class VSCodeTester {
4082 * Poll for MATLAB to disconnect from VSCode
4183 */
4284 public async assertMATLABDisconnected ( ) : Promise < void > {
43- return await PollingUtils . poll ( this . getConnectionStatus . bind ( this ) , 'MATLAB: Not Connected' , 'Expected MATLAB to be disonnected' )
85+ return await PollingUtils . poll ( this . getConnectionStatus . bind ( this ) , 'MATLAB: Not Connected' , 'Expected MATLAB to be disconnected' )
86+ }
87+
88+ /**
89+ * Return the path to 'test-files' directory
90+ */
91+ public getTestFilesDirectory ( ) : string {
92+ return path . resolve ( __dirname , '..' , '..' , 'test-files' )
4493 }
4594
4695 /**
4796 * Open a file from the 'test-files' directory
4897 */
49- public async openDocument ( filename : string ) : Promise < void > {
50- const filepath = path . resolve ( __dirname , '..' , '..' , 'test-files' , filename )
98+ public async openEditor ( filename : string ) : Promise < vet . TextEditor > {
99+ const filepath = path . resolve ( this . getTestFilesDirectory ( ) , filename )
51100 await this . browser . openResources ( filepath )
101+ return new vet . TextEditor ( )
52102 }
53103
54104 /**
55105 * Close the editor that is currently active
56106 */
57- public async closeActiveDocument ( ) : Promise < void > {
58- const editor = new vet . TextEditor ( ) ;
107+ public async closeActiveEditor ( ) : Promise < void > {
108+ const editor = new vet . TextEditor ( )
59109 if ( await editor . isDirty ( ) ) {
60- await new vet . EditorView ( ) . closeEditor ( await editor . getTitle ( ) ) ;
61- const dialog = new vet . ModalDialog ( ) ;
62- return await dialog . pushButton ( 'Don\'t Save' ) ;
110+ await new vet . EditorView ( ) . closeEditor ( await editor . getTitle ( ) )
111+ const dialog = new vet . ModalDialog ( )
112+ return await dialog . pushButton ( 'Don\'t Save' )
63113 }
64- return await new vet . EditorView ( ) . closeEditor ( await editor . getTitle ( ) ) ;
114+ return await new vet . EditorView ( ) . closeEditor ( await editor . getTitle ( ) )
65115 }
66116
67117 /**
68118 * Opens the MATLAB terminal and creates a new terminal tester
69119 */
70120 public async openMATLABTerminal ( ) : Promise < TerminalTester > {
71- const prompt = await this . workbench . openCommandPrompt ( )
121+ const prompt = await this . workbench . openCommandPrompt ( ) as vet . InputBox
72122 await prompt . setText ( '>matlab.openCommandWindow' )
73- await prompt . confirm ( )
74- const terminal = await new vet . BottomBarPanel ( ) . openTerminalView ( ) ;
123+ await this . selectQuickPick ( prompt , 'MATLAB: Open Command Window' ) ;
124+ await this . assertMATLABConnected ( )
125+ const terminal = await new vet . BottomBarPanel ( ) . openTerminalView ( )
75126 const terminalTester = new TerminalTester ( this . workbench , terminal )
76127 this . terminal = terminalTester
77128 return terminalTester
78129 }
79130
80- public async selectFromNotification ( label : string ) : Promise < void > {
81- await this . waitForNotifications ( )
82- const notifications = await this . workbench . getNotifications ( ) ;
83- const notification = notifications [ 0 ] ;
84- return await notification . takeAction ( label )
85- }
86-
87- public async clearNotifications ( ) : Promise < void > {
88- let notifications = await this . workbench . getNotifications ( ) ;
89- while ( notifications . length > 0 ) {
90- await notifications [ 0 ] . dismiss ( ) ;
91- notifications = await this . workbench . getNotifications ( ) ;
92- }
93- }
94-
95- private async waitForNotifications ( ) : Promise < void > {
96- await PollingUtils . poll ( this . doNotificationsExist . bind ( this ) , true )
97- }
98-
99- private async doNotificationsExist ( ) : Promise < boolean > {
100- const notifications = await this . workbench . getNotifications ( ) ;
101- return notifications . length > 0
102- }
103-
104131 public async runCurrentFile ( ) : Promise < void > {
105132 const prompt = await this . workbench . openCommandPrompt ( )
106133 await prompt . setText ( '>matlab.runFile' )
107134 return await prompt . confirm ( )
108135 }
136+
137+ public async setSetting ( id : string , value : string ) : Promise < void > {
138+ const editor = await this . workbench . openSettings ( ) ;
139+ const setting = await editor . findSettingByID ( id ) as vet . ComboSetting | vet . TextSetting ;
140+ await setting . setValue ( value )
141+ return await new vet . EditorView ( ) . closeEditor ( 'Settings' )
142+ }
143+
144+ public async setCheckBoxSetting ( id : string , value : boolean ) : Promise < void > {
145+ const editor = await this . workbench . openSettings ( ) ;
146+ const setting = await editor . findSettingByID ( id ) as vet . CheckboxSetting ;
147+ await setting . setValue ( value )
148+ return await new vet . EditorView ( ) . closeEditor ( 'Settings' )
149+ }
109150}
0 commit comments