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

Add end 2 end test to block icons #7589

Merged
merged 1 commit into from
Jul 10, 2018

Conversation

jorgefilipecosta
Copy link
Member

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.

@jorgefilipecosta jorgefilipecosta added [Feature] Blocks Overall functionality of blocks [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests. labels Jun 27, 2018
@jorgefilipecosta jorgefilipecosta self-assigned this Jun 27, 2018
@jorgefilipecosta jorgefilipecosta added this to the 3.2 milestone Jun 28, 2018
Copy link
Member

@gziolo gziolo left a 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' } );
Copy link
Member

Choose a reason for hiding this comment

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

Whitespaces need some tweaks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Improved.

Copy link
Member

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.

} );

afterAll( async () => {
await newDesktopBrowserPage();
Copy link
Member

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.

Copy link
Member Author

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

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', () => {
Copy link
Member

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.

Copy link
Member Author

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.

/**
* Inserts first inserter block. Inserter needs to be open.
*/
export async function insertFirstBlockInInserter() {
Copy link
Member

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.

Copy link
Member Author

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)
Copy link
Member

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.

Copy link
Member Author

Choose a reason for hiding this comment

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

Corrected

},
category: 'common',

edit() {
Copy link
Member

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() {
Copy link
Member

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.

@jorgefilipecosta jorgefilipecosta force-pushed the add/end-2-end-test-block-icons branch 2 times, most recently from 01d8416 to ed8e261 Compare June 29, 2018 12:36
@jorgefilipecosta
Copy link
Member Author

jorgefilipecosta commented Jun 29, 2018

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.
I'm not seeing how we can test the flow of a custom block setting an icon until that icon passes by the transformations and appears on the UI without an end to end test. It is similar to our end to end test of PluginPostStatusInfo we can unit test each part but to test all the flow we used an end 2 end test.

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.

@jorgefilipecosta jorgefilipecosta modified the milestones: 3.2, 3.3 Jul 5, 2018
'wp-hooks',
'wp-i18n'
),
filemtime( plugin_dir_path( __FILE__ ) . 'hooks-api/index.js' ),
Copy link
Member

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' ), :)

);
},
} );

Copy link
Member

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.

Copy link
Member

@gziolo gziolo left a 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.

@gziolo
Copy link
Member

gziolo commented Jul 10, 2018

#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 :)

@jorgefilipecosta jorgefilipecosta merged commit 6ce81bf into master Jul 10, 2018
@jorgefilipecosta jorgefilipecosta deleted the add/end-2-end-test-block-icons branch July 10, 2018 15:51
}

describe( 'Correctly Renders Block Icons on Inserter and Inspector', () => {
const dashIconRegex = /<svg.*class=".*dashicons-cart.*?">.*<\/svg>/;
Copy link
Member

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.

Copy link
Member Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Blocks Overall functionality of blocks [Type] Automated Testing Testing infrastructure changes impacting the execution of end-to-end (E2E) and/or unit tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants