Ver código fonte

Added util for createing view root for tests.

Oskar Wróbel 8 anos atrás
pai
commit
4f48f8a38d

+ 24 - 0
packages/ckeditor5-engine/tests/view/_utils/createroot.js

@@ -0,0 +1,24 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import RootEditableElement from '../../../src/view/rooteditableelement';
+
+/**
+ * Creates view root element and sets it to {@link module:engine/view/document~Document#roots roots collection}.
+ *
+ * @param {module:engine/view/document~Document} doc View document.
+ * @param {String} name Root element name.
+ * @param {String} rootName Root name.
+ * @returns {module:engine/view/rooteditableelement~RootEditableElement} Root element.
+ */
+export default function createRoot( doc, name = 'div', rootName = 'main' ) {
+	const root = new RootEditableElement( name );
+
+	root.document = doc;
+	root.rootName = rootName;
+	doc.roots.add( root );
+
+	return root;
+}

+ 38 - 0
packages/ckeditor5-engine/tests/view/utils-tests/createroot.js

@@ -0,0 +1,38 @@
+/**
+ * @license Copyright (c) 2003-2017, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md.
+ */
+
+import Document from '../../../src/view/document.js';
+import RootAttributeElement from '../../../src/view/rooteditableelement.js';
+import createRoot from '../_utils/createroot.js';
+
+describe( 'createRoot', () => {
+	let viewDoc;
+
+	beforeEach( () => {
+		viewDoc = new Document();
+	} );
+
+	it( 'should create view root element with given data', () => {
+		const root = createRoot( viewDoc, 'h1', 'header' );
+
+		expect( root ).to.instanceof( RootAttributeElement );
+		expect( root.name ).to.equal( 'h1' );
+		expect( root.rootName ).to.equal( 'header' );
+	} );
+
+	it( 'should create view root element with default data', () => {
+		const root = createRoot( viewDoc );
+
+		expect( root ).to.instanceof( RootAttributeElement );
+		expect( root.name ).to.equal( 'div' );
+		expect( root.rootName ).to.equal( 'main' );
+	} );
+
+	it( 'should insert root element to view document roots collection', () => {
+		const root = createRoot( viewDoc );
+
+		expect( viewDoc.getRoot() ).to.equal( root );
+	} );
+} );