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

Button block: Add tests #19002

Merged
merged 12 commits into from
Mar 18, 2021
Merged

Button block: Add tests #19002

merged 12 commits into from
Mar 18, 2021

Conversation

stacimc
Copy link
Contributor

@stacimc stacimc commented Mar 3, 2021

Adds tests for the Button block.

Changes proposed in this Pull Request:

  • Pulls settings out of the block into a Controls component for simplification/separate testing
  • Adds tests

Jetpack product discussion

p1HpG7-b3G-p2

Does this pull request change what data or activity we track or use?

Testing instructions:

  • Run tests from the projects/plugins/jetpack folder with:
yarn jest extensions/blocks/button/test/edit.js
yarn jest extensions/blocks/button/test/controls.js
  • Manually test the Button block, including setting all of the color/border radius selections

Proposed changelog entry for your changes:

@matticbot
Copy link
Contributor

Caution: This PR has changes that must be merged to WordPress.com
Hello stacimc! These changes need to be synced to WordPress.com - If you 're an a11n, please commandeer and confirm D58003-code works as expected before merging this PR. Once this PR is merged, please commit the changes to WP.com. Thank you!
This revision will be updated with each commit to this PR

@github-actions github-actions bot added the [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ label Mar 3, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2021

Thank you for your PR!

When contributing to Jetpack, we have a few suggestions that can help us test and review your patch:

  • ✅ Include a description of your PR changes.
  • ❌ All commits were linted before commit.
  • ✅ Add a "[Status]" label (In Progress, Needs Team Review, ...).
  • ✅ Add testing instructions.
  • ✅ Specify whether this PR includes any changes to data or privacy.

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.
Then, add the "[Status] Needs Team review" label and ask someone from your team review the code.
Once you’ve done so, switch to the "[Status] Needs Review" label; someone from Jetpack Crew will then review this PR and merge it to be included in the next Jetpack release.undefined


Jetpack plugin:

  • Next scheduled release: April 6, 2021.
  • Scheduled code freeze: March 29, 2021

} );

