-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Keycodes package modifiers usage and adding missing JSDocs. #11855
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
Keycodes package modifiers usage and adding missing JSDocs. #11855
Conversation
…lity/11535-test-utils-jsdocs-and-modifiers-update
… with rawShortcuts.
…lity/11535-test-utils-jsdocs-and-modifiers-update
nicolad
left a comment
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.
Hi @gziolo, based on this modifierMapping
const SELECT_WORD_MODIFIER_KEYS = process.platform === 'darwin' ? [ 'Shift', 'Alt' ] : [ 'Shift', 'Control' ];
from this file https://github.com/WordPress/gutenberg/blob/master/test/e2e/specs/links.test.js#L18
I have updated this modifier:
https://github.com/WordPress/gutenberg/blob/master/packages/keycodes/src/index.js#L56
This change caused this test to fail:
https://github.com/WordPress/gutenberg/blob/master/packages/edit-post/src/components/keyboard-shortcut-help-modal/test/index.js
What's your thought on this, should I updated the test or should I change back keycodes package ?
|
I think @talldan have the most experience with Keyboard shortcuts modal so I would defer it to him. I see also a lot of failing e2e tests because of:
In general, I like the direction where this PR is heading. It would be awesome if we could land those changes as it will allow us to reuse existing utilities rather than duplicate them for all tests. |
packages/keycodes/src/index.js
Outdated
| export const rawShortcut = mapValues( modifiers, ( modifier ) => { | ||
| return ( character, _isApple = isAppleOS ) => { | ||
| return [ ...modifier( _isApple ), character.toLowerCase() ].join( '+' ); | ||
| return [ ...modifier( _isApple ), character.toLowerCase() ].filter( ( key ) => key !== '' ).join( '+' ); |
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.
What was the reason that filtering is introduced?
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 is because when we are passing second argument to pressWithModifier there is no need to pass it to rawShortcut also, because key is used only in here await page.keyboard.press( key )
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 think it might be tidier to export the modifiers const from keycodes, and write a function that maps the keys exactly as they're needed within the e2e/utils (instead of using rawShortcut in tests).
That would also allow the possibility of adding extra combinations to the list of modifiers that are only used in tests (e.g. the shift+control word selection modifiers) and the production implementation wouldn't need to be touched.
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.
Agree, have adjusted this, also had swapped ctrl, because in tests it was used as Control. Also shiftAlt is overwritten in pressWithModifier to align with tests prior usage.
For some reasons Travis has cached META_KEY and SELECT_WORD_MODIFIER_KEYS, which is causing tests to fail, is there a way to clean cache in Travis ?
talldan
left a comment
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.
Hey @vadimnicolai - thanks for the changes!
I've added a couple of comments for things that I think need to be addressed.
packages/keycodes/src/index.js
Outdated
| export const rawShortcut = mapValues( modifiers, ( modifier ) => { | ||
| return ( character, _isApple = isAppleOS ) => { | ||
| return [ ...modifier( _isApple ), character.toLowerCase() ].join( '+' ); | ||
| return [ ...modifier( _isApple ), character.toLowerCase() ].filter( ( key ) => key !== '' ).join( '+' ); |
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 think it might be tidier to export the modifiers const from keycodes, and write a function that maps the keys exactly as they're needed within the e2e/utils (instead of using rawShortcut in tests).
That would also allow the possibility of adding extra combinations to the list of modifiers that are only used in tests (e.g. the shift+control word selection modifiers) and the production implementation wouldn't need to be touched.
|
I will try to clear caches on Travis and restart build. |
gziolo
left a comment
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 is looking very good, it still needs some adjustments.
There are some issues to resolve:
[0] [0] /home/travis/build/WordPress/gutenberg/test/e2e/specs/links.test.js
[0] [0] 391:28 error 'META_KEY' is not defined no-undef
[0] [0] 461:28 error 'SELECT_WORD_MODIFIER_KEYS' is not defined no-undef
[0] [0]
[0] [0] /home/travis/build/WordPress/gutenberg/test/e2e/specs/undo.test.js
[0] [0] 25:28 error 'META_KEY' is not defined no-undef
[0] [0] 34:28 error 'META_KEY' is not defined no-undef
[0] [0] 39:28 error 'META_KEY' is not defined no-undef
[0] [0]
[0] [0] ✖ 8 problems (5 errors, 3 warnings)
There are still references to the removed constants:
ReferenceError: META_KEY is not defined 389 | 390 | // Press Cmd+K to insert a link > 391 | await pressWithModifier( META_KEY, 'K' ); | ^ 392 | 393 | // Wait for the URL field to auto-focus 394 | await waitForAutoFocus(); at Object.META_KEY (test/e2e/specs/links.test.js:391:28) at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40) at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22) at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21) at asyncGeneratorStep (test/e2e/specs/links.test.js:15:103) at _next (test/e2e/specs/links.test.js:17:194)● Links › link popover remains visible after a mouse drag event
ReferenceError: SELECT_WORD_MODIFIER_KEYS is not defined
459 |
460 | // Select some text
> 461 | await pressWithModifier( SELECT_WORD_MODIFIER_KEYS, 'ArrowLeft' );
| ^
462 |
463 | // Click on the Link button
464 | await page.click( 'button[aria-label="Link"]' );
at Object.SELECT_WORD_MODIFIER_KEYS (test/e2e/specs/links.test.js:461:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/links.test.js:15:103)
at _next (test/e2e/specs/links.test.js:17:194)
FAIL test/e2e/specs/undo.test.js (6.534s)
● undo › should undo typing after a pause
ReferenceError: META_KEY is not defined
23 | expect( await getEditedPostContent() ).toMatchSnapshot();
24 |
> 25 | await pressWithModifier( META_KEY, 'z' );
| ^
26 |
27 | expect( await getEditedPostContent() ).toMatchSnapshot();
28 | } );
at Object.META_KEY (test/e2e/specs/undo.test.js:25:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/undo.test.js:9:103)
at _next (test/e2e/specs/undo.test.js:11:194)
● undo › should undo typing after non input change
ReferenceError: META_KEY is not defined
32 |
33 | await page.keyboard.type( 'before keyboard ' );
> 34 | await pressWithModifier( META_KEY, 'b' );
| ^
35 | await page.keyboard.type( 'after keyboard' );
36 |
37 | expect( await getEditedPostContent() ).toMatchSnapshot();
at Object.META_KEY (test/e2e/specs/undo.test.js:34:28)
at tryCatch (node_modules/regenerator-runtime/runtime.js:62:40)
at Generator.invoke [as _invoke] (node_modules/regenerator-runtime/runtime.js:288:22)
at Generator.prototype.(anonymous function) [as next] (node_modules/regenerator-runtime/runtime.js:114:21)
at asyncGeneratorStep (test/e2e/specs/undo.test.js:9:103)
at _next (test/e2e/specs/undo.test.js:11:194)
…lity/11535-test-utils-jsdocs-and-modifiers-update
…code-quality/11535-test-utils-jsdocs-and-modifiers-update
…code-quality/11535-test-utils-jsdocs-and-modifiers-update
|
It should be very close to what you have locally if you use Docker instance provided with the repository.
There are 9 tests failing in this suite. Everything else passes. Maybe |
| ...modifiers, | ||
| shiftAlt: ( _isApple ) => _isApple ? [ SHIFT, ALT ] : [ SHIFT, CTRL ], | ||
| }; | ||
| const mappedModifiers = overWrittenModifiers[ modifier ]( isAppleOS ); |
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 think I found what's causing issues. isAppleOS should be called here. It is passed down as function and that's why shiftAlt is always [ SHIFT, ALT ].
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.
Actually, it should be inside shiftAlt. It's not easy to debug using GitHub UI :)
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.
You have an eye of the 🐯
|
Is it ok if I will add missing JSDocs in a separate PR ? |
|
Yes, sure thing. Another nice refactor, thanks for all your help with making e2e test utils better 🙇 |
* Add e2e tests for the format API * Fixes some whitespace issues * Update format-api.test.js * Add missing dependencies to the script registration * Add snapshot to test * Check for custom button, remove extra lines * Change modifier keys used From #11855
| * | ||
| * @type {string} | ||
| */ | ||
| const SELECT_WORD_MODIFIER_KEYS = process.platform === 'darwin' ? [ 'Shift', 'Alt' ] : [ 'Shift', 'Control' ]; |
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 JSDoc comment on the preceding comment existed to complement this line of code. With this line of code removed, that JSDoc should have been removed as well.
See: #21297

Description
Replaced
pressWithModifiermethod from e2e test utils with modifiers from keycodes package.Added missing JSDocs in test utils files.
How has this been tested?
Testing will be done with TravisCI
Types of changes
Enhancements
Checklist: