Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

Commit 3d597b7

Browse files
committed
Added missing tests.
1 parent d235741 commit 3d597b7

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed

tests/widgettoolbarrepository.js

+65
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,71 @@ describe( 'WidgetToolbarRepository', () => {
136136
expect( balloon.visibleView ).to.equal( null );
137137
} );
138138

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+
139204
it( 'toolbar should update its position when other widget is selected', () => {
140205
widgetToolbarRepository.register( 'fake', {
141206
items: editor.config.get( 'fake.toolbar' ),

0 commit comments

Comments
 (0)