Przeglądaj źródła

Changed: Remove crateButtonDropdown() and createListDropdown() helpers.

Maciej Gołaszewski 8 lat temu
rodzic
commit
8ddbd29f90

+ 0 - 58
packages/ckeditor5-ui/src/dropdown/button/createbuttondropdown.js

@@ -1,58 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module ui/dropdown/button/createbuttondropdown
- */
-
-import {
-	addDefaultBehavior,
-	addToolbarToDropdown,
-	createSingleButtonDropdown
-} from '../utils';
-
-import '../../../theme/components/dropdown/buttondropdown.css';
-
-/**
- * Creates an instance of {@link module:ui/dropdown/button/buttondropdownview~ButtonDropdownView} class using
- * a provided {@link module:ui/dropdown/button/buttondropdownmodel~ButtonDropdownModel}.
- *
- *		const buttons = [];
- *
- *		buttons.push( new ButtonView() );
- *		buttons.push( editor.ui.componentFactory.get( 'someButton' ) );
- *
- *		const model = new Model( {
- *			label: 'A button dropdown',
- *			isVertical: true,
- *			buttons
- *		} );
- *
- *		const dropdown = createButtonDropdown( model, locale );
- *
- *		// Will render a vertical button dropdown labeled "A button dropdown"
- *		// with a button group in the panel containing two buttons.
- *		dropdown.render()
- *		document.body.appendChild( dropdown.element );
- *
- * The model instance remains in control of the dropdown after it has been created. E.g. changes to the
- * {@link module:ui/dropdown/dropdownmodel~DropdownModel#label `model.label`} will be reflected in the
- * dropdown button's {@link module:ui/button/buttonview~ButtonView#label} attribute and in DOM.
- *
- * See {@link module:ui/dropdown/createdropdown~createDropdown}.
- *
- * @param {module:ui/dropdown/button/buttondropdownmodel~ButtonDropdownModel} model Model of the list dropdown.
- * @param {module:utils/locale~Locale} locale The locale instance.
- * @returns {module:ui/dropdown/button/buttondropdownview~ButtonDropdownView} The button dropdown view instance.
- * @returns {module:ui/dropdown/dropdownview~DropdownView}
- */
-export default function createButtonDropdown( model, locale ) {
-	const dropdownView = createSingleButtonDropdown( model, locale );
-
-	addToolbarToDropdown( dropdownView, model );
-	addDefaultBehavior( dropdownView );
-
-	return dropdownView;
-}

+ 0 - 61
packages/ckeditor5-ui/src/dropdown/list/createlistdropdown.js

@@ -1,61 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/**
- * @module ui/dropdown/list/createlistdropdown
- */
-
-import {
-	addDefaultBehavior,
-	addListViewToDropdown,
-	createSingleButtonDropdown
-} from '../utils';
-
-/**
- * Creates an instance of {@link module:ui/dropdown/list/listdropdownview~ListDropdownView} class using
- * a provided {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel}.
- *
- *		const items = new Collection();
- *
- *		items.add( new Model( { label: 'First item', style: 'color: red' } ) );
- *		items.add( new Model( { label: 'Second item', style: 'color: green', class: 'foo' } ) );
- *
- *		const model = new Model( {
- *			isEnabled: true,
- *			items,
- *			isOn: false,
- *			label: 'A dropdown'
- *		} );
- *
- *		const dropdown = createListDropdown( model, locale );
- *
- *		// Will render a dropdown labeled "A dropdown" with a list in the panel
- *		// containing two items.
- *		dropdown.render()
- *		document.body.appendChild( dropdown.element );
- *
- * The model instance remains in control of the dropdown after it has been created. E.g. changes to the
- * {@link module:ui/dropdown/dropdownmodel~DropdownModel#label `model.label`} will be reflected in the
- * dropdown button's {@link module:ui/button/buttonview~ButtonView#label} attribute and in DOM.
- *
- * The
- * {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel#items items collection}
- * of the {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel model} also controls the
- * presence and attributes of respective {@link module:ui/list/listitemview~ListItemView list items}.
- *
- * See {@link module:ui/dropdown/createdropdown~createDropdown} and {@link module:list/list~List}.
- *
- * @param {module:ui/dropdown/list/listdropdownmodel~ListDropdownModel} model Model of the list dropdown.
- * @param {module:utils/locale~Locale} locale The locale instance.
- * @returns {module:ui/dropdown/list/listdropdownview~ListDropdownView} The list dropdown view instance.
- */
-export default function createListDropdown( model, locale ) {
-	const dropdownView = createSingleButtonDropdown( model, locale );
-
-	addListViewToDropdown( dropdownView, model, locale );
-	addDefaultBehavior( dropdownView );
-
-	return dropdownView;
-}

