Преглед изворни кода

Added tests to ParagraphButtonUI class.

Szymon Kupś пре 7 година
родитељ
комит
7ff89c8edb
1 измењених фајлова са 84 додато и 0 уклоњено
  1. 84 0
      packages/ckeditor5-paragraph/tests/paragraphbuttonui.js

+ 84 - 0
packages/ckeditor5-paragraph/tests/paragraphbuttonui.js

@@ -0,0 +1,84 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* globals document */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import Paragraph from '../src/paragraph';
+import Heading from '@ckeditor/ckeditor5-heading/src/heading';
+import ParagraphButtonUI from '../src/paragraphbuttonui';
+import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
+import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+import icon from '../theme/icons/paragraph.svg';
+
+describe( 'HeadingButtonUI', () => {
+	let editorElement, editor;
+
+	describe( 'default config', () => {
+		beforeEach( () => {
+			editorElement = document.createElement( 'div' );
+			document.body.appendChild( editorElement );
+
+			return ClassicTestEditor
+				.create( editorElement, {
+					plugins: [ Paragraph, ParagraphButtonUI, Heading ],
+					toolbar: [ 'paragraph' ]
+				} )
+				.then( newEditor => {
+					editor = newEditor;
+					setData( editor.model, '<paragraph>f{}oo</paragraph>' );
+				} );
+		} );
+
+		afterEach( () => {
+			editorElement.remove();
+
+			return editor.destroy();
+		} );
+
+		it( 'should define default buttons', () => {
+			const factory = editor.ui.componentFactory;
+
+			expect( factory.create( 'paragraph' ) ).to.be.instanceOf( ButtonView );
+		} );
+
+		it( 'should intialize buttons with correct data', () => {
+			const paragraphButton = editor.ui.componentFactory.create( 'paragraph' );
+
+			expect( paragraphButton.label ).to.equal( 'Paragraph' );
+			expect( paragraphButton.icon ).to.equal( icon );
+			expect( paragraphButton.tooltip ).to.equal( true );
+		} );
+
+		it( 'should bind button to command', () => {
+			const paragraphButton = editor.ui.componentFactory.create( 'paragraph' );
+			const paragraphCommand = editor.commands.get( 'paragraph' );
+
+			expect( paragraphCommand.isEnabled ).to.be.true;
+			expect( paragraphButton.isEnabled ).to.be.true;
+
+			paragraphCommand.isEnabled = false;
+			expect( paragraphButton.isEnabled ).to.be.false;
+
+			expect( paragraphCommand.value ).to.be.true;
+			expect( paragraphButton.isOn ).to.be.true;
+
+			setData( editor.model, '<heading2>f{}oo</heading2>' );
+
+			expect( paragraphCommand.value ).to.be.false;
+			expect( paragraphButton.isOn ).to.be.false;
+		} );
+
+		it( 'should bind button execute to command execute', () => {
+			const pararaphButton = editor.ui.componentFactory.create( 'paragraph' );
+			const executeCommandSpy = sinon.spy( editor, 'execute' );
+
+			pararaphButton.fire( 'execute' );
+
+			sinon.assert.calledOnce( executeCommandSpy );
+			sinon.assert.calledWithExactly( executeCommandSpy, 'paragraph' );
+		} );
+	} );
+} );