Ver código fonte

Tests: Added unit tests for better code coverage.

Marek Lewandowski 5 anos atrás
pai
commit
5f677e12db
1 arquivos alterados com 31 adições e 0 exclusões
  1. 31 0
      packages/ckeditor5-image/tests/imageresize.js

+ 31 - 0
packages/ckeditor5-image/tests/imageresize.js

@@ -28,6 +28,8 @@ import {
 	getHandleCenterPoint
 } from '@ckeditor/ckeditor5-widget/tests/widgetresize/_utils/utils';
 
+import WidgetResize from '@ckeditor/ckeditor5-widget/src/widgetresize';
+
 describe( 'ImageResize', () => {
 	// 100x50 black png image
 	const IMAGE_SRC_FIXTURE = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAAAyCAQAAAAAPLY1AAAAQklEQVR42u3PQREAAAgDoK1/' +
@@ -90,6 +92,19 @@ describe( 'ImageResize', () => {
 				.to.equal( `<figure class="image image_resized" style="width:50%;"><img src="${ IMAGE_SRC_FIXTURE }"></figure>` );
 		} );
 
+		it( 'removes style and extra class when no longer resized', () => {
+			setData( editor.model, `<image src="${ IMAGE_SRC_FIXTURE }" width="50%"></image>` );
+
+			const imageModel = editor.model.document.getRoot().getChild( 0 );
+
+			editor.model.change( writer => {
+				writer.removeAttribute( 'width', imageModel );
+			} );
+
+			expect( editor.getData() )
+				.to.equal( `<figure class="image"><img src="${ IMAGE_SRC_FIXTURE }"></figure>` );
+		} );
+
 		it( 'doesn\'t downcast consumed tokens', () => {
 			editor.conversion.for( 'downcast' ).add( dispatcher =>
 				dispatcher.on( 'attribute:width:image', ( evt, data, conversionApi ) => {
@@ -178,6 +193,20 @@ describe( 'ImageResize', () => {
 		} );
 	} );
 
+	it( 'uses percents by default', async () => {
+		const localEditor = await createEditor( {
+			plugins: [ Image, ImageStyle, Paragraph, Undo, Table, ImageResize ]
+		} );
+
+		const attachToSpy = sinon.spy( localEditor.plugins.get( WidgetResize ), 'attachTo' );
+
+		setData( localEditor.model, `[<image imageStyle="side" src="${ IMAGE_SRC_FIXTURE }"></image>]` );
+
+		expect( attachToSpy.args[ 0 ][ 0 ] ).to.have.a.property( 'unit', '%' );
+
+		attachToSpy.restore();
+	} );
+
 	describe( 'side image resizing', () => {
 		beforeEach( () => createEditor() );
 
@@ -428,6 +457,8 @@ describe( 'ImageResize', () => {
 				widget = viewDocument.getRoot().getChild( 1 );
 
 				focusEditor( editor );
+
+				return editor;
 			} );
 	}
 } );