Răsfoiți Sursa

Refactored tests.

Kamil Piechaczek 5 ani în urmă
părinte
comite
b5a2d00cc1
1 a modificat fișierele cu 128 adăugiri și 164 ștergeri
  1. 128 164
      packages/ckeditor5-link/tests/linkimageediting.js

+ 128 - 164
packages/ckeditor5-link/tests/linkimageediting.js

@@ -587,35 +587,57 @@ describe( 'LinkImageEditing', () => {
 		} );
 
 		describe( 'upcast converter', () => {
-			let editor;
-
-			it( 'should upcast attributes from initial data', async () => {
-				editor = await VirtualTestEditor.create( {
-					initialData: '<figure class="image"><a href="url" target="_blank" rel="noopener noreferrer" download="file">' +
-						'<img src="/assets/sample.png"></a></figure>',
-					plugins: [ Paragraph, LinkImageEditing ],
-					link: {
-						decorators: {
-							isExternal: {
-								mode: 'manual',
-								label: 'Open in a new window',
-								attributes: {
-									target: '_blank',
-									rel: 'noopener noreferrer'
-								}
-							},
-							isDownloadable: {
-								mode: 'manual',
-								label: 'Downloadable',
-								attributes: {
-									download: 'file'
+			let editor, model;
+
+			beforeEach( () => {
+				return VirtualTestEditor
+					.create( {
+						plugins: [ Paragraph, LinkImageEditing ],
+						link: {
+							decorators: {
+								isExternal: {
+									mode: 'manual',
+									label: 'Open in a new tab',
+									attributes: {
+										target: '_blank',
+										rel: 'noopener noreferrer'
+									}
+								},
+								isDownloadable: {
+									mode: 'manual',
+									label: 'Downloadable',
+									attributes: {
+										download: 'download'
+									}
+								},
+								isGallery: {
+									mode: 'manual',
+									label: 'Gallery link',
+									attributes: {
+										class: 'gallery'
+									}
 								}
 							}
 						}
-					}
-				} );
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+					} );
+			} );
 
-				model = editor.model;
+			afterEach( () => {
+				return editor.destroy();
+			} );
+
+			it( 'should upcast attributes', async () => {
+				editor.setData(
+					'<figure class="image">' +
+						'<a href="url" target="_blank" rel="noopener noreferrer" download="download">' +
+							'<img src="/assets/sample.png">' +
+						'</a>' +
+					'</figure>'
+				);
 
 				expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
 					'<image linkHref="url" linkIsDownloadable="true" linkIsExternal="true" src="/assets/sample.png"></image>'
@@ -625,67 +647,20 @@ describe( 'LinkImageEditing', () => {
 			} );
 
 			it( 'should not upcast partial and incorrect attributes', async () => {
-				editor = await VirtualTestEditor.create( {
-					initialData: '<figure class="image"><a href="url" target="_blank" rel="noopener noreferrer" download="something">' +
-						'<img src="/assets/sample.png"></a></figure>',
-					plugins: [ Paragraph, LinkImageEditing ],
-					link: {
-						decorators: {
-							isExternal: {
-								mode: 'manual',
-								label: 'Open in a new window',
-								attributes: {
-									target: '_blank',
-									rel: 'noopener noreferrer'
-								}
-							},
-							isDownloadable: {
-								mode: 'manual',
-								label: 'Downloadable',
-								attributes: {
-									download: 'file'
-								}
-							}
-						}
-					}
-				} );
-
-				model = editor.model;
+				editor.setData(
+					'<figure class="image">' +
+						'<a href="url" target="_blank" rel="noopener noreferrer" download="something">' +
+							'<img src="/assets/sample.png">' +
+						'</a>' +
+					'</figure>'
+				);
 
 				expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
 					'<image linkHref="url" linkIsExternal="true" src="/assets/sample.png"></image>'
 				);
-
-				await editor.destroy();
 			} );
 
-			it( 'allows overwriting conversion process using highest priority', async () => {
-				editor = await VirtualTestEditor.create( {
-					initialData: '',
-					plugins: [ Paragraph, LinkImageEditing ],
-					link: {
-						decorators: {
-							isExternal: {
-								mode: 'manual',
-								label: 'Open in a new window',
-								attributes: {
-									target: '_blank',
-									rel: 'noopener noreferrer'
-								}
-							},
-							isDownloadable: {
-								mode: 'manual',
-								label: 'Downloadable',
-								attributes: {
-									download: 'file'
-								}
-							}
-						}
-					}
-				} );
-
-				model = editor.model;
-
+			it( 'allows overwriting conversion process using highest priority', () => {
 				// Block manual decorator converter. Consume all attributes and do nothing with them.
 				editor.conversion.for( 'upcast' ).add( dispatcher => {
 					dispatcher.on( 'element:a', ( evt, data, conversionApi ) => {
@@ -706,85 +681,35 @@ describe( 'LinkImageEditing', () => {
 				);
 
 				expect( editor.getData() ).to.equal( '<figure class="image"><a href="url"><img src="/assets/sample.png"></a></figure>' );
-
-				await editor.destroy();
 			} );
-		} );
-	} );
 
-	describe( 'integration', () => {
-		let editor, model;
-
-		beforeEach( () => {
-			return VirtualTestEditor
-				.create( {
-					plugins: [ Paragraph, LinkImageEditing ],
-					link: {
-						decorators: {
-							isExternal: {
-								mode: 'manual',
-								label: 'Open in a new tab',
-								attributes: {
-									target: '_blank',
-									rel: 'noopener noreferrer'
-								}
-							},
-							isDownloadable: {
-								mode: 'manual',
-								label: 'Downloadable',
-								attributes: {
-									download: 'download'
-								}
-							},
-							isGallery: {
-								mode: 'manual',
-								label: 'Gallery link',
-								attributes: {
-									class: 'gallery'
-								}
-							}
-						}
-					}
-				} )
-				.then( newEditor => {
-					editor = newEditor;
-					model = editor.model;
-				} );
-		} );
-
-		afterEach( () => {
-			return editor.destroy();
-		} );
-
-		// See: #7975.
-		describe( 'manual decorators: linked text and linked image', () => {
 			it( 'should upcast the decorators when linked image (figure > a > img)', () => {
 				editor.setData(
 					'<figure class="image">' +
-						'<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
-							'<img src="sample.jpg" alt="bar">' +
-						'</a>' +
-						'<figcaption>Caption</figcaption>' +
+					'<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
+					'<img src="sample.jpg" alt="bar">' +
+					'</a>' +
+					'<figcaption>Caption</figcaption>' +
 					'</figure>' +
 					'<p>' +
-						'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
-							'https://cksource.com' +
-						'</a>' +
+					'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
+					'https://cksource.com' +
+					'</a>' +
 					'</p>'
 				);
 
 				expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
 					'<image alt="bar" ' +
-						'linkHref="https://cksource.com" ' +
-						'linkIsDownloadable="true" ' +
-						'linkIsExternal="true" ' +
-						'linkIsGallery="true" ' +
-						'src="sample.jpg">' +
+					'linkHref="https://cksource.com" ' +
+					'linkIsDownloadable="true" ' +
+					'linkIsExternal="true" ' +
+					'linkIsGallery="true" ' +
+					'src="sample.jpg">' +
 					'</image>' +
 					'<paragraph>' +
-						'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
-							'https://cksource.com' +
-						'</$text>' +
+					'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
+					'https://cksource.com' +
+					'</$text>' +
 					'</paragraph>'
 				);
 			} );
@@ -792,44 +717,84 @@ describe( 'LinkImageEditing', () => {
 			it( 'should upcast the decorators when linked image (a > img)', () => {
 				editor.setData(
 					'<a class="gallery" href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
-						'<img src="sample.jpg" alt="bar">' +
+					'<img src="sample.jpg" alt="bar">' +
 					'</a>' +
 					'<p>' +
-						'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
-							'https://cksource.com' +
-						'</a>' +
+					'<a href="https://cksource.com" target="_blank" rel="noopener noreferrer" download="download">' +
+					'https://cksource.com' +
+					'</a>' +
 					'</p>'
 				);
 
 				expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
 					'<image alt="bar" ' +
-						'linkHref="https://cksource.com" ' +
-						'linkIsDownloadable="true" ' +
-						'linkIsExternal="true" ' +
-						'linkIsGallery="true" ' +
-						'src="sample.jpg">' +
+					'linkHref="https://cksource.com" ' +
+					'linkIsDownloadable="true" ' +
+					'linkIsExternal="true" ' +
+					'linkIsGallery="true" ' +
+					'src="sample.jpg">' +
 					'</image>' +
 					'<paragraph>' +
-						'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
-							'https://cksource.com' +
-						'</$text>' +
+					'<$text linkHref="https://cksource.com" linkIsDownloadable="true" linkIsExternal="true">' +
+					'https://cksource.com' +
+					'</$text>' +
 					'</paragraph>'
 				);
 			} );
+		} );
+
+		describe( 'downcast converter', () => {
+			let editor, model;
+
+			beforeEach( () => {
+				return VirtualTestEditor
+					.create( {
+						plugins: [ Paragraph, LinkImageEditing ],
+						link: {
+							decorators: {
+								isExternal: {
+									mode: 'manual',
+									label: 'Open in a new tab',
+									attributes: {
+										target: '_blank',
+										rel: 'noopener noreferrer'
+									}
+								},
+								isDownloadable: {
+									mode: 'manual',
+									label: 'Downloadable',
+									attributes: {
+										download: 'download'
+									}
+								},
+								isGallery: {
+									mode: 'manual',
+									label: 'Gallery link',
+									attributes: {
+										class: 'gallery'
+									}
+								}
+							}
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+					} );
+			} );
+
+			afterEach( () => {
+				return editor.destroy();
+			} );
 
 			it( 'should downcast the decorators after applying a change', () => {
 				setModelData( model,
-					'<image alt="bar" src="sample.jpg"></image>' +
+					'[<image alt="bar" src="sample.jpg"></image>]' +
 					'<paragraph>' +
 						'<$text>https://cksource.com</$text>' +
 					'</paragraph>'
 				);
 
-				model.change( writer => {
-					// <image>
-					writer.setSelection( model.document.getRoot().getChild( 0 ), 'on' );
-				} );
-
 				editor.execute( 'link', 'https://cksource.com', {
 					linkIsDownloadable: true,
 					linkIsExternal: true,
@@ -837,7 +802,6 @@ describe( 'LinkImageEditing', () => {
 				} );
 
 				model.change( writer => {
-					// <$text>
 					writer.setSelection( model.document.getRoot().getChild( 1 ).getChild( 0 ), 'on' );
 				} );