Explorar o código

Tests: Added some integration tests for percent-based resizing.

Marek Lewandowski %!s(int64=6) %!d(string=hai) anos
pai
achega
ff4f046372
Modificáronse 1 ficheiros con 66 adicións e 0 borrados
  1. 66 0
      packages/ckeditor5-image/tests/imageresize.js

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

@@ -435,6 +435,72 @@ describe( 'ImageResize', () => {
 		}
 	} );
 
+	describe( 'percent resizing', () => {
+		describe( 'standard image', () => {
+			beforeEach( async () => {
+				await editor.destroy();
+
+				editor = await ClassicEditor
+					.create( editorElement, {
+						plugins: [ Image, ImageStyle, Paragraph, Undo, Table, ImageResize ]
+					} );
+
+				setData( editor.model, `<paragraph>foo</paragraph>[<image src="${ IMAGE_SRC_FIXTURE }"></image>]` );
+
+				view = editor.editing.view;
+				viewDocument = view.document;
+				widget = viewDocument.getRoot().getChild( 1 );
+			} );
+
+			it( 'shrinks correctly with left-bottom handler', generateResizeTest( {
+				expectedWidth: 16,
+				modelRegExp: /<paragraph>foo<\/paragraph><image src=".+?" width="([\d]{2}(?:\.[\d]{1,2}))%"><\/image>/,
+				pointerOffset: {
+					x: 10,
+					y: -10
+				},
+				resizerPosition: 'bottom-left'
+			} ) );
+
+			it( 'enlarges correctly with right-bottom handler', generateResizeTest( {
+				expectedWidth: 22,
+				modelRegExp: /<paragraph>foo<\/paragraph><image src=".+?" width="([\d]{2}(?:\.[\d]{1,2}))%"><\/image>/,
+				pointerOffset: {
+					x: 0,
+					y: 5
+				},
+				resizerPosition: 'bottom-right'
+			} ) );
+		} );
+
+		describe( 'side image', () => {
+			beforeEach( async () => {
+				await editor.destroy();
+
+				editor = await ClassicEditor
+					.create( editorElement, {
+						plugins: [ Image, ImageStyle, Paragraph, Undo, Table, ImageResize ]
+					} );
+
+				setData( editor.model, `<paragraph>foo</paragraph>[<image imageStyle="side" src="${ IMAGE_SRC_FIXTURE }"></image>]` );
+
+				view = editor.editing.view;
+				viewDocument = view.document;
+				widget = viewDocument.getRoot().getChild( 1 );
+			} );
+
+			it( 'shrinks correctly with left-bottom handler', generateResizeTest( {
+				expectedWidth: 18,
+				modelRegExp: /<paragraph>foo<\/paragraph><image imageStyle="side" src=".+?" width="([\d]{2}(?:\.[\d]{1,2}))%"><\/image>/,
+				pointerOffset: {
+					x: 10,
+					y: -10
+				},
+				resizerPosition: 'bottom-left'
+			} ) );
+		} );
+	} );
+
 	describe( 'undo integration', () => {
 		beforeEach( () => {
 			setData( editor.model, `<paragraph>foo</paragraph>[<image src="${ IMAGE_SRC_FIXTURE }"></image>]` );