test( 'applies gradient color class and style to the button', () => {
__experimentalUseGradient.mockReturnValueOnce = gradientProps;
Copy link
Member

Choose a reason for hiding this comment

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

As per the Slack thread, try
__experimentalUseGradient.mockImplementation( () => gradientProps );

@stacimc stacimc changed the title [In Progress] Button block: Add tests Button block: Add tests Mar 4, 2021
@stacimc stacimc marked this pull request as ready for review March 4, 2021 21:41
apeatling
apeatling previously approved these changes Mar 9, 2021
Copy link
Member

@apeatling apeatling left a comment

Choose a reason for hiding this comment

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

Works for me, nice!

@apeatling apeatling added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Team Review labels Mar 9, 2021
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

This seems to generate block validation errors when editing posts with Subscriptions blocks:

Click to expand!
Block validation: Block validation failed for `jetpack/subscriptions` (
{
    "name": "jetpack/subscriptions",
    "icon": {
        "src": {
            "key": null,
            "ref": null,
            "props": {
                "width": "24",
                "height": "24",
                "viewBox": "0 0 24 24",
                "fill": "none",
                "xmlns": "http://www.w3.org/2000/svg",
                "children": [
                    {
                        "key": null,
                        "ref": null,
                        "props": {
                            "x": "4.75",
                            "y": "6.75",
                            "width": "14.5",
                            "height": "10.5",
                            "rx": "1.25",
                            "stroke": "#069e08",
                            "strokeWidth": "1.5",
                            "fill": "none"
                        },
                        "_owner": null
                    },
                    {
                        "key": null,
                        "ref": null,
                        "props": {
                            "d": "M19 7L13.3609 12.2363C12.5935 12.9489 11.4065 12.9489 10.6391 12.2363L5 7",
                            "stroke": "#069e08",
                            "strokeWidth": "1.5",
                            "strokeLinejoin": "bevel",
                            "fill": "none"
                        },
                        "_owner": null
                    }
                ]
            },
            "_owner": null
        },
        "foreground": "#069e08"
    },
    "keywords": [
        "subscribe",
        "join",
        "follow"
    ],
    "providesContext": {},
    "usesContext": [],
    "styles": [],
    "title": "Subscription Form",
    "description": {
        "type": "p",
        "key": null,
        "ref": null,
        "props": {
            "children": "A form enabling readers to get notifications when new posts are published from this site."
        },
        "_owner": null
    },
    "category": "grow",
    "example": {
        "attributes": {}
    },
    "deprecated": [
        {
            "attributes": {
                "subscribeButton": {
                    "type": "string",
                    "default": "Subscribe"
                },
                "showSubscribersTotal": {
                    "type": "boolean",
                    "default": false
                },
                "className": {
                    "type": "string"
                }
            }
        },
        {
            "attributes": {
                "subscribePlaceholder": {
                    "type": "string",
                    "default": "Email Address"
                },
                "subscribeButton": {
                    "type": "string",
                    "default": "Subscribe"
                },
                "showSubscribersTotal": {
                    "type": "boolean",
                    "default": false
                },
                "submitButtonText": {
                    "type": "string",
                    "default": "Subscribe"
                },
                "backgroundButtonColor": {
                    "type": "string"
                },
                "textButtonColor": {
                    "type": "string"
                },
                "customBackgroundButtonColor": {
                    "type": "string"
                },
                "customTextButtonColor": {
                    "type": "string"
                },
                "submitButtonClasses": {
                    "type": "string"
                },
                "className": {
                    "type": "string"
                }
            }
        },
        {
            "attributes": {
                "subscribePlaceholder": {
                    "type": "string",
                    "default": "Enter your email address"
                },
                "showSubscribersTotal": {
                    "type": "boolean",
                    "default": false
                },
                "buttonOnNewLine": {
                    "type": "boolean",
                    "default": false
                },
                "submitButtonText": {
                    "type": "string",
                    "default": "Sign Up"
                },
                "emailFieldBackgroundColor": {
                    "type": "string"
                },
                "customEmailFieldBackgroundColor": {
                    "type": "string"
                },
                "emailFieldGradient": {
                    "type": "string"
                },
                "customEmailFieldGradient": {
                    "type": "string"
                },
                "buttonBackgroundColor": {
                    "type": "string"
                },
                "customButtonBackgroundColor": {
                    "type": "string"
                },
                "buttonGradient": {
                    "type": "string"
                },
                "customButtonGradient": {
                    "type": "string"
                },
                "textColor": {
                    "type": "string"
                },
                "customTextColor": {
                    "type": "string"
                },
                "fontSize": {
                    "type": "number"
                },
                "customFontSize": {
                    "type": "number"
                },
                "borderRadius": {
                    "type": "number"
                },
                "borderWeight": {
                    "type": "number"
                },
                "borderColor": {
                    "type": "string"
                },
                "customBorderColor": {
                    "type": "string"
                },
                "padding": {
                    "type": "number"
                },
                "spacing": {
                    "type": "number"
                },
                "className": {
                    "type": "string"
                }
            }
        },
        {
            "attributes": {
                "subscribePlaceholder": {
                    "type": "string",
                    "default": "Enter your email address"
                },
                "showSubscribersTotal": {
                    "type": "boolean",
                    "default": false
                },
                "buttonOnNewLine": {
                    "type": "boolean",
                    "default": false
                },
                "submitButtonText": {
                    "type": "string",
                    "default": "Sign Up"
                },
                "emailFieldBackgroundColor": {
                    "type": "string"
                },
                "customEmailFieldBackgroundColor": {
                    "type": "string"
                },
                "emailFieldGradient": {
                    "type": "string"
                },
                "customEmailFieldGradient": {
                    "type": "string"
                },
                "buttonBackgroundColor": {
                    "type": "string"
                },
                "customButtonBackgroundColor": {
                    "type": "string"
                },
                "buttonGradient": {
                    "type": "string"
                },
                "customButtonGradient": {
                    "type": "string"
                },
                "textColor": {
                    "type": "string"
                },
                "customTextColor": {
                    "type": "string"
                },
                "fontSize": {
                    "type": "number"
                },
                "customFontSize": {
                    "type": "number"
                },
                "borderRadius": {
                    "type": "number"
                },
                "borderWeight": {
                    "type": "number"
                },
                "borderColor": {
                    "type": "string"
                },
                "customBorderColor": {
                    "type": "string"
                },
                "padding": {
                    "type": "number"
                },
                "spacing": {
                    "type": "number"
                },
                "className": {
                    "type": "string"
                }
            }
        }
    ],
    "attributes": {
        "subscribePlaceholder": {
            "type": "string",
            "default": "Enter your email address"
        },
        "showSubscribersTotal": {
            "type": "boolean",
            "default": false
        },
        "buttonOnNewLine": {
            "type": "boolean",
            "default": false
        },
        "submitButtonText": {
            "type": "string",
            "default": "Sign Up"
        },
        "emailFieldBackgroundColor": {
            "type": "string"
        },
        "customEmailFieldBackgroundColor": {
            "type": "string"
        },
        "emailFieldGradient": {
            "type": "string"
        },
        "customEmailFieldGradient": {
            "type": "string"
        },
        "buttonBackgroundColor": {
            "type": "string"
        },
        "customButtonBackgroundColor": {
            "type": "string"
        },
        "buttonGradient": {
            "type": "string"
        },
        "customButtonGradient": {
            "type": "string"
        },
        "textColor": {
            "type": "string"
        },
        "customTextColor": {
            "type": "string"
        },
        "fontSize": {
            "type": "number"
        },
        "customFontSize": {
            "type": "number"
        },
        "borderRadius": {
            "type": "number"
        },
        "borderWeight": {
            "type": "number"
        },
        "borderColor": {
            "type": "string"
        },
        "customBorderColor": {
            "type": "string"
        },
        "padding": {
            "type": "number"
        },
        "spacing": {
            "type": "number"
        },
        "className": {
            "type": "string"
        }
    }
}
Content generated by `save` function:

<div class="wp-block-jetpack-subscriptions wp-block-jetpack-subscriptions__supports-newline wp-block-jetpack-subscriptions__use-newline">
			[jetpack_subscription_form
				subscribe_placeholder="Enter your email address"
				show_subscribers_total="false"
				button_on_newline="true"
				submit_button_text="<strong>Sign up</strong> to receive emails of all my future posts"
				custom_background_emailfield_color="undefined"
				custom_background_button_color="undefined"
				custom_text_button_color="undefined"
				custom_font_size="16"
				custom_border_radius="0"
				custom_border_weight="3"
				custom_border_color="#e22658"
				custom_padding="15"
				custom_spacing="10"
				submit_button_classes="has-e-22658-border-color has-text-color has-accent-color has-background has-subtle-background-background-color"
				email_field_classes="has-e-22658-border-color"
				show_only_email_and_button="true"
			]</div>

Content retrieved from post body:

<div class="wp-block-jetpack-subscriptions wp-block-jetpack-subscriptions__supports-newline wp-block-jetpack-subscriptions__use-newline">[jetpack_subscription_form subscribe_placeholder="Enter your email address" show_subscribers_total="false" button_on_newline="true" submit_button_text="<strong>Sign up</strong> to receive emails of all my future posts" custom_font_size="49px" custom_border_radius="0" custom_border_weight="3" custom_border_color="#e22658" custom_padding="15" custom_spacing="10" submit_button_classes="has-49-px-font-size has-e-22658-border-color has-text-color has-accent-color has-background has-subtle-background-background-color" email_field_classes="has-49-px-font-size has-e-22658-border-color" show_only_email_and_button="true"]</div>

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 10, 2021
@stacimc
Copy link
Contributor Author

stacimc commented Mar 10, 2021

This seems to generate block validation errors when editing posts with Subscriptions blocks:

@jeherve Good catch! This is really odd -- I'm not sure what the root cause was, but it looks to have disappeared after rebasing.

@stacimc stacimc added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Mar 10, 2021
@anomiex
Copy link
Contributor

anomiex commented Mar 10, 2021

Needs a changelogger change file. In projects/plugins/jetpack, execute vendor/bin/changelogger add to create one interactively.

@anomiex anomiex added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 10, 2021
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Mar 11, 2021
@jeherve jeherve added this to the 9.6 milestone Mar 11, 2021
@stacimc
Copy link
Contributor Author

stacimc commented Mar 12, 2021

Rebased after merging in the button width options (#18809)

@stacimc stacimc added [Status] In Progress and removed [Status] Ready to Merge Go ahead, you can push that green button! labels Mar 12, 2021
Copy link
Member

@jeherve jeherve left a comment

Choose a reason for hiding this comment

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

@jeherve jeherve added [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! and removed [Status] In Progress labels Mar 15, 2021
@glendaviesnz
Copy link
Contributor

The tests seem to fail now:
https://github.com/Automattic/jetpack/pull/19002/checks?check_run_id=2098887487

@stacimc looks like the test failure is because the dependency tree that the jest test runner is using in the jetpack repo is older that the one that is used to compile the frontend client, and UnitControl is not available. Strange that it didn't fail locally for you though.

The Jetpack crew have been working to get the dependencies updated, in the mean time you will probably either need to comment out the tests that are mounting this part of the component, or you might be able to mock UnitControl in the spec file with something like:

jest.mock( '@wordpress/components', () => ( {
	...jest.requireActual( '@wordpress/components' ),
	__experimentalUnitControl: () => <div>Mocked Unit Control</div>,
} ) );

@stacimc
Copy link
Contributor Author

stacimc commented Mar 16, 2021

The tests seem to fail now:
https://github.com/Automattic/jetpack/pull/19002/checks?check_run_id=2098887487

@stacimc looks like the test failure is because the dependency tree that the jest test runner is using in the jetpack repo is older that the one that is used to compile the frontend client, and UnitControl is not available. Strange that it didn't fail locally for you though.

My apologies -- there were a couple of PRs affected by this and I missed updating the status/comment on this one. Yes, this is being held up by the dependency update :(

I like the suggestion of mocking it for now. I'll work on that and create a follow up to include removing the mock and adding additional tests for the width.

@stacimc
Copy link
Contributor Author

stacimc commented Mar 16, 2021

I've temporarily mocked out the width controls for now, follow up issue to fix at: 253-gh-Automattic/view-design

@stacimc stacimc added [Status] Needs Review To request a review from Crew. Label will be renamed soon. and removed [Status] Needs Author Reply We would need you to make some changes or provide some more details about your PR. Thank you! labels Mar 17, 2021
@jeherve jeherve added [Status] Ready to Merge Go ahead, you can push that green button! and removed [Status] Needs Review To request a review from Crew. Label will be renamed soon. labels Mar 17, 2021
@stacimc stacimc merged commit a78c2df into master Mar 18, 2021
@stacimc stacimc deleted the add/button-tests branch March 18, 2021 17:41
@matticbot matticbot removed the [Status] Ready to Merge Go ahead, you can push that green button! label Mar 18, 2021
@github-actions
Copy link
Contributor

Great news! One last step: head over to your WordPress.com diff, D58003-code, and commit it.
Once you've done so, come back to this PR and add a comment with your changeset ID.

Thank you!

@stacimc
Copy link
Contributor Author

stacimc commented Mar 18, 2021

Holding off on deploying this one, as it relies on #18809 (which needs to be deployed along with the release for the sake of Atomic sites).

@jeherve
Copy link
Member

jeherve commented Apr 6, 2021

r223840-wpcom

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Block] Button [Plugin] Jetpack Issues about the Jetpack plugin. https://wordpress.org/plugins/jetpack/ Touches WP.com Files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants