Răsfoiți Sursa

Tests: Renamed manual test for the creator. Added unit tests.

Aleksander Nowodzinski 9 ani în urmă
părinte
comite
cfbc907e97

+ 1 - 15
packages/ckeditor5-editor-classic/tests/classiccreator.html

@@ -1,17 +1,3 @@
 <head>
 	<link rel="stylesheet" href="%APPS_DIR%ckeditor/build/amd/theme/ckeditor.css">
-</head>
-
-<p>
-	<button id="destroyEditor">Destroy editor</button>
-	<button id="initEditor">Init editor</button>
-</p>
-
-<div id="editor">
-	<h1>Hello world!</h1>
-	<p>This is an editor instance.</p>
-</div>
-
-<div style="height: 1500px; width: 1500px; background: #eee; outline: 2px dashed #ddd; margin: 1em 0; padding: 1em;">
-	* I'm a dummy div to enable scrolling in this test. *
-</div>
+</head>

+ 165 - 29
packages/ckeditor5-editor-classic/tests/classiccreator.js

@@ -3,47 +3,183 @@
  * For licensing, see LICENSE.md.
  */
 
-/* global console:false */
+/* bender-tags: creator */
 
 'use strict';
 
-import CKEDITOR from '/ckeditor.js';
+import Editor from '/ckeditor5/editor.js';
+
+import BoxedEditorUI from '/ckeditor5/ui/boxededitorui/boxededitorui.js';
+import BoxedEditorUIView from '/ckeditor5/ui/boxededitorui/boxededitoruiview.js';
+
+import EditableUI from '/ckeditor5/ui/editableui/editableui.js';
+import InlineEditableUIView from '/ckeditor5/ui/editableui/inline/inlineeditableuiview.js';
+
+import StickyToolbar from '/ckeditor5/ui/bindings/stickytoolbar.js';
+import StickyToolbarView from '/ckeditor5/ui/stickytoolbar/stickytoolbarview.js';
+
+import StandardCreator from '/ckeditor5/creator/standardcreator.js';
 import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
-import testUtils from '/tests/utils/_utils/utils.js';
+import HtmlDataProcessor from '/ckeditor5/engine/dataprocessor/htmldataprocessor.js';
+
+import testUtils from '/tests/ckeditor5/_utils/utils.js';
+
+testUtils.createSinonSandbox();
+
+describe( 'ClassicCreator', () => {
+	let creator, editor, fooElement, barElement;
+
+	beforeEach( function() {
+		fooElement = document.createElement( 'div' );
+		fooElement.setAttribute( 'class', 'first' );
+		fooElement.setAttribute( 'data-test', this.currentTest.title );
+
+		document.body.appendChild( fooElement );
+
+		barElement = document.createElement( 'div' );
+		barElement.setAttribute( 'class', 'second' );
+		barElement.setAttribute( 'data-test', this.currentTest.title );
+
+		document.body.appendChild( barElement );
+
+		editor = new Editor(
+			{
+				foo: fooElement,
+				bar: barElement
+			},
+			{
+				toolbar: [ 'bold', 'italic' ]
+			}
+		);
+
+		creator = new ClassicCreator( editor, new HtmlDataProcessor() );
+	} );
+
+	describe( 'constructor', () => {
+		it( 'inherits from the StandardCreator', () => {
+			expect( creator ).to.be.instanceof( StandardCreator );
+		} );
+
+		it( 'creates a single instance of Editable ', () => {
+			expect( editor.editables ).to.have.length( 1 );
+			expect( editor.editables.get( 0 ).name ).to.equal( 'foo' );
+		} );
+
+		it( 'creates the UI using BoxedEditorUI classes', () => {
+			expect( editor.ui ).to.be.instanceof( BoxedEditorUI );
+			expect( editor.ui.view ).to.be.instanceof( BoxedEditorUIView );
+		} );
+
+		it( 'creates a single document root', () => {
+			expect( editor.document.rootNames ).to.have.members( [ 'foo' ] );
+		} );
+	} );
+
+	describe( 'create', () => {
+		it( 'returns a promise', () => {
+			expect( creator.create() ).to.be.instanceof( Promise );
+		} );
 
-let editor, editable, observer;
+		it( 'calls _replaceElement', () => {
+			const spy = testUtils.sinon.spy( creator, '_replaceElement' );
 
-function initEditor() {
-	CKEDITOR.create( '#editor', {
-		creator: ClassicCreator,
-		toolbar: [ 'bold', 'italic' ]
-	} )
-	.then( ( newEditor ) => {
-		console.log( 'Editor was initialized', newEditor );
-		console.log( 'You can now play with it using global `editor` and `editable` variables.' );
+			return creator.create().then( () => {
+				expect( spy.calledOnce ).to.be.true;
+			} );
+		} );
+
+		it( 'calls _createToolbar', () => {
+			const spy = testUtils.sinon.spy( creator, '_createToolbar' );
+
+			return creator.create().then( () => {
+				expect( spy.calledOnce ).to.be.true;
+			} );
+		} );
 
-		window.editor = editor = newEditor;
-		window.editable = editable = editor.editables.get( 0 );
+		it( 'creates the editable using EditableUI Controller in main region', () => {
+			return creator.create().then( () => {
+				expect( editor.ui.collections.get( 'main' ) ).to.have.length( 1 );
+				expect( editor.ui.collections.get( 'main' ).get( 0 ) ).to.be.instanceof( EditableUI );
+			} );
+		} );
+
+		it( 'creates the editable using InlineEditableUIView in main region', () => {
+			return creator.create().then( () => {
+				expect( editor.ui.collections.get( 'main' ).get( 0 ).view ).to.be.instanceof( InlineEditableUIView );
+			} );
+		} );
+
+		it( 'binds the editable to InlineEditableUIView', () => {
+			return creator.create().then( () => {
+				const editableUIView = editor.ui.collections.get( 'main' ).get( 0 ).view;
+
+				expect( editor.editables.get( 0 ).domElement ).to.equal( editableUIView.element );
+			} );
+		} );
+
+		it( 'initializes the editor.ui', () => {
+			const spy = testUtils.sinon.spy( editor.ui, 'init' );
+
+			return creator.create().then( () => {
+				expect( spy.calledOnce ).to.be.true;
+			} );
+		} );
 
-		observer = testUtils.createObserver();
-		observer.observe( 'Editable', editable );
+		it( 'calls loadDataFromEditorElement', () => {
+			const spy = testUtils.sinon.spy( creator, 'loadDataFromEditorElement' );
+
+			return creator.create().then( () => {
+				expect( spy.calledOnce ).to.be.true;
+			} );
+		} );
 	} );
-}
 
-function destroyEditor() {
-	editor.destroy()
-		.then( () => {
-			window.editor = editor = null;
-			window.editable = editable = null;
+	describe( 'destroy', () => {
+		it( 'returns a promise', () => {
+			return creator.create().then( () => {
+				expect( creator.destroy() ).to.be.instanceof( Promise );
+			} );
+		} );
+
+		it( 'destroys parent class', () => {
+			const spy = testUtils.sinon.spy( StandardCreator.prototype, 'destroy' );
+
+			return creator.create().then( () => {
+				return creator.destroy().then( () => {
+					expect( spy.calledOnce ).to.be.true;
+				} );
+			} );
+		} );
+
+		it( 'calls updateEditorElement', () => {
+			const spy = testUtils.sinon.spy( creator, 'updateEditorElement' );
 
-			observer.stopListening();
-			observer = null;
+			return creator.create().then( () => {
+				return creator.destroy().then( () => {
+					expect( spy.calledOnce ).to.be.true;
+				} );
+			} );
+		} );
 
-			console.log( 'Editor was destroyed' );
+		it( 'destroys the UI', () => {
+			return creator.create().then( () => {
+				return creator.destroy().then( () => {
+					expect( editor.ui.collections ).to.be.null;
+				} );
+			} );
 		} );
-}
+	} );
 
-document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
-document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
+	describe( '_createToolbar', () => {
+		it( 'creates toolbar using StickyToolbar and StickyToolbarView', () => {
+			return creator.create().then( () => {
+				expect( editor.ui.collections.get( 'top' ) ).to.have.length( 1 );
 
-initEditor();
+				const toolbar = editor.ui.collections.get( 'top' ).get( 0 );
+
+				expect( toolbar ).to.be.instanceof( StickyToolbar );
+				expect( toolbar.view ).to.be.instanceof( StickyToolbarView );
+			} );
+		} );
+	} );
+} );

+ 17 - 0
packages/ckeditor5-editor-classic/tests/manual/classiccreator.html

@@ -0,0 +1,17 @@
+<head>
+	<link rel="stylesheet" href="%APPS_DIR%ckeditor/build/amd/theme/ckeditor.css">
+</head>
+
+<p>
+	<button id="destroyEditor">Destroy editor</button>
+	<button id="initEditor">Init editor</button>
+</p>
+
+<div id="editor">
+	<h1>Hello world!</h1>
+	<p>This is an editor instance.</p>
+</div>
+
+<div style="height: 1500px; width: 1500px; background: #eee; outline: 2px dashed #ddd; margin: 1em 0; padding: 1em;">
+	* I'm a dummy div to enable scrolling in this test. *
+</div>

+ 49 - 0
packages/ckeditor5-editor-classic/tests/manual/classiccreator.js

@@ -0,0 +1,49 @@
+/**
+ * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+/* global console:false */
+
+'use strict';
+
+import CKEDITOR from '/ckeditor.js';
+import ClassicCreator from '/ckeditor5/creator-classic/classiccreator.js';
+import testUtils from '/tests/utils/_utils/utils.js';
+
+let editor, editable, observer;
+
+function initEditor() {
+	CKEDITOR.create( '#editor', {
+		creator: ClassicCreator,
+		toolbar: [ 'bold', 'italic' ]
+	} )
+	.then( ( newEditor ) => {
+		console.log( 'Editor was initialized', newEditor );
+		console.log( 'You can now play with it using global `editor` and `editable` variables.' );
+
+		window.editor = editor = newEditor;
+		window.editable = editable = editor.editables.get( 0 );
+
+		observer = testUtils.createObserver();
+		observer.observe( 'Editable', editable );
+	} );
+}
+
+function destroyEditor() {
+	editor.destroy()
+		.then( () => {
+			window.editor = editor = null;
+			window.editable = editable = null;
+
+			observer.stopListening();
+			observer = null;
+
+			console.log( 'Editor was destroyed' );
+		} );
+}
+
+document.getElementById( 'initEditor' ).addEventListener( 'click', initEditor );
+document.getElementById( 'destroyEditor' ).addEventListener( 'click', destroyEditor );
+
+initEditor();

+ 0 - 0
packages/ckeditor5-editor-classic/tests/classiccreator.md → packages/ckeditor5-editor-classic/tests/manual/classiccreator.md