-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Fix autogrow width issue #4393
Conversation
997aa01
to
95dec77
Compare
There was a problem hiding this 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.
tests/plugins/autogrow/autogrow.js
Outdated
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(); | ||
} ); | ||
} ); | ||
}; |
There was a problem hiding this comment.
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.
plugins/autogrow/plugin.js
Outdated
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ); | ||
var isBorderBox = boxSizingType === 'border-box'; | ||
|
||
var width = editor.container.getSize( 'width', isBorderBox ); |
There was a problem hiding this comment.
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.
tests/plugins/autogrow/autogrow.js
Outdated
@@ -8,7 +8,58 @@ | |||
|
|||
bender.editor = {}; | |||
|
|||
bender.createEditor = function( width, paragraphs ) { |
There was a problem hiding this comment.
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
.
tests/plugins/autogrow/autogrow.js
Outdated
'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 ); | ||
}, |
There was a problem hiding this comment.
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.
tests/plugins/autogrow/autogrow.js
Outdated
var initialEditorSize = autogrowTools.getEditorSize( editor ); | ||
|
||
editor.once( 'afterCommandExec', function() { | ||
resume( function name( params ) { |
There was a problem hiding this comment.
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.
Added manual test for this bug. |
There was a problem hiding this 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 |
There was a problem hiding this comment.
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 is4.15.2
. 7372
tag is invalid here. It should be the ticket number, so4372
in our case.
There was a problem hiding this comment.
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! :(
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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.
#### Expected result: | |
## Expected |
|
||
<script> | ||
var editor = CKEDITOR.replace( 'editor', { | ||
allowedContent: true, |
There was a problem hiding this comment.
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.
plugins/autogrow/plugin.js
Outdated
var boxSizingType = editor.container.getComputedStyle( 'box-sizing' ), | ||
isBorderBox = boxSizingType === 'border-box', | ||
width = editor.container.getSize( 'width', isBorderBox ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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, |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
@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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#### Unexpected result: | |
## Unexpected |
1. Focus inside editable window. | ||
2. Add or remove extra lines to force editor resize. | ||
3. Observe editor width. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With each vertical resize editor is shrinking for about margins + paddings. | |
With each vertical resize editor is shrinking for about 2 pixels. |
There was a problem hiding this comment.
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 :)
There was a problem hiding this 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.
That |
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
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.
What is the proposed changelog entry for this pull request?
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