-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add end 2 end test to block icons #7589
Conversation
598413a
to
5c4200e
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.
Those tests are very granular. I’m aware that it’s a lot of work to setup blocks to validate how they fit into inserter. However, do you see any of those tests to be converted into unit tests? Maybe it could be possible to test Inserter’s item from search results with a set of props that mirror what we have here? My point is that e2e tests are super slow comparing to unit tests. We test here some interactions and integration with custom blocks which is awesome, but maybe some details could be covered as component tests. What do you think?
var registerBlockType = wp.blocks.registerBlockType; | ||
var el = wp.element.createElement; | ||
var InnerBlocks = wp.editor.InnerBlocks; | ||
var circle = el( 'circle', { cx: 10, cy: 10, r: 10, fill: 'red', stroke: 'blue', strokeWidth: '10' } ); |
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.
Whitespaces need some tweaks.
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.
Improved.
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 still mixes spaces and tabs.
test/e2e/specs/block-icons.test.js
Outdated
} ); | ||
|
||
afterAll( async () => { | ||
await newDesktopBrowserPage(); |
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.
Is this necessary? I can’t think of any reason to open a page just before test suite ends.
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 agree we don't need to open a new page when the test is ending. I followed what we are doing in
gutenberg/test/e2e/specs/plugins-api.test.js
Lines 20 to 23 in ed8e261
afterAll( async () => { | |
await newDesktopBrowserPage(); | |
await deactivatePlugin( 'gutenberg-test-plugin-plugins-api' ); | |
} ); |
I thought we might have a reason to disable plugins in a new page, but I removed this line, and it seems everything is fine.
return await getInnerHTML( INSERTER_ICON_SELECTOR ); | ||
} | ||
|
||
describe( 'Correctly Renders Block Icons on Inserter and Inspector', () => { |
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.
Why not use Block Icons here to make snapshots smaller? There is some duplication with the name of individual tests.
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 removed the snapshots. We now use another validatiom mechanism so we don't have duplication of snapshots.
test/e2e/support/utils.js
Outdated
/** | ||
* Inserts first inserter block. Inserter needs to be open. | ||
*/ | ||
export async function insertFirstBlockInInserter() { |
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.
Should it be insertFirstBlockFromInserter or insetFirstBlockFoundInInserter instead? It is a bit confusing at the moment. Does it need to be exposed? It isn’t referenced outside.
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.
Updated during the rebase.
var el = wp.element.createElement; | ||
var InnerBlocks = wp.editor.InnerBlocks; | ||
var circle = el( 'circle', { cx: 10, cy: 10, r: 10, fill: 'red', stroke: 'blue', strokeWidth: '10' } ); | ||
var svg = el( 'svg', { width: 20, height: 20, viewBox: '0 0 20 20'}, circle) |
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.
; is missing at the end of the line.
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.
Corrected
}, | ||
category: 'common', | ||
|
||
edit() { |
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 ES6 syntax - object method shorthand 😃
@@ -0,0 +1,157 @@ | |||
( function() { |
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.
Is fine as is, but this plugin might be useful also to test other things. I see it applicable with very slight tweaks to verify custom block categories hook.
01d8416
to
ed8e261
Compare
Hi @gziolo we already have unit tests for the blocks registration, the inserter, and the icon rendering component. The problem is that each part has its own logic and may transform the way an icon is represented/rendered. Each part may work correctly alone but we may have problems on the integration. That said I agree this test right now is very granular. If I'm not in error this is our first end2end test for the registration of a custom block :). In this case for a very specific test. I think we can see this test case as a start. Right now it is only checking the icons but after we can add other checks, e.g: if the categories appear as they should, or if we can add blocks inside. Of course, when needed we should rename the test case file and the name of the tests if we add other checks. |
'wp-hooks', | ||
'wp-i18n' | ||
), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'hooks-api/index.js' ), |
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.
Copy and paste issue, it should be:
filemtime( plugin_dir_path( __FILE__ ) . 'block-icons/index.js' ),
:)
); | ||
}, | ||
} ); | ||
|
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 has obsolete empty line.
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 follow your judgment get it in as is. It's a very nice addition to our suite of tests. I'm looking forward to see how it evolves.
There are 2 or 3 nitpicks to address before you merge it.
#7589 (comment) - regarding this one, we probably should add some basic linting which doesn't expect ES.Next. I will get to it at some point :) |
ed8e261
to
956ab99
Compare
} | ||
|
||
describe( 'Correctly Renders Block Icons on Inserter and Inspector', () => { | ||
const dashIconRegex = /<svg.*class=".*dashicons-cart.*?">.*<\/svg>/; |
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.
Across many branches, I'm getting test failures in this suite when running locally.
Example:
Expected value to match:
/<svg.*class=".*dashicons-cart.*?">.*<\/svg>/
Received:
"<svg aria-hidden=\"true\" role=\"img\" focusable=\"false\" class=\"dashicon dashicons-editor-paragraph\" xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 20 20\"><path d=\"M15 2H7.54c-.83 0-1.59.2-2.28.6-.7.41-1.25.96-1.65 1.65C3.2 4.94 3 5.7 3 6.52s.2 1.58.61 2.27c.4.69.95 1.24 1.65 1.64.69.41 1.45.61 2.28.61h.43V17c0 .27.1.51.29.71.2.19.44.29.71.29.28 0 .51-.1.71-.29.2-.2.3-.44.3-.71V5c0-.27.09-.51.29-.71.2-.19.44-.29.71-.29s.51.1.71.29c.19.2.29.44.29.71v12c0 .27.1.51.3.71.2.19.43.29.71.29.27 0 .51-.1.71-.29.19-.2.29-.44.29-.71V4H15c.27 0 .5-.1.7-.3.2-.19.3-.43.3-.7s-.1-.51-.3-.71C15.5 2.1 15.27 2 15 2z\"></path></svg>"
Also, the regular expression is prone to greediness.
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 tried to debug the problem locally and if I execute the test normally they always pass. If make them slow with PUPPETEER_SLOWMO=30 they start to fail because instead of the expected block being selected the paragraph is selected. That matches with the error message you are seeing. I'm researching why the paragraph is getting selected.
Description
Our logic for block icons is complex and contains many possible ways to set an icon.
This PR adds set of the end 2 end tests to block icons in order to make it harder to regress in the future.
How has this been tested?
I executed the tests and verified they pass with success.