8
0
Просмотр исходного кода

Add unit test for upcast converter and extend manual test with them as well

Mateusz Samsel 6 лет назад
Родитель
Сommit
0a708a9c64

+ 84 - 0
packages/ckeditor5-link/tests/linkediting.js

@@ -587,5 +587,89 @@ describe( 'LinkEditing', () => {
 				expect( editor.getData() ).to.equal( '<p><a href="http://example.com">foo</a>bar</p>' );
 				expect( editor.getData() ).to.equal( '<p><a href="http://example.com">foo</a>bar</p>' );
 			} );
 			} );
 		} );
 		} );
+
+		describe( 'upcast converter', () => {
+			it( 'attributes from initial data are upcast to model', done => {
+				VirtualTestEditor
+					.create( {
+						initialData: '<p><a href="url" target="_blank" rel="noopener noreferrer" download="file">Foo</a>' +
+							'<a href="example.com" download="file">Bar</a></p>',
+						plugins: [ Paragraph, LinkEditing, Enter ],
+						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'
+									}
+								}
+							}
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+
+						expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
+							'<paragraph>' +
+								'<$text linkHref="url" linkIsDownloadable="true" linkIsExternal="true">Foo</$text>' +
+								'<$text linkHref="example.com" linkIsDownloadable="true">Bar</$text>' +
+							'</paragraph>'
+						);
+					} )
+					.then( done )
+					.catch( done );
+			} );
+
+			it( 'partial and incorrect attributes are not upcast to the model', done => {
+				VirtualTestEditor
+					.create( {
+						initialData: '<p><a href="url" target="_blank" download="something">Foo</a>' +
+							'<a href="example.com" download="test">Bar</a></p>',
+						plugins: [ Paragraph, LinkEditing, Enter ],
+						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'
+									}
+								}
+							}
+						}
+					} )
+					.then( newEditor => {
+						editor = newEditor;
+						model = editor.model;
+
+						expect( getModelData( model, { withoutSelection: true } ) ).to.equal(
+							'<paragraph>' +
+								'<$text linkHref="url">Foo</$text>' +
+								'<$text linkHref="example.com">Bar</$text>' +
+							'</paragraph>'
+						);
+					} )
+					.then( done )
+					.catch( done );
+			} );
+		} );
 	} );
 	} );
 } );
 } );

+ 4 - 4
packages/ckeditor5-link/tests/manual/linkdecorator.html

@@ -1,11 +1,11 @@
 <h2>Manual decorators</h2>
 <h2>Manual decorators</h2>
 <div id="editor">
 <div id="editor">
-	<p>This is <a href="http://ckeditor.com">CKEditor5</a> from <a href="http://cksource.com">CKSource</a>.</p>
-	<p>This is <a href="//ckeditor.com">CKEditor5</a> as schemaless url.</p>
+	<p>This is <a href="http://ckeditor.com" target="_blank" rel="noopener noreferrer">CKEditor5</a> from <a href="http://cksource.com" download="download" target="_blank" rel="noopener noreferrer" >CKSource</a>.</p>
+	<p>This is <a href="//ckeditor.com" class="gallery">CKEditor5</a> as schemaless url.</p>
 	<p>This is <a href="#anchor">anchor</a> on this page.</p>
 	<p>This is <a href="#anchor">anchor</a> on this page.</p>
-	<p>This is some random <a href="ftp://127.0.0.1">ftp address</a>.</p>
+	<p>This is some random <a href="ftp://127.0.0.1" download="download">ftp address</a>.</p>
 	<p>This is some <a href="mailto:random@user.org">mail</a>.</p>
 	<p>This is some <a href="mailto:random@user.org">mail</a>.</p>
-	<p>This is some <a href="tel:123456789">phone number</a>.</p>
+	<p>This is some <a href="tel:123456789">phone number</a> with gallery decorator</p>
 </div>
 </div>
 
 
 <h2>Automatic decorators</h2>
 <h2>Automatic decorators</h2>

+ 8 - 3
packages/ckeditor5-link/tests/manual/linkdecorator.md

@@ -4,12 +4,17 @@
 
 
 1. Should be available for every link.
 1. Should be available for every link.
 2. Should be applied to the content only when "Save" was clicked.
 2. Should be applied to the content only when "Save" was clicked.
-3. There should be 3 manual decorators available:
+3. There should be initially set some decorators over specific links based on source data of the editor:
+  * `CKEditor5` has: "Open in a new window"
+  * `CKSource` has: "Open in a new window" and "Downloadable"
+  * `CKEditor5` (schemaless) has: "Gallery"
+  * `ftp address` has: "Downloadable"
+4. There should be 3 manual decorators available:
   * Open in new a new tab
   * Open in new a new tab
   * Downloadable
   * Downloadable
   * Gallery link
   * Gallery link
-4. State of the decorator switches should reflect the model of the currently selected link.
-5. Switch buttons should be focusable (with the tab key), after the URL input. The "save" and "cancel" buttons should be focused last.
+5. State of the decorator switches should reflect the model of the currently selected link.
+6. Switch buttons should be focusable (with the tab key), after the URL input. The "save" and "cancel" buttons should be focused last.
 
 
 ### Automatic decorators (window.editors.automaticDecorators).
 ### Automatic decorators (window.editors.automaticDecorators).