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

Auto adding # to color from colordialog #580

Merged
merged 12 commits into from
Jul 5, 2017
Merged

Auto adding # to color from colordialog #580

merged 12 commits into from
Jul 5, 2017

Conversation

msamsel
Copy link
Contributor

@msamsel msamsel commented Jun 29, 2017

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

yes

This PR contains

  • Unit tests
  • Manual tests

What changes did you make?

There will be automatically added # to colour in colordialog plugin, if colour will be 3 or 6 hexadecimal digit.


Closes #607.

@msamsel msamsel changed the title T/565 Auto adding # to color from colordialog Jun 29, 2017
@Comandeer Comandeer self-requested a review June 30, 2017 09:51
@@ -22,6 +22,14 @@ CKEDITOR.dialog.add( 'colordialog', function( editor ) {
html: ' '
Copy link
Member

Choose a reason for hiding this comment

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

What is the purpose of the changes in this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Change allows on writing unit test for this bug-fix.

Generally writing test for it was very tricky. Problem appeared when ok button is pressed then method clearHighlight() is called. What throw an error because unit test doesn't highlight colour in dialog as user does.
So I just add if-statement which check if focus is defined and also rearrange variable declaration to pass JShint.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Color dialog hasn't got any unit test earlier.
This change:

if ( focused ) {
	focused.removeClass( focusedColorLightCls );
	focused.removeClass( focusedColorDarkCls );
}

Allows on making nice unit test which set up values but doesn't touch focused colour. So test don't throw up errors when only value exists without focusing it.

@@ -203,6 +203,11 @@ CKEDITOR.plugins.add( 'colorbutton', {
total = colors.length + ( moreColorsEnabled ? 2 : 1 );

var clickFn = CKEDITOR.tools.addFunction( function applyColorStyle( color, type ) {
// #565
Copy link
Member

Choose a reason for hiding this comment

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

Please add short comment explaining the change.

@@ -203,6 +203,11 @@ CKEDITOR.plugins.add( 'colorbutton', {
total = colors.length + ( moreColorsEnabled ? 2 : 1 );

var clickFn = CKEDITOR.tools.addFunction( function applyColorStyle( color, type ) {
// #565
if ( /^[0-9a-f]{3}([0-9a-f]{3})?$/i.test( color ) ) {
color = '#' + color;
Copy link
Member

Choose a reason for hiding this comment

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

IMO the fix is placed in incorrect plugin. I'd move it into colordialog one, inside onClose handler of the dialog.

@@ -0,0 +1,240 @@
/* bender-tags: editor,unit */
Copy link
Member

Choose a reason for hiding this comment

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

There's no need for unit tag.

@@ -0,0 +1,14 @@
@bender-tags: manual, tc, 4.8.0, feature, 565
Copy link
Member

Choose a reason for hiding this comment

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

There's no need for manual tag.

@mlewand
Copy link
Contributor

mlewand commented Jun 30, 2017

Ok to sum it up:

The fix should land in the colordialog plugin rather than in color button.

There's no question to that, as first of all the enhancement should propagate to all fetarues using colordialog, see "Cell Properties" dialog:

Cell Properties

Generally speaking it's not colorbutton's job to mess with color format (there are exception but I'll leave it for sake of simplicity).

This ticket will depend on #590, as AFAICS otherwise we'd have to duplicate this logic in colorbutton plugin.

Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

The solution works fine. Just a few things to polish in tests.

@@ -0,0 +1,121 @@
/* bender-tags: editor */
Copy link
Contributor

Choose a reason for hiding this comment

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

Remember to always put unit tag if it is an unit test.

Copy link
Contributor

Choose a reason for hiding this comment

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

So we discussed this once again, if unit tag is not needed (not used by bender) it should be skipped.

@@ -0,0 +1,13 @@
@bender-tags: tc, feature, colordialog, 565, 4.8.0
@bender-ui: collapsed
@bender-ckeditor-plugins: table,tabletools,colordialog,toolbar,wysiwygarea,sourcearea,contextmenu
Copy link
Contributor

Choose a reason for hiding this comment

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

Is sourcearea plugin really needed here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It might be helpful when you wish to check what was included to attribute of tag. E.g. if there will be some invalid string or colour hard to distinguish from others, then checking source might be helpful.

1. Choose background color.
1. Type color in hexadecimal 6-digit format **without** leading `#`. E.g. (`ABC123`).
1. Confirm it.
1. Inseted color should contain additional `#` at the beginning.
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo: Inseted -> Inserted

1. Inseted color should contain additional `#` at the beginning.
1. Repeat above steps for color with hexadecimal 3-digits format. E.g. (`FFF`).

Note: You can also check some wrong situations.
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be not clear what is wrong situation. You could rephrase it like:

You can also check with colors in different formats (rgb, text) or invalid hex strings. For such colors # should not be added.

@@ -0,0 +1,13 @@
@bender-tags: tc, feature, colordialog, 565, 4.8.0
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we do not use feature tag (unless it was added recently)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As it was discussed some time ago there should either bug or feature tag? Or does it change since then?

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm not up to date - if it was discussed with @mlewand or @Comandeer in the last 2-3 weeks it means it should be that way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It was discussed around 12 - 13 June on ckeditor4-chat. I made some kind of sum up for us as pinned post to ckeditor4-chat.


bender.editor = {};

var test = {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is no need to assign it to a variable, you can just write it asbender.test( { ... } ).

},

'test colordialog does not add hash empty value': function() {
var editor = this.editor;
Copy link
Contributor

Choose a reason for hiding this comment

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

All tests have very similar body, maybe it could be extracted to a separate function like assertColor( editor, initialColor, expectedColor ) and then each test will be a one liner, e.g. assertColor( this.editor, '123456', '#123456').

If you put the function inside test object you can even omit editor param because of the same scope so this.editor will be available there.

wait();
},

'test colordialog does not add hash 1 digit': function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

This test fails on IE8.

@f1ames f1ames self-requested a review July 5, 2017 07:17
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

Just three little details to adjust in the tests and it will be ready :)

wait();
},

'test colordialog add hash to colors 6 digits': function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think test names would be more readable like:

  • test colordialog add hash to colors - 6 digits
  • test colordialog add hash to colors: 6 digits
  • test colordialog add hash to colors with 6 digits color

},

'test colordialog does not add hash 1 digit': function() {
// IE8 don't allow on totally wrong values of attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

IE8 doesn't allowing invalid values means the attribute will not be set? I think it might be more clear with something like:
IE8 doesn't allow to use invalid color values. or IE8 doesn't set invalid color values. ?


1. Right click into table cell.
1. Select `Cell -> Cell Properties`.
1. Choose background color.
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it mean to click Choose button and then type color in a colordialog? It might be a little unclear, and typing color without hash in Cell Properties dialog does not add hash (and color when closing dialog) so it may seem it is broken in this case.
To make it more clear you may use: Click Choose next to Background Color or something similar.

@msamsel msamsel added this to the 4.8.0 milestone Jul 5, 2017
@f1ames f1ames self-requested a review July 5, 2017 10:13
Copy link
Contributor

@f1ames f1ames left a comment

Choose a reason for hiding this comment

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

LGTM!

@mlewand mlewand dismissed Comandeer’s stale review July 5, 2017 11:07

Tomasz is off, while all the points from the list has been addressed

@f1ames f1ames force-pushed the t/565 branch 2 times, most recently from 4de4d20 to 2b6bd45 Compare July 5, 2017 11:48
@f1ames f1ames merged commit 6ae9c49 into major Jul 5, 2017
@f1ames f1ames deleted the t/565 branch July 5, 2017 11:51
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.

4 participants