Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix autogrow width issue #4393

Merged
merged 12 commits into from
Nov 24, 2020
Merged

Fix autogrow width issue #4393

merged 12 commits into from
Nov 24, 2020

Conversation

sculpt0r
Copy link
Contributor

@sculpt0r sculpt0r commented Nov 23, 2020

What is the purpose of this pull request?

Bug fix

Does your PR contain necessary tests?

All patches that change the editor code must include tests. You can always read more
on PR testing,
how to set the testing environment and
how to create tests
in the official CKEditor documentation.

This PR contains

  • Unit tests
  • Manual tests

Did you follow the CKEditor 4 code style guide?

Your code should follow the guidelines from the CKEditor 4 code style guide which helps keep the entire codebase consistent.

  • PR is consistent with the code style guide

What is the proposed changelog entry for this pull request?

* [#4372](https://github.com/ckeditor/ckeditor4/issues/4372): Fixed: [Autogrow](https://ckeditor.com/cke4/addon/autogrow) plugin changes editor's width when used with absolute [`config.width`](https://ckeditor.com/docs/ckeditor4/latest/api/CKEDITOR_config.html#cfg-width) value. 

What changes did you make?

Give an overview…
Add tests for autogrow plugin with multiple width cases.
Change creation of width value for resizing. Based on this logic (#4372 (comment))

Which issues does your PR resolve?

Closes #4372

@sculpt0r sculpt0r changed the base branch from major to master November 23, 2020 07:37
@jacekbogdanski jacekbogdanski self-assigned this Nov 23, 2020
Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Please, add a manual test for the changes.

Comment on lines 11 to 36
bender.createEditor = function( width, paragraphs ) {
bender.editorBot.create( {
name: 'EditorWidth' + width,
config: {
width: width
}
}, function( bot ) {
bot.setData( autogrowTools.getTestContent( paragraphs ), function() {
var editor = bot.editor;
var initialEditorSize = autogrowTools.getEditorSize( editor );

editor.once( 'afterCommandExec', function() {
resume( function name( params ) {
var editorSize = autogrowTools.getEditorSize( editor );

assert.isTrue( editorSize.height > initialEditorSize.height, 'editor height should increase' );
assert.areEqual( editorSize.width, initialEditorSize.width, 'editor width should not change' );
} );
} );

editor.execCommand( 'autogrow' );

wait();
} );
} );
};
Copy link
Member

Choose a reason for hiding this comment

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

It's better to just create a separate helper method than extending existing objects we don't own, so we won't accidentally overwrite current or future API.

Comment on lines 151 to 154
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' );
var isBorderBox = boxSizingType === 'border-box';

var width = editor.container.getSize( 'width', isBorderBox );
Copy link
Member

Choose a reason for hiding this comment

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

We are declaring variables using a single var statement when possible. Please, join variables.

@@ -8,7 +8,58 @@

bender.editor = {};

bender.createEditor = function( width, paragraphs ) {
Copy link
Member

@jacekbogdanski jacekbogdanski Nov 23, 2020

Choose a reason for hiding this comment

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

This method does much more than creating an editor. It set up the whole testing environment and does assertions. Please, rename it into something more verbose, like testXXX.

Comment on lines 40 to 62
'test autogrow for editor width 200%': function() {
bender.createEditor( '200%', 6 );
},
// (#4372)
'test autogrow for editor width 20em': function() {
bender.createEditor( '20em', 6 );
},
// (#4372)
'test autogrow for editor width 200px': function() {
bender.createEditor( '200px', 6 );
},
// (#4372)
'test autogrow for editor width 200': function() {
bender.createEditor( 200, 6 );
},
// (#4372)
'test autogrow for editor width 0': function() {
bender.createEditor( 0, 6 );
},
// (#4372)
'test autogrow for editor width auto': function() {
bender.createEditor( 'auto', 6 );
},
Copy link
Member

Choose a reason for hiding this comment

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

Since we are not changing the number of paragraphs anywhere, maybe let's just hardcode it inside the test method? We could also choose a bit higher value to make sure to not depend on some edge case, like 10.

var initialEditorSize = autogrowTools.getEditorSize( editor );

editor.once( 'afterCommandExec', function() {
resume( function name( params ) {
Copy link
Member

Choose a reason for hiding this comment

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

params is not used, so could be omitted. We could skipname name also since it's not telling anything and we are using anonymous functions in most cases.

@sculpt0r
Copy link
Contributor Author

Please, add a manual test for the changes.

Added manual test for this bug.
Should I also edit PR to check 'Manual tests'?

Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Just some minor changes required.

@@ -0,0 +1,14 @@
@bender-tags: 4.15.1, bug, 7372
Copy link
Member

Choose a reason for hiding this comment

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

  • We are using some more descriptive names for manual tests, please see other manuals as an example. Here, we could go with autogrowboxsize.
  • We are at 4.15.1. version already. The upcoming release version for bugs is 4.15.2.
  • 7372 tag is invalid here. It should be the ticket number, so 4372 in our case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm confused about one thing:

We are at 4.15.1. version already. The upcoming release version for bugs is 4.15.2.

So I should tag it with a future version of the editor?

7372 tag is invalid here. It should be the ticket number, so 4372 in our case.

🙊 I mean it, so shame on me for this! :(

Copy link
Member

Choose a reason for hiding this comment

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

Yes, it should reflect the target release, not the current one, as we are not providing backward patches.

2. Add or remove extra lines to force editor resize.
3. Observe editor width.

#### Expected result:
Copy link
Member

Choose a reason for hiding this comment

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

Headings should follow the correct level depending on the context. Here, we should rather use the 2nd level heading as the first level is added automatically by the bender under Test steps. Also, let's unify a bit headings naming with Expected/Unexpected titles to follow the same convention as in other tests.

Suggested change
#### Expected result:
## Expected


<script>
var editor = CKEDITOR.replace( 'editor', {
allowedContent: true,
Copy link
Member

Choose a reason for hiding this comment

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

We are avoiding disabling ACF by setting allowedContent to true to mimic the standard editor configuration when possible. Since we are just using paragraphs for these manual tests, this line is not necessary.

Comment on lines 151 to 153
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ),
isBorderBox = boxSizingType === 'border-box',
width = editor.container.getSize( 'width', isBorderBox );
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ),
isBorderBox = boxSizingType === 'border-box',
width = editor.container.getSize( 'width', isBorderBox );
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ),
isBorderBox = boxSizingType === 'border-box',
width = editor.container.getSize( 'width', isBorderBox );

@@ -19,8 +19,36 @@ var autogrowTools = ( function() {
return html;
}

function testEditorSizeWithContent( editorWidth ) {
bender.editorBot.create( {
name: 'EditorWidth' + editorWidth,
Copy link
Member

Choose a reason for hiding this comment

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

Running this test twice with the same editorWidth will result in an error as we will try to create two editors with the same name. Since this test helper has been extracted as a separate tool method, maybe we could improve it by adding some more random editor name? As an example. you could use new Date().getTime() as it's really unlikely it will match milliseconds:

name: 'editor_' + new Date().getTime()

@@ -0,0 +1,14 @@
@bender-tags: 4.15.1, bug, 7372
@bender-ui: collapsed
@bender-ckeditor-plugins: wysiwygarea, autogrow
Copy link
Member

Choose a reason for hiding this comment

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

Let's add some minimal editor plugins, so the editor toolbar loads nicely.

Suggested change
@bender-ckeditor-plugins: wysiwygarea, autogrow
@bender-ckeditor-plugins: wysiwygarea, autogrow, basicstyles, toolbar, resize

#### Expected result:
The editor should have constant width. Only height is changing according to vertical amount of content.

#### Unexpected result:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#### Unexpected result:
## Unexpected

Comment on lines 6 to 8
1. Focus inside editable window.
2. Add or remove extra lines to force editor resize.
3. Observe editor width.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
1. Focus inside editable window.
2. Add or remove extra lines to force editor resize.
3. Observe editor width.
1. Focus the editor.
2. Press `enter` multiple times to force the editor to resize.

3. Observe editor width.

#### Expected result:
The editor should have constant width. Only height is changing according to vertical amount of content.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The editor should have constant width. Only height is changing according to vertical amount of content.
Editor width is not changing during auto-resize.

The editor should have constant width. Only height is changing according to vertical amount of content.

#### Unexpected result:
With each vertical resize editor is shrinking for about margins + paddings.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
With each vertical resize editor is shrinking for about margins + paddings.
With each vertical resize editor is shrinking for about 2 pixels.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That was my first thought. Later it comes to my mind (I may be over-obsessed) if the default margin and padding will change, those 2px will be invalid. Anyway, I apply suggestion :)

Copy link
Member

@jacekbogdanski jacekbogdanski left a comment

Choose a reason for hiding this comment

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

Looks good!

I've ignored unit tests on IE8 as they were failing for no good reason despite that the manual tests worked fine.

@sculpt0r
Copy link
Contributor Author

Looks good!

I've ignored unit tests on IE8 as they were failing for no good reason despite that the manual tests worked fine.

That IE thing... I have to remember to run tests on supported browsers. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Autogrow width issue
2 participants