8
0
Oskar Wróbel 6 лет назад
Родитель
Сommit
1ac6a83b01

+ 43 - 0
packages/ckeditor5-core/src/contextplugin.js

@@ -0,0 +1,43 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+/**
+ * @module core/contextplugin
+ */
+
+import ObservableMixin from '@ckeditor/ckeditor5-utils/src/observablemixin';
+import mix from '@ckeditor/ckeditor5-utils/src/mix';
+
+/**
+ * The base class for {@link module:core/context~Context} plugin classes.
+ *
+ * @implements module:core/plugin~PluginInterface
+ * @mixes module:utils/observablemixin~ObservableMixin
+ */
+export default class ContextPlugin {
+	/**
+	 * Creates a new plugin instance.
+	 *
+	 * @param {module:core/context~Context|module:core/editor/editor~Editor} context
+	 */
+	constructor( context ) {
+		/**
+		 * The context instance.
+		 *
+		 * @readonly
+		 * @type {module:core/context~Context|module:core/editor/editor~Editor}
+		 */
+		this.context = context;
+	}
+
+	/**
+	 * @inheritDoc
+	 */
+	destroy() {
+		this.stopListening();
+	}
+}
+
+mix( ContextPlugin, ObservableMixin );

+ 35 - 0
packages/ckeditor5-core/tests/contextplugin.js

@@ -0,0 +1,35 @@
+/**
+ * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
+ * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
+ */
+
+import ContextPlugin from '../src/contextplugin';
+
+describe( 'ContextPlugin', () => {
+	const contextMock = {};
+
+	describe( 'constructor()', () => {
+		it( 'should set the `context` property', () => {
+			const plugin = new ContextPlugin( contextMock );
+
+			expect( plugin ).to.have.property( 'context' ).to.equal( contextMock );
+		} );
+
+		describe( 'destroy()', () => {
+			it( 'should be defined', () => {
+				const plugin = new ContextPlugin( contextMock );
+
+				expect( plugin.destroy ).to.be.a( 'function' );
+			} );
+
+			it( 'should stop listening', () => {
+				const plugin = new ContextPlugin( contextMock );
+				const stopListeningSpy = sinon.spy( plugin, 'stopListening' );
+
+				plugin.destroy();
+
+				sinon.assert.calledOnce( stopListeningSpy );
+			} );
+		} );
+	} );
+} );