8
0
فهرست منبع

Add basic tests for CKFinder plugins.

Maciej Gołaszewski 7 سال پیش
والد
کامیت
37543686c0

+ 45 - 1
packages/ckeditor5-ckfinder/tests/ckfinder.js

@@ -3,4 +3,48 @@
  * For licensing, see LICENSE.md.
  */
 
-describe( 'CKFinder', () => {} );
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import global from '@ckeditor/ckeditor5-utils/src/dom/global';
+
+import CKFinder from '../src/ckfinder';
+import CKFinderUI from '../src/ckfinderui';
+import CKFinderEditing from '../src/ckfinderediting';
+
+describe( 'CKFinder', () => {
+	let editorElement, editor;
+
+	beforeEach( () => {
+		editorElement = global.document.createElement( 'div' );
+		global.document.body.appendChild( editorElement );
+
+		return ClassicTestEditor
+			.create( editorElement, {
+				plugins: [ CKFinder ]
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	afterEach( () => {
+		editorElement.remove();
+
+		return editor.destroy();
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( CKFinder ) ).to.instanceOf( CKFinder );
+	} );
+
+	it( 'should load CKFinderUI plugin', () => {
+		expect( editor.plugins.get( CKFinderUI ) ).to.instanceOf( CKFinderUI );
+	} );
+
+	it( 'should load CKFinderEditing plugin', () => {
+		expect( editor.plugins.get( CKFinderEditing ) ).to.instanceOf( CKFinderEditing );
+	} );
+
+	it( 'has proper name', () => {
+		expect( CKFinder.pluginName ).to.equal( 'CKFinder' );
+	} );
+} );

+ 48 - 0
packages/ckeditor5-ckfinder/tests/ckfinderediting.js

@@ -0,0 +1,48 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import global from '@ckeditor/ckeditor5-utils/src/dom/global';
+import Command from '@ckeditor/ckeditor5-core/src/command';
+
+import CKFinder from '../src/ckfinder';
+import CKFinderEditing from '../src/ckfinderediting';
+
+describe( 'CKFinderEditing', () => {
+	let editorElement, editor;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		editorElement = global.document.createElement( 'div' );
+		global.document.body.appendChild( editorElement );
+
+		return ClassicTestEditor
+			.create( editorElement, {
+				plugins: [ CKFinder ]
+
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+			} );
+	} );
+
+	afterEach( () => {
+		editorElement.remove();
+
+		return editor.destroy();
+	} );
+
+	it( 'should be loaded', () => {
+		expect( editor.plugins.get( CKFinderEditing ) ).to.be.instanceOf( CKFinderEditing );
+	} );
+
+	it( 'should register command', () => {
+		const command = editor.commands.get( 'ckfinder' );
+
+		expect( command ).to.be.instanceOf( Command );
+	} );
+} );

+ 81 - 0
packages/ckeditor5-ckfinder/tests/ckfinderui.js

@@ -0,0 +1,81 @@
+/**
+ * @license Copyright (c) 2003-2018, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global window */
+
+import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
+import testUtils from '@ckeditor/ckeditor5-core/tests/_utils/utils';
+import global from '@ckeditor/ckeditor5-utils/src/dom/global';
+
+import ButtonView from '@ckeditor/ckeditor5-ui/src/button/buttonview';
+import ckfinderIcon from '@ckeditor/ckeditor5-ui/theme/icons/dropdown-arrow.svg';
+
+import CKFinder from '../src/ckfinder';
+
+describe( 'CKFinder', () => {
+	let editorElement, editor, button;
+
+	testUtils.createSinonSandbox();
+
+	beforeEach( () => {
+		editorElement = global.document.createElement( 'div' );
+		global.document.body.appendChild( editorElement );
+
+		return ClassicTestEditor
+			.create( editorElement, {
+				plugins: [ CKFinder ]
+
+			} )
+			.then( newEditor => {
+				editor = newEditor;
+				button = editor.ui.componentFactory.create( 'ckfinder' );
+			} );
+	} );
+
+	afterEach( () => {
+		editorElement.remove();
+
+		return editor.destroy();
+	} );
+
+	it( 'should add the "ckfinder" component to the factory', () => {
+		expect( button ).to.be.instanceOf( ButtonView );
+	} );
+
+	describe( 'button', () => {
+		it( 'should bind #isEnabled to the command', () => {
+			const command = editor.commands.get( 'ckfinder' );
+
+			expect( button.isEnabled ).to.be.true;
+
+			command.isEnabled = false;
+			expect( button.isEnabled ).to.be.false;
+		} );
+
+		it( 'should set a #label of the #buttonView', () => {
+			expect( button.label ).to.equal( 'CKFinder' );
+		} );
+
+		it( 'should set an #icon of the #buttonView', () => {
+			expect( button.icon ).to.equal( ckfinderIcon );
+		} );
+
+		it( 'should enable tooltips for the #buttonView', () => {
+			expect( button.tooltip ).to.be.true;
+		} );
+
+		it( 'should execute bold command on model execute event', () => {
+			window.CKFinder = {
+				modal: () => {}
+			};
+
+			const executeStub = testUtils.sinon.spy( editor, 'execute' );
+
+			button.fire( 'execute' );
+
+			sinon.assert.calledOnce( executeStub );
+		} );
+	} );
+} );