-
Notifications
You must be signed in to change notification settings - Fork 805
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
Subscriptions: Add unit tests and fixtures to validate block content parsing #18993
Conversation
Caution: This PR has changes that must be merged to WordPress.com |
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 If you are an automattician, once your PR is ready for review add the "[Status] Needs Team review" label and ask someone from your team review the code. jetpack plugin:
|
Thank you for your PR! When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:
This comment will be updated as you work on your PR and make changes. If you think that some of those checks are not needed for your PR, please explain why you think so. Thanks for cooperation 🤖 Once your PR is ready for review, check one last time that all required checks (other than "Required review") appearing at the bottom of this PR are passing or skipped. Jetpack plugin:
|
2206e89
to
14796c4
Compare
fe1032e
to
6b596c9
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.
This is testing well for me @ramonjd, I tried the block out in a sandboxed wpcom environment and in my local Jetpack site, and the block still works as expected.
I left a tiny comment about the padding tests, but I also noticed with the edit.js
tests it appears to be trying to fire the apiFetch
. It doesn't seem to be breaking the tests, but does log out a warning when I run yarn jest extensions/blocks/subscriptions/test/
:
Is it worth mocking apiFetch
for the Edit tests?
projects/plugins/jetpack/extensions/blocks/subscriptions/controls.js
Outdated
Show resolved
Hide resolved
projects/plugins/jetpack/extensions/blocks/subscriptions/test/controls.js
Outdated
Show resolved
Hide resolved
Thanks for pointing this out @andrewserong! Totally agree we should remove those warnings. It also gave me a chance to learn about act() |
This tested well for me, and api notices are no longer logged. For some reason the block content migrates every time you load a page in the editor with this block, even though the save function and saved content are the same:
I can't see an obvious reason why this is happening, but it looks like this is an existing bug as it happens on WPcom currently, so not sure if you want to investigate further or add a separate issue for it. |
This tests well for me 👍
With empty/default attributes the current block version's shortcode matches the v1 deprecation. That deprecation implements As the current default subscribe block content matches and is "valid", the If that It appears that the point of this deprecation was to migrate from the isEligible: attr => {
if ( ! attr.hasOwnProperty( 'subscribeButton' ) || ! isEmpty( attr.subscribeButton ) ) {
return false;
}
return true;
}, Making a change like this might give an opportunity to run the fixture tests in earnest as well? 🙂 |
bbe050e
to
2e0bcab
Compare
…uttonText. To determine whether deprecation v1 is eligible we need to check for both the old property subscribeButton and its value since only checking for empty matches empty/default on other versions. See: #18993#issuecomment-793490858
Thanks so much @glendaviesnz and @aaronrobertshaw for your reviews and explanations! TIL I've implemented the changes as recommended and can confirm that the content migration console message does not appear after the change. 🙇 |
I've pushed a commit updating all the fixtures and some of the deprecations. All the tests are green for me and all the deprecations' Ran the tests as per the PR instructions but also via There are a couple of things to note.
|
…nd adding initial control tests.
…ontrols Adding mocks for apiFetch in the edit tests Using zero values for default input[type=number] fields to receive more reliable userEvent.type results
…bute to submitButtonText. To determine whether deprecation v1 is eligible we need to check for both the old property subscribeButton and its value since only checking for empty matches empty/default on other versions. See: #18993#issuecomment-793490858
Bring all deprecations and fixtures into line
Needs rebase after d001afc Also, I suspect we need to update our dependency on |
Clearing some controls before modifying values
854511d
to
58cdf87
Compare
Noting that this was planned in #16763, but we've run into some issues that have stopped from updating so far. :( |
…porarily to avoid type/import errors that should be fixed when we update the wordpress monorepo
I've mocked the button width control component (similar to the Button tests) in the meantime to move this PR forward. |
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.
Lgtm, tests are passing now 👍
Great news! One last step: head over to your WordPress.com diff, D57958-code, and commit it. Thank you! |
r223841-wpcom |
Changes proposed in this Pull Request:
This PR adds unit and block fixture parsing tests to the Subscriptions block, and extricate the controls into a
controls.js
file.No block functionality is affected.
Jetpack product discussion
p1HpG7-b3G-p2
Does this pull request change what data or activity we track or use?
No.
Testing instructions:
Running the unit tests:
cd projects/plugins/jetpack && yarn fixtures:test extensions/blocks/subscriptions/test/
We should also ensure that the block works as expected in the editor and saved stats on a site.
To test the subscriptions block in a browser we need an active connection or have the plugin running on WPCOM in order to activate the module.
Apply D57958-code to your sandbox and add a subscriptions block to a new sandboxed test site.
Proposed changelog entry for your changes:
None. No functional changes made.