Skip to content
This repository has been archived by the owner on Jun 26, 2020. It is now read-only.

Fixed resizer initial percentage values for sie images #308

Merged
merged 10 commits into from
Oct 3, 2019
84 changes: 84 additions & 0 deletions tests/imageresize.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,90 @@ describe( 'ImageResize', () => {
}
} );

describe( 'percent resizing', () => {
describe( 'standard image', () => {
beforeEach( async () => {
await editor.destroy();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is odd. Please create the right editor for the specific describe block. Creating 2 editors for no reason is both confusing and slows down the tests.


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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This duplicates the code from the topmost beforeEach().

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'
} ) );

it( 'enlarges correctly an image with unsupported width unit', async () => {
setData( editor.model, `<paragraph>foo</paragraph>[<image src="${ IMAGE_SRC_FIXTURE }" width="50pt"></image>]` );

view = editor.editing.view;
viewDocument = view.document;
widget = viewDocument.getRoot().getChild( 1 );

await generateResizeTest( {
expectedWidth: 15,
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>]` );
Expand Down