Przeglądaj źródła

Correct unit test, add 'length' property to automaticdecorators class.

Mateusz Samsel 6 lat temu
rodzic
commit
aacd85e6fa

+ 0 - 1
packages/ckeditor5-link/src/linkediting.js

@@ -92,7 +92,6 @@ export default class LinkEditing extends Plugin {
 	enableAutomaticDecorators( automaticDecoratorDefinitions ) {
 		const editor = this.editor;
 		const automaticDecorators = new AutomaticDecorators();
-
 		// Adds default decorator for external links.
 		if ( editor.config.get( 'link.targetDecorator' ) ) {
 			automaticDecorators.add( {

+ 11 - 0
packages/ckeditor5-link/src/utils/automaticdecorators.js

@@ -22,6 +22,17 @@ export default class AutomaticDecorators {
 		this._definitions = new Set();
 	}
 
+	/**
+	 * Gives information how many decorators is stored in {@link module:link/utils/automaticdecorators~AutomaticDecorators} instance.
+	 *
+	 * @readonly
+	 * @protected
+	 * @type {Number}
+	 */
+	get length() {
+		return this._definitions.size;
+	}
+
 	/**
 	 * Add item or array of items with automatic rules for applying decorators to link plugin.
 	 *

+ 10 - 1
packages/ckeditor5-link/tests/linkediting.js

@@ -33,6 +33,10 @@ describe( 'LinkEditing', () => {
 			} );
 	} );
 
+	afterEach( () => {
+		editor.destroy();
+	} );
+
 	it( 'should be loaded', () => {
 		expect( editor.plugins.get( LinkEditing ) ).to.be.instanceOf( LinkEditing );
 	} );
@@ -393,8 +397,8 @@ describe( 'LinkEditing', () => {
 			} );
 
 			describe( 'for link.targetDecorator = false', () => {
+				let editor, model;
 				beforeEach( () => {
-					editor.destroy();
 					return VirtualTestEditor
 						.create( {
 							plugins: [ Paragraph, LinkEditing, Enter ],
@@ -408,6 +412,11 @@ describe( 'LinkEditing', () => {
 							view = editor.editing.view;
 						} );
 				} );
+
+				afterEach( () => {
+					editor.destroy();
+				} );
+
 				it( 'link.targetDecorator is set as true value', () => {
 					expect( editor.config.get( 'link.targetDecorator' ) ).to.be.true;
 				} );

+ 8 - 4
packages/ckeditor5-link/tests/utils/automaticdecorators.js

@@ -17,6 +17,10 @@ describe( 'Automatic Decorators', () => {
 		} );
 	} );
 
+	it( 'has length equal 0 after initialization', () => {
+		expect( automaticDecorators.length ).to.equal( 0 );
+	} );
+
 	describe( 'add()', () => {
 		const tests = [
 			{
@@ -44,10 +48,10 @@ describe( 'Automatic Decorators', () => {
 			}
 		];
 		it( 'can accept single object', () => {
-			expect( automaticDecorators._definitions.size ).to.equal( 0 );
+			expect( automaticDecorators.length ).to.equal( 0 );
 
 			automaticDecorators.add( tests[ 0 ] );
-			expect( automaticDecorators._definitions.size ).to.equal( 1 );
+			expect( automaticDecorators.length ).to.equal( 1 );
 
 			const firstValue = automaticDecorators._definitions.values().next().value;
 
@@ -62,11 +66,11 @@ describe( 'Automatic Decorators', () => {
 		} );
 
 		it( 'can accept array of objects', () => {
-			expect( automaticDecorators._definitions.size ).to.equal( 0 );
+			expect( automaticDecorators.length ).to.equal( 0 );
 
 			automaticDecorators.add( tests );
 
-			expect( automaticDecorators._definitions.size ).to.equal( 3 );
+			expect( automaticDecorators.length ).to.equal( 3 );
 
 			const setIterator = automaticDecorators._definitions.values();
 			setIterator.next();