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

Telephone link type support in link plugin #2214

Merged
merged 27 commits into from
Jul 17, 2018
Merged

Telephone link type support in link plugin #2214

merged 27 commits into from
Jul 17, 2018

Conversation

engineering-this
Copy link
Contributor

What is the purpose of this pull request?

New feature

Does your PR contain necessary tests?

All patches which 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

What changes did you make?

Added new dialog input[type="tel"]. And used in in link plugin for inputing phone number in new link type. Also added config options to set validation regex and alert message when validation fails.

Closes #2154

@engineering-this engineering-this changed the title Telephone linke type support in link plugin Telephone link type support in link plugin Jul 11, 2018
@mlewand mlewand added the review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer. label Jul 11, 2018
Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Field for telephone number is marked as required yet it is allowed to have empty value. IMO even without validation editor should disallow inserting empty telephone number.

Additionally there is no unit test for inserting telephone link without validation.

var editor = this.getDialog()._.editor,
regExp = editor.config.linkTelNumberValidate_regExp,
msg = editor.config.linkTelNumberValidate_msg,
dialog = this.getDialog();
Copy link
Member

Choose a reason for hiding this comment

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

If we move this variable definition earlier, we could use it to get editor:

editor = dialog._.editor

Microoptimisations – FTW!

bot.dialog( 'link', function( dialog ) {
var expectedNumber = '123456789',
input,
stub = this._stubs.alert = sinon.stub( window, 'alert' );
Copy link
Member

Choose a reason for hiding this comment

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

TBH creating this._stubs and whole tearDown logic seems a little bit like overkill. We got only this one stub, which could be restored with one line of code instead of current 7. Keeping whole stubbing code inside test itself also improves readability.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

Editors in manual tests are not entirely visible:

Editor's instance with partially hidden under Bender's message toolbar

},

// (#2154)
'test telephone number link without validation': assertTelephoneLinks(),
Copy link
Member

Choose a reason for hiding this comment

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

If test is moved into dedicated function, then this function should be customisable. The bare minimum is the ability to pass object with input and expected output. Otherwise the dedicated function is not reusable in future tests that could be added later, in another issue.

Also asserts could be moved into callback.

regExp = editor.config.linkTelNumberValidate_regExp,
msg = editor.config.linkTelNumberValidate_msg,
linkLang = editor.lang.link,
func = CKEDITOR.dialog.validate.notEmpty( linkLang.noTel ),
Copy link
Member

Choose a reason for hiding this comment

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

func could be just inlined into messageWhenEmpty variable.

msg = editor.config.linkTelNumberValidate_msg,
linkLang = editor.lang.link,
func = CKEDITOR.dialog.validate.notEmpty( linkLang.noTel ),
messageWhenEmpty = func.apply( this );;
Copy link
Member

Choose a reason for hiding this comment

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

Double semicolon.

return true;
}

if ( typeof messageWhenEmpty === 'string' || !messageWhenEmpty ) {
Copy link
Member

Choose a reason for hiding this comment

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

Can't it be simplified to message !== true?

return messageWhenEmpty;
}

if ( regExp && !regExp.test( this.getValue() ) ) {
Copy link
Member

Choose a reason for hiding this comment

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

Note that we have built-in CKEDITOR.dialog.validate.regex, which could simplify the logic.

* config.linkTelNumberValidate_regExp = /^[0-9]{9}$/;
*
* @since 4.11.0
* @cfg {RegExp} [linkTelNumberValidate_regExp]
Copy link
Member

Choose a reason for hiding this comment

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

I'm thinking about changing names of variables to linkTelNumberRegExp and linkTelNumberMsg. ATM only these two config variables in link plugin contain underscore, introducing some kind of inconsistency.

Copy link
Member

@Comandeer Comandeer left a comment

Choose a reason for hiding this comment

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

LGTM! I've just updated manual tests, rephrase message about empty input and fixed some code style issues.

@Comandeer Comandeer merged commit 1545a0e into major Jul 17, 2018
@Comandeer Comandeer deleted the t/2154 branch July 17, 2018 18:01
@mlewand
Copy link
Contributor

mlewand commented Jul 20, 2018

@engineering-this @Comandeer I don't think we made a good choice with the config.linkTelNumberMsg:

  • The message about invalid phone format should be simply put in the lang files and provided by our plugin. By putting it in the config you put the hassle of localizing this message to the dev integrating CKE4, while it should just work™. Providing it in lang file provides localization, contributed by our amazing community out of the box, for everyone.
  • Secondly I think the name does not fully explains the purpose. Name is linkTelNumberMsg and it does n't mention that it's a message in case of invalid number/wrong format.

@Comandeer
Copy link
Member

The reason behind putting it in config was the fact that validation will be custom – so the message also could be custom, to include information about the desired format of the telephone number.

@mlewand
Copy link
Contributor

mlewand commented Jul 20, 2018

@Comandeer That sounds like a good use case to remember about, though you can still define the default message in the lang file and allow for customization in case of need.

So the default lang entry would look pretty much like that:

en
invalidTelNumberMessage: 'Invalid phone number format.',

While you could optionally override it. It could be with config, so you would have a config.linkInvalidTelNumberMessage = 'Format should follow an XYZ pattern.'.

I have emphasized could because I'm not a big fan of adding a config option to customize the error message alone, instead I'd like to see some reusable way to adjust any lang entry during the runtime.

TBH I don't know any clear right off the bat (would need to check the code), but you can always do that by listening to instanceReady event and overwriting any lang property that should be customized. However I know, it's pretty advanced as for such use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
review:easy Pull requests that can be reviewed by a Junior Developer before being reviewed by the Reviewer.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants