Browse Source

Update unit test to follow new configuration of link decorators.

Mateusz Samsel 6 years ago
parent
commit
9394a6bc03

+ 25 - 25
packages/ckeditor5-link/tests/linkcommand.js

@@ -271,14 +271,14 @@ describe( 'LinkCommand', () => {
 					command = new LinkCommand( editor );
 
 					command.manualDecorators.add( new ManualDecorator( {
-						id: 'linkManualDecorator0',
+						id: 'linkDecoratorIsFoo',
 						label: 'Foo',
 						attributes: {
 							class: 'Foo'
 						}
 					} ) );
 					command.manualDecorators.add( new ManualDecorator( {
-						id: 'linkManualDecorator1',
+						id: 'linkDecoratorIsBar',
 						label: 'Bar',
 						attributes: {
 							target: '_blank'
@@ -287,7 +287,7 @@ describe( 'LinkCommand', () => {
 
 					model.schema.extend( '$text', {
 						allowIn: '$root',
-						allowAttributes: [ 'linkHref', 'linkManualDecorator0', 'linkManualDecorator1' ]
+						allowAttributes: [ 'linkHref', 'linkDecoratorIsFoo', 'linkDecoratorIsBar' ]
 					} );
 
 					model.schema.register( 'p', { inheritAllFrom: '$block' } );
@@ -302,25 +302,25 @@ describe( 'LinkCommand', () => {
 			it( 'should insert additional attributes to link when it is created', () => {
 				setData( model, 'foo[]bar' );
 
-				command.execute( 'url', { linkManualDecorator0: true, linkManualDecorator1: true } );
+				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'foo[<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true">url</$text>]bar' );
+					.equal( 'foo[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">url</$text>]bar' );
 			} );
 
 			it( 'should add additional attributes to link when link is modified', () => {
 				setData( model, 'f<$text linkHref="url">o[]oba</$text>r' );
 
-				command.execute( 'url', { linkManualDecorator0: true, linkManualDecorator1: true } );
+				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true">ooba</$text>]r' );
+					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
 			} );
 
 			it( 'should remove additional attributes to link if those are falsy', () => {
-				setData( model, 'foo<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true" >u[]rl</$text>bar' );
+				setData( model, 'foo<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">u[]rl</$text>bar' );
 
-				command.execute( 'url', { linkManualDecorator0: false, linkManualDecorator1: false } );
+				command.execute( 'url', { linkDecoratorIsFoo: false, linkDecoratorIsBar: false } );
 
 				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
@@ -330,25 +330,25 @@ describe( 'LinkCommand', () => {
 			it( 'should insert additional attributes to link when it is created', () => {
 				setData( model, 'f[ooba]r' );
 
-				command.execute( 'url', { linkManualDecorator0: true, linkManualDecorator1: true } );
+				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true">ooba</$text>]r' );
+					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
 			} );
 
 			it( 'should add additional attributes to link when link is modified', () => {
 				setData( model, 'f[<$text linkHref="foo">ooba</$text>]r' );
 
-				command.execute( 'url', { linkManualDecorator0: true, linkManualDecorator1: true } );
+				command.execute( 'url', { linkDecoratorIsFoo: true, linkDecoratorIsBar: true } );
 
 				expect( getData( model ) ).to
-					.equal( 'f[<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true">ooba</$text>]r' );
+					.equal( 'f[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">ooba</$text>]r' );
 			} );
 
 			it( 'should remove additional attributes to link if those are falsy', () => {
-				setData( model, 'foo[<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true" >url</$text>]bar' );
+				setData( model, 'foo[<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">url</$text>]bar' );
 
-				command.execute( 'url', { linkManualDecorator0: false, linkManualDecorator1: false } );
+				command.execute( 'url', { linkDecoratorIsFoo: false, linkDecoratorIsBar: false } );
 
 				expect( getData( model ) ).to.equal( 'foo[<$text linkHref="url">url</$text>]bar' );
 			} );
@@ -356,35 +356,35 @@ describe( 'LinkCommand', () => {
 
 		describe( 'restoreManualDecoratorStates()', () => {
 			it( 'synchronize values with current model state', () => {
-				setData( model, 'foo<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true" >u[]rl</$text>bar' );
+				setData( model, 'foo<$text linkDecoratorIsBar="true" linkDecoratorIsFoo="true" linkHref="url">u[]rl</$text>bar' );
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkManualDecorator0: true,
-					linkManualDecorator1: true
+					linkDecoratorIsFoo: true,
+					linkDecoratorIsBar: true
 				} );
 
 				command.manualDecorators.first.value = false;
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkManualDecorator0: false,
-					linkManualDecorator1: true,
+					linkDecoratorIsFoo: false,
+					linkDecoratorIsBar: true,
 				} );
 
 				command.restoreManualDecoratorStates();
 
 				expect( decoratorStates( command.manualDecorators ) ).to.deep.equal( {
-					linkManualDecorator0: true,
-					linkManualDecorator1: true,
+					linkDecoratorIsFoo: true,
+					linkDecoratorIsBar: true,
 				} );
 			} );
 		} );
 
 		describe( '_getDecoratorStateFromModel', () => {
 			it( 'obtain current values from the model', () => {
-				setData( model, 'foo[<$text linkHref="url" linkManualDecorator1="true" >url</$text>]bar' );
+				setData( model, 'foo[<$text linkDecoratorIsBar="true" linkHref="url">url</$text>]bar' );
 
-				expect( command._getDecoratorStateFromModel( 'linkManualDecorator0' ) ).to.be.false;
-				expect( command._getDecoratorStateFromModel( 'linkManualDecorator1' ) ).to.be.true;
+				expect( command._getDecoratorStateFromModel( 'linkDecoratorIsFoo' ) ).to.be.false;
+				expect( command._getDecoratorStateFromModel( 'linkDecoratorIsBar' ) ).to.be.true;
 			} );
 		} );
 	} );

+ 7 - 5
packages/ckeditor5-link/tests/linkediting.js

@@ -481,27 +481,29 @@ describe( 'LinkEditing', () => {
 							plugins: [ Paragraph, LinkEditing, Enter ],
 							link: {
 								addTargetToExternalLinks: false,
-								decorators: [
-									{
+								decorators: {
+									IsExternal: {
 										mode: 'automatic',
 										callback: url => url.startsWith( 'http' ),
 										attributes: {
 											target: '_blank'
 										}
-									}, {
+									},
+									IsDownloadable: {
 										mode: 'automatic',
 										callback: url => url.includes( 'download' ),
 										attributes: {
 											download: 'download'
 										}
-									}, {
+									},
+									IsMail: {
 										mode: 'automatic',
 										callback: url => url.startsWith( 'mailto:' ),
 										attributes: {
 											class: 'mail-url'
 										}
 									}
-								]
+								}
 							}
 						} )
 						.then( newEditor => {

+ 7 - 7
packages/ckeditor5-link/tests/linkui.js

@@ -969,15 +969,15 @@ describe( 'LinkUI', () => {
 						.create( editorElement, {
 							plugins: [ LinkEditing, LinkUI, Paragraph ],
 							link: {
-								decorators: [
-									{
+								decorators: {
+									IsFoo: {
 										mode: 'manual',
 										label: 'Foo',
 										attributes: {
 											foo: 'bar'
 										}
 									}
-								]
+								}
 							}
 						} )
 						.then( newEditor => {
@@ -1010,18 +1010,18 @@ describe( 'LinkUI', () => {
 				it( 'should gather information about manual decorators', () => {
 					const executeSpy = testUtils.sinon.spy( editor, 'execute' );
 
-					setModelData( model, 'f[<$text linkHref="url" linkManualDecorator0="true">ooba</$text>]r' );
+					setModelData( model, 'f[<$text linkHref="url" linkDecoratorIsFoo="true">ooba</$text>]r' );
 					expect( formView.urlInputView.inputView.element.value ).to.equal( 'url' );
-					expect( formView.getDecoratorSwitchesState() ).to.deep.equal( { linkManualDecorator0: true } );
+					expect( formView.getDecoratorSwitchesState() ).to.deep.equal( { linkDecoratorIsFoo: true } );
 
 					formView.fire( 'submit' );
 
 					expect( executeSpy.calledOnce ).to.be.true;
-					expect( executeSpy.calledWithExactly( 'link', 'url', { linkManualDecorator0: true } ) ).to.be.true;
+					expect( executeSpy.calledWithExactly( 'link', 'url', { linkDecoratorIsFoo: true } ) ).to.be.true;
 				} );
 
 				it( 'should reset switch state when form view is closed', () => {
-					setModelData( model, 'f[<$text linkHref="url" linkManualDecorator0="true">ooba</$text>]r' );
+					setModelData( model, 'f[<$text linkHref="url" linkDecoratorIsFoo="true">ooba</$text>]r' );
 
 					const manualDecorators = editor.commands.get( 'link' ).manualDecorators;
 					const firstDecoratorModel = manualDecorators.first;

+ 3 - 3
packages/ckeditor5-link/tests/ui/linkformview.js

@@ -309,15 +309,15 @@ describe( 'LinkFormView', () => {
 					toolbar: [ 'link' ],
 					language: 'pl',
 					link: {
-						decorators: [
-							{
+						decorators: {
+							IsExternal: {
 								mode: 'manual',
 								label: 'Open in a new tab',
 								attributes: {
 									target: '_blank'
 								}
 							}
-						]
+						}
 					}
 				} )
 				.then( newEditor => {

+ 6 - 6
packages/ckeditor5-link/tests/unlinkcommand.js

@@ -235,22 +235,22 @@ describe( 'UnlinkCommand', () => {
 			return ModelTestEditor.create( {
 				extraPlugins: [ LinkEditing ],
 				link: {
-					decorators: [
-						{
+					decorators: {
+						IsFoo: {
 							mode: 'manual',
 							label: 'Foo',
 							attributes: {
 								class: 'foo'
 							}
 						},
-						{
+						IsBar: {
 							mode: 'manual',
 							label: 'Bar',
 							attributes: {
 								target: '_blank'
 							}
 						}
-					]
+					}
 				}
 			} )
 				.then( newEditor => {
@@ -261,7 +261,7 @@ describe( 'UnlinkCommand', () => {
 
 					model.schema.extend( '$text', {
 						allowIn: '$root',
-						allowAttributes: 'linkHref'
+						allowAttributes: [ 'linkHref', 'linkDecoratorIsFoo', 'linkDecoratorIsBar' ]
 					} );
 
 					model.schema.register( 'p', { inheritAllFrom: '$block' } );
@@ -273,7 +273,7 @@ describe( 'UnlinkCommand', () => {
 		} );
 
 		it( 'should remove manual decorators from links together with linkHref', () => {
-			setData( model, '<$text linkHref="url" linkManualDecorator0="true" linkManualDecorator1="true" >f[]oobar</$text>' );
+			setData( model, '<$text linkHref="url" linkDecoratorIsFoo="true" linkDecoratorIsBar="true" >f[]oobar</$text>' );
 
 			command.execute();