@@ -7,6 +7,8 @@ import { ShellInput } from './shell-input';
7
7
import { ShellOutput } from './shell-output' ;
8
8
import { ShellOutputEntry } from './shell-output-line' ;
9
9
10
+ const styles = require ( './shell.less' ) ;
11
+
10
12
const wait : ( ms ?: number ) => Promise < void > = ( ms = 10 ) => {
11
13
return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
12
14
} ;
@@ -17,6 +19,7 @@ describe('<Shell />', () => {
17
19
let fakeRuntime ;
18
20
let wrapper : ShallowWrapper | ReactWrapper ;
19
21
let scrollIntoView ;
22
+ let elementFocus ;
20
23
let onInput ;
21
24
22
25
beforeEach ( ( ) => {
@@ -27,6 +30,7 @@ describe('<Shell />', () => {
27
30
} ;
28
31
29
32
scrollIntoView = sinon . spy ( Element . prototype , 'scrollIntoView' ) ;
33
+ elementFocus = sinon . spy ( HTMLElement . prototype , 'focus' ) ;
30
34
31
35
fakeRuntime = {
32
36
evaluate : sinon . fake . returns ( { value : 'some result' } )
@@ -43,6 +47,7 @@ describe('<Shell />', () => {
43
47
44
48
afterEach ( ( ) => {
45
49
scrollIntoView . restore ( ) ;
50
+ elementFocus . restore ( ) ;
46
51
} ) ;
47
52
48
53
it ( 'renders a ShellOutput component' , ( ) => {
@@ -265,4 +270,30 @@ describe('<Shell />', () => {
265
270
266
271
expect ( Element . prototype . scrollIntoView ) . to . have . been . calledTwice ;
267
272
} ) ;
273
+
274
+ it ( 'focuses on the input when the background container is clicked' , ( ) => {
275
+ wrapper = mount ( < Shell runtime = { fakeRuntime } /> ) ;
276
+ const container = wrapper . find ( `.${ styles . shell } ` ) ;
277
+
278
+ const fakeMouseEvent : any = {
279
+ target : 'a' ,
280
+ currentTarget : 'a'
281
+ } ;
282
+ container . prop ( 'onClick' ) ( fakeMouseEvent ) ;
283
+
284
+ expect ( HTMLElement . prototype . focus ) . to . have . been . calledOnce ;
285
+ } ) ;
286
+
287
+ it ( 'does not focus on the input when an element that is not the background container is clicked' , ( ) => {
288
+ wrapper = mount ( < Shell runtime = { fakeRuntime } /> ) ;
289
+ const container = wrapper . find ( `.${ styles . shell } ` ) ;
290
+
291
+ const fakeMouseEvent : any = {
292
+ target : 'a' ,
293
+ currentTarget : 'b'
294
+ } ;
295
+ container . prop ( 'onClick' ) ( fakeMouseEvent ) ;
296
+
297
+ expect ( HTMLElement . prototype . focus ) . to . not . have . been . called ;
298
+ } ) ;
268
299
} ) ;
0 commit comments