Procházet zdrojové kódy

Tests: Rewritten tests for `CloudServices` using `Context`.

Szymon Cofalik před 5 roky
rodič
revize
bcfed402fc

+ 35 - 30
packages/ckeditor5-cloud-services/tests/cloudservices.js

@@ -6,6 +6,7 @@
 /* global document */
 
 import CloudServices from '../src/cloudservices';
+import Context from '@ckeditor/ckeditor5-core/src/context';
 import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
 import TokenMock from './_utils/tokenmock';
 
@@ -27,8 +28,8 @@ describe( 'CloudServices', () => {
 
 	describe( 'init()', () => {
 		it( 'should expose its properties based on config', () => {
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						tokenUrl: 'http://token-endpoint',
@@ -46,39 +47,48 @@ describe( 'CloudServices', () => {
 				} );
 		} );
 
-		it( 'should be able to get by its plugin name', () => {
+		it( 'should work as an editor plugin', () => {
 			return ClassicTestEditor
 				.create( element, {
-					plugins: [ CloudServices ]
+					plugins: [ CloudServices ],
+					cloudServices: {
+						tokenUrl: 'http://token-endpoint',
+						additionalOption: 'some-value'
+					}
 				} )
 				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( 'CloudServices' );
+					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+
 					expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
+					expect( cloudServicesPlugin.tokenUrl ).to.equal( 'http://token-endpoint' );
+					expect( cloudServicesPlugin.additionalOption ).to.equal( 'some-value' );
+
+					return editor.destroy();
 				} );
 		} );
 
+		it( 'should be able to get by its plugin name', () => {
+			return Context.create( { plugins: [ CloudServices ] } ).then( editor => {
+				const cloudServicesPlugin = editor.plugins.get( 'CloudServices' );
+				expect( cloudServicesPlugin ).to.be.instanceOf( CloudServices );
+			} );
+		} );
+
 		it( 'should not throw an error when no config is provided', () => {
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ]
-				} );
+			return Context.create( { plugins: [ CloudServices ] } );
 		} );
 
 		it( 'should not expose any default uploadUrl', () => {
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ]
-				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+			return Context.create( { plugins: [ CloudServices ] } ).then( editor => {
+				const cloudServicesPlugin = editor.plugins.get( CloudServices );
 
-					expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
-				} );
+				expect( cloudServicesPlugin.uploadUrl ).to.be.undefined;
+			} );
 		} );
 
 		it( 'should use provided uploadUrl', () => {
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						uploadUrl: 'https://some-upload-url/'
@@ -94,8 +104,8 @@ describe( 'CloudServices', () => {
 		it( 'should provide token if tokenUrl is provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
-			return ClassicTestEditor
-				.create( element, {
+			return Context
+				.create( {
 					plugins: [ CloudServices ],
 					cloudServices: {
 						tokenUrl: 'http://token-endpoint',
@@ -113,16 +123,11 @@ describe( 'CloudServices', () => {
 		it( 'should not provide token if tokenUrl is not provided', () => {
 			CloudServices.Token.initialToken = 'initial-token';
 
-			return ClassicTestEditor
-				.create( element, {
-					plugins: [ CloudServices ],
-					cloudServices: {}
-				} )
-				.then( editor => {
-					const cloudServicesPlugin = editor.plugins.get( CloudServices );
+			return Context.create( { plugins: [ CloudServices ] } ).then( editor => {
+				const cloudServicesPlugin = editor.plugins.get( CloudServices );
 
-					expect( cloudServicesPlugin.token ).to.equal( null );
-				} );
+				expect( cloudServicesPlugin.token ).to.equal( null );
+			} );
 		} );
 	} );
 } );