-
Notifications
You must be signed in to change notification settings - Fork 0
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
tests: Add tests for CoreHeading
block
#10
Conversation
8ae47f1
to
77fe2b0
Compare
a09a490
to
32cc02a
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.
@ashutoshgautams see the changes in 32cc02a:
Tl;dr
- Instead of setting the same block for each test, we set the
post_content
inside each test. - Our
$this->query()
is shared and covers all the possible fields (generic on the query, block-specific on the fragment). We should test them all. - If we think there's a bug, leave the assert, but comment it out or leave a comment nearby.
- Additional tests are used for different
post_content
to get a different set of values out of the attributes. Currently we need to test align, anchor, backgroundColor, fonts, gradient, textColor etc. (Again it's possible some will be null when they shouldnt)
Next Steps
Add tests for additional snippets to cover the attributes that are null in the current test.
(Use the block test data for inspiration: https://github.com/WordPress/theme-test-data/blob/master/64-block-test-data.xml )
1a2d5d6
to
ae45158
Compare
af21213
to
92e7ae6
Compare
@ashutoshgautams I did a rebase onto the latest |
ecd8b31
to
92e7ae6
Compare
- cover the attributes that are null
Update CoreHeadingTest with Comprehensive Attribute TestingDescriptionThis PR updates the CoreHeadingTest class to provide more comprehensive testing of the CoreHeading block attributes in the wp-graphql-content-blocks plugin. The changes address previously null attributes and ensure that all possible configurations of the CoreHeading block are properly tested. Changes Made
Types of Changes
Checklist:
Additional NotesThis update significantly improves our test coverage for the CoreHeading block. It should help catch any potential issues with attribute parsing or returning in future updates to the plugin. |
This whole thing reads like GPT - and more importantly I'm pretty sure it's inaccurate. I've updated the PR description with a template. Please edit it and fill in the things I marked. |
CoreHeading
block
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.
@ashutoshgautams - looking good 🙌
- Update new tests so
assertEquals()
tests the entire attributes array. Leave an inline comment by any attributes that are// Previously untested.
by any of the earlier tests in the class. - Update the PR description.
- Add + commit a changeset:
npm run changeset
- Since we're just adding tests, not any new features, set the release type as
patch
- For the message use the new PR title: "tests: Add tests for
CoreHeading
block". - You'll see a generated json file with the info you inserted into the cli - confirm it's good before committing.
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.
Fix the remaining annotations and phpcbf
and we'll be ready to open it on wpe
52bdf70
to
7301ed9
Compare
(resolving all the old comments, since they're just noise in light of #10 (comment) ) |
tests/unit/CoreHeadingTest.php
Outdated
public function test_retrieve_core_heading_with_background_color() { | ||
$block_content = ' | ||
<!-- wp:heading {"backgroundColor":"vivid-red-background-color"} --> | ||
<h2 class="wp-block-heading has-vivid-red-background-color has-background">Heading with Background Color</h2> | ||
<!-- /wp:heading> | ||
'; | ||
|
||
wp_update_post( | ||
[ | ||
'ID' => $this->post_id, | ||
'post_content' => $block_content, | ||
] | ||
); | ||
|
||
$actual = graphql( | ||
[ | ||
'query' => $this->query(), | ||
'variables' => [ 'id' => $this->post_id ], | ||
] | ||
); | ||
|
||
$block = $actual['data']['post']['editorBlocks'][0]; | ||
$attributes = $block['attributes']; | ||
|
||
$this->assertEquals( | ||
[ | ||
'align' => null, | ||
'anchor' => null, | ||
'backgroundColor' => 'vivid-red-background-color', | ||
'className' => null, | ||
'content' => 'Heading with Background Color', | ||
'cssClassName' => 'wp-block-heading has-vivid-red-background-color has-background', | ||
'fontFamily' => null, | ||
'fontSize' => null, | ||
'gradient' => null, | ||
'level' => 2.0, | ||
'lock' => null, | ||
'placeholder' => null, | ||
'style' => null, | ||
'textAlign' => null, | ||
'textColor' => null, | ||
], | ||
$attributes | ||
); | ||
} |
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 being tested in test_retrieve_core_heading_with_font_family_and_size
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.
@ashutoshgautams based on the duplications, I think it might be beneficial to add doc-blocks listing the specific attributes targeted by the test. See #24 for an example of what I mean.
Add those, remove the unnecessary duplicate tests I flagged, and update the PR description, and this should be good to go.
Edit: I also think we're missing a lock
test
@@ -74,6 +90,11 @@ className | |||
'; | |||
} | |||
|
|||
/** | |||
* Test the retrieval of core/heading block attributes. | |||
* |
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 important part of the doc blocks I was referencing was the explicit list of "previously untested" attributes, so it's clear at a glance what each test is covering.
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.
Apart from line 94, everywhere else 'doc blocks' already contains => explicit list of "previously untested" attributes.
Added it here as well.
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.
@ashutoshgautams - LGTM 🙌
- Update the PR description to include
lock
- (Optional) Squash the commit history into a single commit.
- Open a PR upstream and copy the pr title + description from here.
- Tag me in a comment on that new PR.
Tracking wpengine#296
What
This PR backfills tests for the
CoreHeading
block and its attributes.Tested attributes:
Untested fields:
CoreHeadingAttributes.metadata
- @todoCoreHeadingAttributes.placeholder
- Not explicitly tested, always returns null in current testsExposed issues:
CoreHeading.cssClassNames
: returnsnull
even when the block has CSS classes. This is commented out in the test file.CoreHeadingAttributes.level
returns aFloat
instead of anInteger
. This is noted in a comment in the test file.These issues are noted in comments within the test file and should be addressed in future updates.