@@ -136,6 +136,71 @@ describe( 'WidgetToolbarRepository', () => {
136
136
expect ( balloon . visibleView ) . to . equal ( null ) ;
137
137
} ) ;
138
138
139
+ it ( 'toolbar should be removed from not visible balloon stack when the `getRelatedElement` callback returns null' , ( ) => {
140
+ balloon . add ( {
141
+ view : new View ( ) ,
142
+ stackId : 'secondary' ,
143
+ position : {
144
+ target : { }
145
+ }
146
+ } ) ;
147
+
148
+ widgetToolbarRepository . register ( 'fake' , {
149
+ items : editor . config . get ( 'fake.toolbar' ) ,
150
+ getRelatedElement : getSelectedFakeWidget
151
+ } ) ;
152
+
153
+ setData ( model , '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' ) ;
154
+
155
+ const fakeWidgetToolbarView = widgetToolbarRepository . _toolbarDefinitions . get ( 'fake' ) . view ;
156
+
157
+ expect ( balloon . hasView ( fakeWidgetToolbarView ) ) ;
158
+ expect ( balloon . visibleView ) . to . not . equal ( fakeWidgetToolbarView ) ;
159
+
160
+ model . change ( writer => {
161
+ // Select the <paragraph>foo</paragraph>.
162
+ writer . setSelection ( model . document . getRoot ( ) . getChild ( 0 ) , 'in' ) ;
163
+ } ) ;
164
+
165
+ expect ( balloon . hasView ( fakeWidgetToolbarView ) ) . to . equal ( false ) ;
166
+ } ) ;
167
+
168
+ it ( 'toolbar should be hidden when the editor ui lost focus' , ( ) => {
169
+ widgetToolbarRepository . register ( 'fake' , {
170
+ items : editor . config . get ( 'fake.toolbar' ) ,
171
+ getRelatedElement : getSelectedFakeWidget
172
+ } ) ;
173
+
174
+ setData ( model , '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' ) ;
175
+
176
+ editor . ui . focusTracker . isFocused = false ;
177
+
178
+ expect ( balloon . visibleView ) . to . equal ( null ) ;
179
+ } ) ;
180
+
181
+ it ( 'toolbar should do nothing with toolbar when the editor ui lost focus but toolbar is not a visible view' , ( ) => {
182
+ balloon . add ( {
183
+ view : new View ( ) ,
184
+ stackId : 'secondary' ,
185
+ position : {
186
+ target : { }
187
+ }
188
+ } ) ;
189
+
190
+ widgetToolbarRepository . register ( 'fake' , {
191
+ items : editor . config . get ( 'fake.toolbar' ) ,
192
+ getRelatedElement : getSelectedFakeWidget
193
+ } ) ;
194
+
195
+ setData ( model , '<paragraph>foo</paragraph>[<fake-widget></fake-widget>]' ) ;
196
+
197
+ const fakeWidgetToolbarView = widgetToolbarRepository . _toolbarDefinitions . get ( 'fake' ) . view ;
198
+
199
+ editor . ui . focusTracker . isFocused = false ;
200
+
201
+ expect ( balloon . hasView ( fakeWidgetToolbarView ) ) . to . equal ( true ) ;
202
+ } ) ;
203
+
139
204
it ( 'toolbar should update its position when other widget is selected' , ( ) => {
140
205
widgetToolbarRepository . register ( 'fake' , {
141
206
items : editor . config . get ( 'fake.toolbar' ) ,
0 commit comments