瀏覽代碼

Tests: Tests for `Context.builtinPlugins` and `Context.defaultConfig`.

Szymon Cofalik 5 年之前
父節點
當前提交
c22b250eaa
共有 1 個文件被更改,包括 66 次插入0 次删除
  1. 66 0
      packages/ckeditor5-core/tests/context.js

+ 66 - 0
packages/ckeditor5-core/tests/context.js

@@ -296,4 +296,70 @@ describe( 'Context', () => {
 			await editor.destroy();
 		} );
 	} );
+
+	describe( 'builtinPlugins', () => {
+		class PluginA extends ContextPlugin {}
+		class PluginB extends ContextPlugin {}
+		class PluginC extends ContextPlugin {}
+
+		beforeEach( () => {
+			Context.builtinPlugins = [ PluginA, PluginB, PluginC ];
+		} );
+
+		afterEach( () => {
+			delete Context.builtinPlugins;
+		} );
+
+		it( 'should load plugins built in the Context even if the passed config is empty', () => {
+			const context = new Context();
+
+			return context.initPlugins()
+				.then( () => {
+					expect( getPlugins( context ).length ).to.equal( 3 );
+
+					expect( context.plugins.get( PluginA ) ).to.be.an.instanceof( ContextPlugin );
+					expect( context.plugins.get( PluginB ) ).to.be.an.instanceof( ContextPlugin );
+					expect( context.plugins.get( PluginC ) ).to.be.an.instanceof( ContextPlugin );
+				} );
+		} );
+
+		it( 'should load plugins provided in the config and should ignore plugins built in the Editor', () => {
+			const context = new Context( {
+				plugins: [
+					PluginA
+				]
+			} );
+
+			return context.initPlugins()
+				.then( () => {
+					expect( getPlugins( context ).length ).to.equal( 1 );
+
+					expect( context.plugins.get( PluginA ) ).to.be.an.instanceof( ContextPlugin );
+				} );
+		} );
+	} );
+
+	describe( 'defaultConfig', () => {
+		beforeEach( () => {
+			Context.defaultConfig = { foo: 1, bar: 2 };
+		} );
+
+		afterEach( () => {
+			delete Context.defaultConfig;
+		} );
+
+		it( 'should extend an editor configuration using built in config', () => {
+			const context = new Context( {
+				foo: 4
+			} );
+
+			expect( context.config.get( 'foo' ) ).to.equal( 4 );
+			expect( context.config.get( 'bar' ) ).to.equal( 2 );
+		} );
+	} );
 } );
+
+function getPlugins( editor ) {
+	return Array.from( editor.plugins )
+		.map( entry => entry[ 1 ] ); // Get instances.
+}