1
+ import {
2
+ bootstrapFormEditor ,
3
+ getFormEditor ,
4
+ inject
5
+ } from 'test/TestHelper' ;
6
+
7
+
8
+ describe ( 'renderer' , function ( ) {
9
+
10
+ beforeEach ( bootstrapFormEditor ( ) ) ;
11
+
12
+ afterEach ( function ( ) {
13
+ getFormEditor ( ) . destroy ( ) ;
14
+ } ) ;
15
+
16
+
17
+ function getContainer ( ) {
18
+ return getFormEditor ( ) . _container ;
19
+ }
20
+
21
+ describe ( 'focus handling' , function ( ) {
22
+
23
+ it ( 'should be focusable' , inject ( function ( formEditor ) {
24
+
25
+ // given
26
+ var container = getContainer ( ) ;
27
+
28
+ // when
29
+ container . focus ( ) ;
30
+
31
+ // then
32
+ expect ( document . activeElement ) . to . equal ( container ) ;
33
+ } ) ) ;
34
+
35
+
36
+ describe ( '<hover>' , function ( ) {
37
+
38
+ beforeEach ( function ( ) {
39
+ document . body . focus ( ) ;
40
+ } ) ;
41
+
42
+
43
+ it ( 'should focus if body is focused' , inject ( function ( formEditor , eventBus ) {
44
+
45
+ // given
46
+ var container = getContainer ( ) ;
47
+
48
+ // when
49
+ eventBus . fire ( 'element.hover' ) ;
50
+
51
+ // then
52
+ expect ( document . activeElement ) . to . equal ( container ) ;
53
+ } ) ) ;
54
+
55
+
56
+ it ( 'should not scroll on focus' , inject ( function ( canvas , eventBus ) {
57
+
58
+ // given
59
+ var container = getContainer ( ) ;
60
+
61
+ var clientRect = container . getBoundingClientRect ( ) ;
62
+
63
+ // when
64
+ eventBus . fire ( 'element.hover' ) ;
65
+
66
+ // then
67
+ expect ( clientRect ) . to . eql ( container . getBoundingClientRect ( ) ) ;
68
+ } ) ) ;
69
+
70
+
71
+ it ( 'should not focus on existing document focus' , inject ( function ( canvas , eventBus ) {
72
+
73
+ // given
74
+ var inputEl = document . createElement ( 'input' ) ;
75
+
76
+ document . body . appendChild ( inputEl ) ;
77
+ inputEl . focus ( ) ;
78
+
79
+ // assume
80
+ expect ( document . activeElement ) . to . equal ( inputEl ) ;
81
+
82
+ // when
83
+ eventBus . fire ( 'element.hover' ) ;
84
+
85
+ // then
86
+ expect ( document . activeElement ) . to . eql ( inputEl ) ;
87
+ } ) ) ;
88
+
89
+ } ) ;
90
+
91
+ } ) ;
92
+
93
+ } ) ;
0 commit comments