Browse Source

Tests: Add tests for createSplitButtonForDropdown() and createButtonForDropdown().

Maciej Gołaszewski 7 years ago
parent
commit
4a6d0c718f

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

@@ -88,7 +88,7 @@ export function createButtonForDropdown( model, locale ) {
 export function createSplitButtonForDropdown( model, locale ) {
 	const splitButtonView = new SplitButtonView( locale );
 
-	// TODO: something wierd with binding
+	// TODO: Check if those binding are in good place (maybe move them to SplitButton) or add tests.
 	splitButtonView.actionView.bind( 'isOn' ).to( splitButtonView );
 	splitButtonView.actionView.bind( 'tooltip' ).to( splitButtonView );
 

+ 46 - 18
packages/ckeditor5-ui/tests/dropdown/utils.js

@@ -15,6 +15,11 @@ import Model from '../../src/model';
 import View from '../../src/view';
 import ButtonView from '../../src/button/buttonview';
 import ToolbarView from '../../src/toolbar/toolbarview';
+import ListItemView from '../../src/list/listitemview';
+import ListView from '../../src/list/listview';
+import DropdownView from '../../src/dropdown/dropdownview';
+import DropdownPanelView from '../../src/dropdown/dropdownpanelview';
+import SplitButtonView from '../../src/button/splitbuttonview';
 
 import {
 	addListViewToDropdown,
@@ -28,11 +33,6 @@ import {
 	enableModelIfOneIsEnabled,
 	focusDropdownContentsOnArrows
 } from '../../src/dropdown/utils';
-import ListItemView from '../../src/list/listitemview';
-
-import ListView from '../../src/list/listview';
-import DropdownView from '../../src/dropdown/dropdownview';
-import DropdownPanelView from '../../src/dropdown/dropdownpanelview';
 
 const assertBinding = utilsTestUtils.assertBinding;
 
@@ -46,6 +46,10 @@ describe( 'utils', () => {
 		dropdownView = createDropdownView( model, buttonView, locale );
 	} );
 
+	afterEach( () => {
+		dropdownView.element.remove();
+	} );
+
 	describe( 'focusDropdownContentsOnArrows()', () => {
 		let panelChildView;
 
@@ -174,19 +178,51 @@ describe( 'utils', () => {
 	} );
 
 	describe( 'createButtonForDropdown()', () => {
-		it( 'accepts locale', () => {
-			const buttonView = createButtonForDropdown( model, locale );
+		beforeEach( () => {
+			buttonView = createButtonForDropdown( new Model(), locale );
+		} );
 
+		it( 'accepts locale', () => {
 			expect( buttonView.locale ).to.equal( locale );
 		} );
+
+		it( 'returns ButtonView instance', () => {
+			expect( buttonView ).to.be.instanceof( ButtonView );
+		} );
+
+		it( 'delegates "execute" to "select" event', () => {
+			const spy = sinon.spy();
+
+			buttonView.on( 'select', spy );
+
+			buttonView.fire( 'exec' );
+
+			sinon.assert.calledOnce( spy );
+		} );
 	} );
 
 	describe( 'createSplitButtonForDropdown()', () => {
-		it( 'accepts locale', () => {
-			const buttonView = createSplitButtonForDropdown( model, locale );
+		beforeEach( () => {
+			buttonView = createSplitButtonForDropdown( new Model(), locale );
+		} );
 
+		it( 'accepts locale', () => {
 			expect( buttonView.locale ).to.equal( locale );
 		} );
+
+		it( 'returns SplitButtonView instance', () => {
+			expect( buttonView ).to.be.instanceof( SplitButtonView );
+		} );
+
+		it( 'binds actionView "execute" to "select" event', () => {
+			const spy = sinon.spy();
+
+			buttonView.on( 'select', spy );
+
+			buttonView.fire( 'exec' );
+
+			sinon.assert.calledOnce( spy );
+		} );
 	} );
 
 	describe( 'createDropdownView()', () => {
@@ -292,7 +328,7 @@ describe( 'utils', () => {
 		} );
 	} );
 
-	describe( 'createSplitButtonDropdown()', () => {} );
+	describe( 'createSplitButtonDropdown()', () => { } );
 
 	describe( 'createSingleButtonDropdown()', () => {} );
 
@@ -341,10 +377,6 @@ describe( 'utils', () => {
 			document.body.appendChild( dropdownView.element );
 		} );
 
-		afterEach( () => {
-			dropdownView.element.remove();
-		} );
-
 		it( 'sets view#locale', () => {
 			expect( dropdownView.locale ).to.equal( locale );
 		} );
@@ -427,10 +459,6 @@ describe( 'utils', () => {
 			document.body.appendChild( dropdownView.element );
 		} );
 
-		afterEach( () => {
-			dropdownView.element.remove();
-		} );
-
 		it( 'sets view#locale', () => {
 			expect( dropdownView.locale ).to.equal( locale );
 		} );