+ 78 - 1
packages/ckeditor5-ui/src/dropdown/utils.js

@@ -141,9 +141,48 @@ export function enableModelIfOneIsEnabled( model, observables ) {
 	);
 }
 
+/**
+ * Creates an instance of {@link module:ui/dropdown/list/listdropdownview~ListDropdownView} class using
+ * a provided {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel}.
+ *
+ *		const items = new Collection();
+ *
+ *		items.add( new Model( { label: 'First item', style: 'color: red' } ) );
+ *		items.add( new Model( { label: 'Second item', style: 'color: green', class: 'foo' } ) );
+ *
+ *		const model = new Model( {
+ *			isEnabled: true,
+ *			items,
+ *			isOn: false,
+ *			label: 'A dropdown'
+ *		} );
+ *
+ *		const dropdown = createListDropdown( model, locale );
+ *
+ *		// Will render a dropdown labeled "A dropdown" with a list in the panel
+ *		// containing two items.
+ *		dropdown.render()
+ *		document.body.appendChild( dropdown.element );
+ *
+ * The model instance remains in control of the dropdown after it has been created. E.g. changes to the
+ * {@link module:ui/dropdown/dropdownmodel~DropdownModel#label `model.label`} will be reflected in the
+ * dropdown button's {@link module:ui/button/buttonview~ButtonView#label} attribute and in DOM.
+ *
+ * The
+ * {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel#items items collection}
+ * of the {@link module:ui/dropdown/list/listdropdownmodel~ListDropdownModel model} also controls the
+ * presence and attributes of respective {@link module:ui/list/listitemview~ListItemView list items}.
+ *
+ * See {@link module:ui/dropdown/createdropdown~createDropdown} and {@link module:list/list~List}.
+ *
+ * @param {module:ui/dropdown/list/listdropdownmodel~ListDropdownModel} model Model of the list dropdown.
+ * @param {module:utils/locale~Locale} locale The locale instance.
+ * @returns {module:ui/dropdown/list/listdropdownview~ListDropdownView} The list dropdown view instance.
+ */
 export function addListViewToDropdown( dropdownView, model, locale ) {
 	const listView = dropdownView.listView = new ListView( locale );
 
+	// TODO: make this param of method instead of model property
 	listView.items.bindTo( model.items ).using( itemModel => {
 		const item = new ListItemView( locale );
 
@@ -155,11 +194,48 @@ export function addListViewToDropdown( dropdownView, model, locale ) {
 
 	dropdownView.panelView.children.add( listView );
 
+	// TODO: make this also on toolbar????
 	listView.items.delegate( 'execute' ).to( dropdownView );
 
 	return listView;
 }
 
+// TODO: where I go??? Make something smart since
+import '../../theme/components/dropdown/buttondropdown.css';
+
+/**
+ * Creates an instance of {@link module:ui/dropdown/button/buttondropdownview~ButtonDropdownView} class using
+ * a provided {@link module:ui/dropdown/button/buttondropdownmodel~ButtonDropdownModel}.
+ *
+ *		const buttons = [];
+ *
+ *		buttons.push( new ButtonView() );
+ *		buttons.push( editor.ui.componentFactory.get( 'someButton' ) );
+ *
+ *		const model = new Model( {
+ *			label: 'A button dropdown',
+ *			isVertical: true,
+ *			buttons
+ *		} );
+ *
+ *		const dropdown = createButtonDropdown( model, locale );
+ *
+ *		// Will render a vertical button dropdown labeled "A button dropdown"
+ *		// with a button group in the panel containing two buttons.
+ *		dropdown.render()
+ *		document.body.appendChild( dropdown.element );
+ *
+ * The model instance remains in control of the dropdown after it has been created. E.g. changes to the
+ * {@link module:ui/dropdown/dropdownmodel~DropdownModel#label `model.label`} will be reflected in the
+ * dropdown button's {@link module:ui/button/buttonview~ButtonView#label} attribute and in DOM.
+ *
+ * See {@link module:ui/dropdown/createdropdown~createDropdown}.
+ *
+ * @param {module:ui/dropdown/button/buttondropdownmodel~ButtonDropdownModel} model Model of the list dropdown.
+ * @param {module:utils/locale~Locale} locale The locale instance.
+ * @returns {module:ui/dropdown/button/buttondropdownview~ButtonDropdownView} The button dropdown view instance.
+ * @returns {module:ui/dropdown/dropdownview~DropdownView}
+ */
 export function addToolbarToDropdown( dropdownView, model ) {
 	const toolbarView = dropdownView.toolbarView = new ToolbarView();
 
@@ -195,6 +271,7 @@ export function addDefaultBehavior( dropdownView ) {
 // @param {Iterable.<module:ui/button/buttonview~ButtonView>} buttons
 // @param {String} attribute
 // @returns {Array.<String>}
-function getBindingTargets( buttons, attribute ) {
+export function getBindingTargets( buttons, attribute ) {
 	return Array.prototype.concat( ...buttons.map( button => [ button, attribute ] ) );
 }
+

+ 0 - 174
packages/ckeditor5-ui/tests/dropdown/button/createbuttondropdown.js

@@ -1,174 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* globals document, Event */
-
-import Model from '../../../src/model';
-import createButtonDropdown from '../../../src/dropdown/button/createbuttondropdown';
-
-import ButtonView from '../../../src/button/buttonview';
-import ToolbarView from '../../../src/toolbar/toolbarview';
-
-import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
-
-describe( 'createButtonDropdown', () => {
-	let view, model, locale, buttons;
-
-	beforeEach( () => {
-		locale = { t() {} };
-		buttons = [ '<svg>foo</svg>', '<svg>bar</svg>' ].map( icon => {
-			const button = new ButtonView();
-			button.icon = icon;
-
-			return button;
-		} );
-
-		model = new Model( {
-			isVertical: true,
-			buttons
-		} );
-
-		view = createButtonDropdown( model, locale );
-		view.render();
-		document.body.appendChild( view.element );
-	} );
-
-	afterEach( () => {
-		view.element.remove();
-	} );
-
-	describe( 'constructor()', () => {
-		it( 'sets view#locale', () => {
-			expect( view.locale ).to.equal( locale );
-		} );
-
-		describe( 'view#toolbarView', () => {
-			it( 'is created', () => {
-				const panelChildren = view.panelView.children;
-
-				expect( panelChildren ).to.have.length( 1 );
-				expect( panelChildren.get( 0 ) ).to.equal( view.toolbarView );
-				expect( view.toolbarView ).to.be.instanceof( ToolbarView );
-			} );
-
-			it( 'delegates view.toolbarView#execute to the view', done => {
-				view.on( 'execute', evt => {
-					expect( evt.source ).to.equal( view.toolbarView.items.get( 0 ) );
-					expect( evt.path ).to.deep.equal( [ view.toolbarView.items.get( 0 ), view ] );
-
-					done();
-				} );
-
-				view.toolbarView.items.get( 0 ).fire( 'execute' );
-			} );
-
-			it( 'reacts on model#isVertical', () => {
-				model.isVertical = false;
-				expect( view.toolbarView.isVertical ).to.be.false;
-
-				model.isVertical = true;
-				expect( view.toolbarView.isVertical ).to.be.true;
-			} );
-
-			it( 'reacts on model#toolbarClassName', () => {
-				expect( view.toolbarView.className ).to.be.undefined;
-
-				model.set( 'toolbarClassName', 'foo' );
-				expect( view.toolbarView.className ).to.equal( 'foo' );
-			} );
-		} );
-
-		it( 'changes view#isOpen on view#execute', () => {
-			view.isOpen = true;
-
-			view.fire( 'execute' );
-			expect( view.isOpen ).to.be.false;
-
-			view.fire( 'execute' );
-			expect( view.isOpen ).to.be.false;
-		} );
-
-		it( 'listens to view#isOpen and reacts to DOM events (valid target)', () => {
-			// Open the dropdown.
-			view.isOpen = true;
-
-			// Fire event from outside of the dropdown.
-			document.body.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Closed the dropdown.
-			expect( view.isOpen ).to.be.false;
-
-			// Fire event from outside of the dropdown.
-			document.body.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still closed.
-			expect( view.isOpen ).to.be.false;
-		} );
-
-		it( 'listens to view#isOpen and reacts to DOM events (invalid target)', () => {
-			// Open the dropdown.
-			view.isOpen = true;
-
-			// Event from view.element should be discarded.
-			view.element.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still open.
-			expect( view.isOpen ).to.be.true;
-
-			// Event from within view.element should be discarded.
-			const child = document.createElement( 'div' );
-			view.element.appendChild( child );
-
-			child.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still open.
-			expect( view.isOpen ).to.be.true;
-		} );
-
-		describe( 'activates keyboard navigation for the dropdown', () => {
-			it( 'so "arrowdown" focuses the #toolbarView if dropdown is open', () => {
-				const keyEvtData = {
-					keyCode: keyCodes.arrowdown,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				};
-				const spy = sinon.spy( view.toolbarView, 'focus' );
-
-				view.isOpen = false;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.notCalled( spy );
-
-				view.isOpen = true;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.calledOnce( spy );
-			} );
-
-			it( 'so "arrowup" focuses the last #item in #toolbarView if dropdown is open', () => {
-				const keyEvtData = {
-					keyCode: keyCodes.arrowup,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				};
-				const spy = sinon.spy( view.toolbarView, 'focusLast' );
-
-				view.isOpen = false;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.notCalled( spy );
-
-				view.isOpen = true;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.calledOnce( spy );
-			} );
-		} );
-	} );
-} );

+ 0 - 185
packages/ckeditor5-ui/tests/dropdown/list/createlistdropdown.js

@@ -1,185 +0,0 @@
-/**
- * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md.
- */
-
-/* globals document, Event */
-
-import Model from '../../../src/model';
-import createListDropdown from '../../../src/dropdown/list/createlistdropdown';
-import Collection from '@ckeditor/ckeditor5-utils/src/collection';
-import ListView from '../../../src/list/listview';
-import ListItemView from '../../../src/list/listitemview';
-import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
-
-describe( 'createListDropdown', () => {
-	let view, model, locale, items;
-
-	beforeEach( () => {
-		locale = { t() {} };
-		items = new Collection();
-		model = new Model( {
-			isEnabled: true,
-			items,
-			isOn: false,
-			label: 'foo'
-		} );
-
-		view = createListDropdown( model, locale );
-		view.render();
-		document.body.appendChild( view.element );
-	} );
-
-	afterEach( () => {
-		view.element.remove();
-	} );
-
-	describe( 'constructor()', () => {
-		it( 'sets view#locale', () => {
-			expect( view.locale ).to.equal( locale );
-		} );
-
-		describe( 'view#listView', () => {
-			it( 'is created', () => {
-				const panelChildren = view.panelView.children;
-
-				expect( panelChildren ).to.have.length( 1 );
-				expect( panelChildren.get( 0 ) ).to.equal( view.listView );
-				expect( view.listView ).to.be.instanceof( ListView );
-			} );
-
-			it( 'is bound to model#items', () => {
-				items.add( new Model( { label: 'a', style: 'b' } ) );
-				items.add( new Model( { label: 'c', style: 'd' } ) );
-
-				expect( view.listView.items ).to.have.length( 2 );
-				expect( view.listView.items.get( 0 ) ).to.be.instanceOf( ListItemView );
-				expect( view.listView.items.get( 1 ).label ).to.equal( 'c' );
-				expect( view.listView.items.get( 1 ).style ).to.equal( 'd' );
-
-				items.remove( 1 );
-				expect( view.listView.items ).to.have.length( 1 );
-				expect( view.listView.items.get( 0 ).label ).to.equal( 'a' );
-				expect( view.listView.items.get( 0 ).style ).to.equal( 'b' );
-			} );
-
-			it( 'binds all attributes in model#items', () => {
-				const itemModel = new Model( { label: 'a', style: 'b', foo: 'bar', baz: 'qux' } );
-
-				items.add( itemModel );
-
-				const item = view.listView.items.get( 0 );
-
-				expect( item.foo ).to.equal( 'bar' );
-				expect( item.baz ).to.equal( 'qux' );
-
-				itemModel.baz = 'foo?';
-				expect( item.baz ).to.equal( 'foo?' );
-			} );
-
-			it( 'delegates view.listView#execute to the view', done => {
-				items.add( new Model( { label: 'a', style: 'b' } ) );
-
-				view.on( 'execute', evt => {
-					expect( evt.source ).to.equal( view.listView.items.get( 0 ) );
-					expect( evt.path ).to.deep.equal( [ view.listView.items.get( 0 ), view ] );
-
-					done();
-				} );
-
-				view.listView.items.get( 0 ).fire( 'execute' );
-			} );
-		} );
-
-		it( 'changes view#isOpen on view#execute', () => {
-			view.isOpen = true;
-
-			view.fire( 'execute' );
-			expect( view.isOpen ).to.be.false;
-
-			view.fire( 'execute' );
-			expect( view.isOpen ).to.be.false;
-		} );
-
-		it( 'listens to view#isOpen and reacts to DOM events (valid target)', () => {
-			// Open the dropdown.
-			view.isOpen = true;
-
-			// Fire event from outside of the dropdown.
-			document.body.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Closed the dropdown.
-			expect( view.isOpen ).to.be.false;
-
-			// Fire event from outside of the dropdown.
-			document.body.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still closed.
-			expect( view.isOpen ).to.be.false;
-		} );
-
-		it( 'listens to view#isOpen and reacts to DOM events (invalid target)', () => {
-			// Open the dropdown.
-			view.isOpen = true;
-
-			// Event from view.element should be discarded.
-			view.element.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still open.
-			expect( view.isOpen ).to.be.true;
-
-			// Event from within view.element should be discarded.
-			const child = document.createElement( 'div' );
-			view.element.appendChild( child );
-
-			child.dispatchEvent( new Event( 'mousedown', {
-				bubbles: true
-			} ) );
-
-			// Dropdown is still open.
-			expect( view.isOpen ).to.be.true;
-		} );
-
-		describe( 'activates keyboard navigation for the dropdown', () => {
-			it( 'so "arrowdown" focuses the #listView if dropdown is open', () => {
-				const keyEvtData = {
-					keyCode: keyCodes.arrowdown,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				};
-				const spy = sinon.spy( view.listView, 'focus' );
-
-				view.isOpen = false;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.notCalled( spy );
-
-				view.isOpen = true;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.calledOnce( spy );
-			} );
-
-			it( 'so "arrowup" focuses the last #item in #listView if dropdown is open', () => {
-				const keyEvtData = {
-					keyCode: keyCodes.arrowup,
-					preventDefault: sinon.spy(),
-					stopPropagation: sinon.spy()
-				};
-				const spy = sinon.spy( view.listView, 'focusLast' );
-
-				view.isOpen = false;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.notCalled( spy );
-
-				view.isOpen = true;
-				view.keystrokes.press( keyEvtData );
-				sinon.assert.calledOnce( spy );
-			} );
-		} );
-	} );
-} );

+ 9 - 4
packages/ckeditor5-ui/tests/dropdown/manual/dropdown.js

@@ -9,7 +9,6 @@ import Model from '../../../src/model';
 import Collection from '@ckeditor/ckeditor5-utils/src/collection';
 
 import createDropdown from '../../../src/dropdown/createdropdown';
-import createListDropdown from '../../../src/dropdown/list/createlistdropdown';
 
 import testUtils from '../../_utils/utils';
 
@@ -18,7 +17,7 @@ import alignRightIcon from '@ckeditor/ckeditor5-core/theme/icons/object-right.sv
 import alignCenterIcon from '@ckeditor/ckeditor5-core/theme/icons/object-center.svg';
 import ButtonView from '../../../src/button/buttonview';
 
-import createButtonDropdown from '../../../src/dropdown/button/createbuttondropdown';
+import { addDefaultBehavior, addListViewToDropdown, addToolbarToDropdown, createSingleButtonDropdown } from '../../../src/dropdown/utils';
 
 const ui = testUtils.createTestUIView( {
 	dropdown: '#dropdown',
@@ -59,7 +58,10 @@ function testList() {
 		items: collection
 	} );
 
-	const dropdownView = createListDropdown( model );
+	const dropdownView = createSingleButtonDropdown( model, {} );
+
+	addListViewToDropdown( dropdownView, model, {} );
+	addDefaultBehavior( dropdownView );
 
 	dropdownView.on( 'execute', evt => {
 		/* global console */
@@ -127,7 +129,10 @@ function testButton() {
 		buttons: buttonViews
 	} );
 
-	const buttonDropdown = createButtonDropdown( buttonDropdownModel, {} );
+	const buttonDropdown = createSingleButtonDropdown( buttonDropdownModel, {} );
+
+	addToolbarToDropdown( buttonDropdown, buttonDropdownModel );
+	addDefaultBehavior( buttonDropdown );
 
 	ui.buttonDropdown.add( buttonDropdown );
 

+ 343 - 0
packages/ckeditor5-ui/tests/dropdown/utils.js

@@ -0,0 +1,343 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document, Event */
+
+import { keyCodes } from '@ckeditor/ckeditor5-utils/src/keyboard';
+
+import Model from '../../src/model';
+
+import View from '../../src/view';
+import ButtonView from '../../src/button/buttonview';
+import ToolbarView from '../../src/toolbar/toolbarview';
+
+import {
+	addListViewToDropdown,
+	addToolbarToDropdown,
+	closeDropdownOnBlur,
+	closeDropdownOnExecute,
+	createButtonForDropdown,
+	createDropdownView,
+	createSingleButtonDropdown,
+	focusDropdownContentsOnArrows
+} from '../../src/dropdown/utils';
+import ListItemView from '../../src/list/listitemview';
+
+import ListView from '../../src/list/listview';
+import Collection from '../../../ckeditor5-utils/src/collection';
+
+describe( 'utils', () => {
+	let dropdownView, buttonView, model, locale;
+
+	beforeEach( () => {
+		locale = { t() {} };
+		model = new Model();
+		buttonView = createButtonForDropdown( model, locale );
+		dropdownView = createDropdownView( model, buttonView, locale );
+	} );
+
+	describe( 'focusDropdownContentsOnArrows', () => {
+		let panelChildView;
+
+		beforeEach( () => {
+			panelChildView = new View();
+			panelChildView.setTemplate( { tag: 'div' } );
+			panelChildView.focus = () => {};
+			panelChildView.focusLast = () => {};
+
+			// TODO: describe this as #contentView instaed of #listView and #toolbarView
+			dropdownView.panelView.children.add( panelChildView );
+
+			focusDropdownContentsOnArrows( dropdownView );
+
+			dropdownView.render();
+			document.body.appendChild( dropdownView.element );
+		} );
+
+		it( '"arrowdown" focuses the #innerPanelView if dropdown is open', () => {
+			const keyEvtData = {
+				keyCode: keyCodes.arrowdown,
+				preventDefault: sinon.spy(),
+				stopPropagation: sinon.spy()
+			};
+			const spy = sinon.spy( panelChildView, 'focus' );
+
+			dropdownView.isOpen = false;
+			dropdownView.keystrokes.press( keyEvtData );
+			sinon.assert.notCalled( spy );
+
+			dropdownView.isOpen = true;
+			dropdownView.keystrokes.press( keyEvtData );
+
+			sinon.assert.calledOnce( spy );
+		} );
+
+		it( '"arrowup" focuses the last #item in #innerPanelView if dropdown is open', () => {
+			const keyEvtData = {
+				keyCode: keyCodes.arrowup,
+				preventDefault: sinon.spy(),
+				stopPropagation: sinon.spy()
+			};
+			const spy = sinon.spy( panelChildView, 'focusLast' );
+
+			dropdownView.isOpen = false;
+			dropdownView.keystrokes.press( keyEvtData );
+			sinon.assert.notCalled( spy );
+
+			dropdownView.isOpen = true;
+			dropdownView.keystrokes.press( keyEvtData );
+			sinon.assert.calledOnce( spy );
+		} );
+	} );
+
+	describe( 'closeDropdownOnExecute', () => {
+		beforeEach( () => {
+			closeDropdownOnExecute( dropdownView );
+
+			dropdownView.render();
+			document.body.appendChild( dropdownView.element );
+		} );
+
+		it( 'changes view#isOpen on view#execute', () => {
+			dropdownView.isOpen = true;
+
+			dropdownView.fire( 'execute' );
+			expect( dropdownView.isOpen ).to.be.false;
+
+			dropdownView.fire( 'execute' );
+			expect( dropdownView.isOpen ).to.be.false;
+		} );
+	} );
+
+	describe( 'closeDropdownOnBlur', () => {
+		beforeEach( () => {
+			closeDropdownOnBlur( dropdownView );
+
+			dropdownView.render();
+			document.body.appendChild( dropdownView.element );
+		} );
+
+		it( 'listens to view#isOpen and reacts to DOM events (valid target)', () => {
+			// Open the dropdown.
+			dropdownView.isOpen = true;
+
+			// Fire event from outside of the dropdown.
+			document.body.dispatchEvent( new Event( 'mousedown', {
+				bubbles: true
+			} ) );
+
+			// Closed the dropdown.
+			expect( dropdownView.isOpen ).to.be.false;
+
+			// Fire event from outside of the dropdown.
+			document.body.dispatchEvent( new Event( 'mousedown', {
+				bubbles: true
+			} ) );
+
+			// Dropdown is still closed.
+			expect( dropdownView.isOpen ).to.be.false;
+		} );
+
+		it( 'listens to view#isOpen and reacts to DOM events (invalid target)', () => {
+			// Open the dropdown.
+			dropdownView.isOpen = true;
+
+			// Event from view.element should be discarded.
+			dropdownView.element.dispatchEvent( new Event( 'mousedown', {
+				bubbles: true
+			} ) );
+
+			// Dropdown is still open.
+			expect( dropdownView.isOpen ).to.be.true;
+
+			// Event from within view.element should be discarded.
+			const child = document.createElement( 'div' );
+			dropdownView.element.appendChild( child );
+
+			child.dispatchEvent( new Event( 'mousedown', {
+				bubbles: true
+			} ) );
+
+			// Dropdown is still open.
+			expect( dropdownView.isOpen ).to.be.true;
+		} );
+	} );
+
+	describe( 'createButtonForDropdown', () => {} );
+
+	describe( 'createSplitButtonForDropdown', () => {} );
+
+	describe( 'createDropdownView', () => {} );
+
+	describe( 'createSplitButtonDropdown', () => {} );
+
+	describe( 'createSingleButtonDropdown', () => {} );
+
+	describe( 'enableModelIfOneIsEnabled', () => {} );
+
+	describe( 'addListViewToDropdown', () => {
+		let items;
+
+		beforeEach( () => {
+			items = new Collection();
+			model = new Model( {
+				isEnabled: true,
+				items,
+				isOn: false,
+				label: 'foo'
+			} );
+
+			dropdownView = createSingleButtonDropdown( model, locale );
+
+			addListViewToDropdown( dropdownView, model, locale );
+
+			dropdownView.render();
+			document.body.appendChild( dropdownView.element );
+		} );
+
+		afterEach( () => {
+			dropdownView.element.remove();
+		} );
+
+		it( 'sets view#locale', () => {
+			expect( dropdownView.locale ).to.equal( locale );
+		} );
+
+		describe( 'view#listView', () => {
+			it( 'is created', () => {
+				const panelChildren = dropdownView.panelView.children;
+
+				expect( panelChildren ).to.have.length( 1 );
+				expect( panelChildren.get( 0 ) ).to.equal( dropdownView.listView );
+				expect( dropdownView.listView ).to.be.instanceof( ListView );
+			} );
+
+			it( 'is bound to model#items', () => {
+				items.add( new Model( { label: 'a', style: 'b' } ) );
+				items.add( new Model( { label: 'c', style: 'd' } ) );
+
+				expect( dropdownView.listView.items ).to.have.length( 2 );
+				expect( dropdownView.listView.items.get( 0 ) ).to.be.instanceOf( ListItemView );
+				expect( dropdownView.listView.items.get( 1 ).label ).to.equal( 'c' );
+				expect( dropdownView.listView.items.get( 1 ).style ).to.equal( 'd' );
+
+				items.remove( 1 );
+				expect( dropdownView.listView.items ).to.have.length( 1 );
+				expect( dropdownView.listView.items.get( 0 ).label ).to.equal( 'a' );
+				expect( dropdownView.listView.items.get( 0 ).style ).to.equal( 'b' );
+			} );
+
+			it( 'binds all attributes in model#items', () => {
+				const itemModel = new Model( { label: 'a', style: 'b', foo: 'bar', baz: 'qux' } );
+
+				items.add( itemModel );
+
+				const item = dropdownView.listView.items.get( 0 );
+
+				expect( item.foo ).to.equal( 'bar' );
+				expect( item.baz ).to.equal( 'qux' );
+
+				itemModel.baz = 'foo?';
+				expect( item.baz ).to.equal( 'foo?' );
+			} );
+
+			it( 'delegates view.listView#execute to the view', done => {
+				items.add( new Model( { label: 'a', style: 'b' } ) );
+
+				dropdownView.on( 'execute', evt => {
+					expect( evt.source ).to.equal( dropdownView.listView.items.get( 0 ) );
+					expect( evt.path ).to.deep.equal( [ dropdownView.listView.items.get( 0 ), dropdownView ] );
+
+					done();
+				} );
+
+				dropdownView.listView.items.get( 0 ).fire( 'execute' );
+			} );
+		} );
+	} );
+
+	describe( 'addToolbarToDropdown', () => {
+		let buttons;
+
+		beforeEach( () => {
+			buttons = [ '<svg>foo</svg>', '<svg>bar</svg>' ].map( icon => {
+				const button = new ButtonView();
+
+				button.icon = icon;
+
+				return button;
+			} );
+
+			model = new Model( {
+				isVertical: true,
+				buttons
+			} );
+
+			dropdownView = createSingleButtonDropdown( model, locale );
+
+			addToolbarToDropdown( dropdownView, model );
+
+			dropdownView.render();
+			document.body.appendChild( dropdownView.element );
+		} );
+
+		afterEach( () => {
+			dropdownView.element.remove();
+		} );
+
+		describe( 'constructor()', () => {
+			it( 'sets view#locale', () => {
+				expect( dropdownView.locale ).to.equal( locale );
+			} );
+
+			describe( 'view#toolbarView', () => {
+				it( 'is created', () => {
+					const panelChildren = dropdownView.panelView.children;
+
+					expect( panelChildren ).to.have.length( 1 );
+					expect( panelChildren.get( 0 ) ).to.equal( dropdownView.toolbarView );
+					expect( dropdownView.toolbarView ).to.be.instanceof( ToolbarView );
+				} );
+
+				it.skip( 'delegates view.toolbarView.items#execute to the view', done => {
+					dropdownView.on( 'execute', evt => {
+						expect( evt.source ).to.equal( dropdownView.toolbarView.items.get( 0 ) );
+						expect( evt.path ).to.deep.equal( [ dropdownView.toolbarView.items.get( 0 ), dropdownView ] );
+
+						done();
+					} );
+
+					dropdownView.toolbarView.items.get( 0 ).fire( 'execute' );
+				} );
+
+				it( 'reacts on model#isVertical', () => {
+					model.isVertical = false;
+					expect( dropdownView.toolbarView.isVertical ).to.be.false;
+
+					model.isVertical = true;
+					expect( dropdownView.toolbarView.isVertical ).to.be.true;
+				} );
+
+				// TODO: remove?
+				it( 'reacts on model#toolbarClassName', () => {
+					expect( dropdownView.toolbarView.className ).to.be.undefined;
+
+					model.set( 'toolbarClassName', 'foo' );
+					expect( dropdownView.toolbarView.className ).to.equal( 'foo' );
+				} );
+			} );
+
+			describe( 'buttons', () => {
+				// TODO: test me!
+			} );
+		} );
+	} );
+
+	describe( 'addDefaultBehavior', () => {} );
+
+	describe( 'getBindingTargets', () => {} );
+
+	describe.skip( 'to sort', () => {} );
+} );