@@ -9,6 +9,7 @@ import * as path from 'path';
9
9
import * as TypeMoq from 'typemoq' ;
10
10
import { Disposable , Selection , TextDocument , TextEditor , Uri } from 'vscode' ;
11
11
12
+ import { ReactWrapper } from 'enzyme' ;
12
13
import { IApplicationShell , IDocumentManager } from '../../client/common/application/types' ;
13
14
import { IDataScienceSettings } from '../../client/common/types' ;
14
15
import { createDeferred , waitForPromise } from '../../client/common/utils/async' ;
@@ -19,7 +20,9 @@ import { InteractiveWindowMessages } from '../../client/datascience/interactive-
19
20
import { InteractiveWindow } from '../../client/datascience/interactive-window/interactiveWindow' ;
20
21
import { concatMultilineStringInput } from '../../datascience-ui/common' ;
21
22
import { InteractivePanel } from '../../datascience-ui/history-react/interactivePanel' ;
23
+ import { IKeyboardEvent } from '../../datascience-ui/react-common/event' ;
22
24
import { ImageButton } from '../../datascience-ui/react-common/imageButton' ;
25
+ import { MonacoEditor } from '../../datascience-ui/react-common/monacoEditor' ;
23
26
import { DataScienceIocContainer } from './dataScienceIocContainer' ;
24
27
import { createDocument } from './editor-integration/helpers' ;
25
28
import { defaultDataScienceSettings } from './helpers' ;
@@ -38,6 +41,7 @@ import {
38
41
addMockData ,
39
42
CellInputState ,
40
43
CellPosition ,
44
+ enterEditorKey ,
41
45
enterInput ,
42
46
escapePath ,
43
47
findButton ,
@@ -87,6 +91,13 @@ suite('DataScience Interactive Window output tests', () => {
87
91
return update ;
88
92
}
89
93
94
+ function simulateKeyPressOnEditor (
95
+ editorControl : ReactWrapper < any , Readonly < { } > , React . Component > | undefined ,
96
+ keyboardEvent : Partial < IKeyboardEvent > & { code : string }
97
+ ) {
98
+ enterEditorKey ( editorControl , keyboardEvent ) ;
99
+ }
100
+
90
101
// Uncomment this to debug hangs on exit
91
102
// suiteTeardown(() => {
92
103
// asyncDump();
@@ -217,6 +228,36 @@ for i in range(10):
217
228
}
218
229
) ;
219
230
231
+ runMountedTest (
232
+ 'Escape/Ctrl+U' ,
233
+ async wrapper => {
234
+ // Create an interactive window so that it listens to the results.
235
+ const interactiveWindow = await getOrCreateInteractiveWindow ( ioc ) ;
236
+ await interactiveWindow . show ( ) ;
237
+
238
+ // Type in the input box
239
+ const editor = getInteractiveEditor ( wrapper ) ;
240
+ typeCode ( editor , 'a=1\na' ) ;
241
+
242
+ // Check code is what we think it is
243
+ const reactEditor = editor . instance ( ) as MonacoEditor ;
244
+ assert . equal ( reactEditor . state . model ?. getValue ( ) . replace ( / \r / g, '' ) , 'a=1\na' ) ;
245
+
246
+ // Send escape
247
+ simulateKeyPressOnEditor ( editor , { code : 'Escape' } ) ;
248
+ assert . equal ( reactEditor . state . model ?. getValue ( ) . replace ( / \r / g, '' ) , '' ) ;
249
+
250
+ typeCode ( editor , 'a=1\na' ) ;
251
+ assert . equal ( reactEditor . state . model ?. getValue ( ) . replace ( / \r / g, '' ) , 'a=1\na' ) ;
252
+
253
+ simulateKeyPressOnEditor ( editor , { code : 'KeyU' , ctrlKey : true } ) ;
254
+ assert . equal ( reactEditor . state . model ?. getValue ( ) . replace ( / \r / g, '' ) , '' ) ;
255
+ } ,
256
+ ( ) => {
257
+ return ioc ;
258
+ }
259
+ ) ;
260
+
220
261
runMountedTest (
221
262
'Click outside cells sets focus to input box' ,
222
263
async wrapper => {
0 commit comments