woocommerce / google-listings-and-ads

Sync your store with Google to list products for free, run paid ads, and track performance straight from your store dashboard.
https://woo.com/products/google-listings-and-ads/
GNU General Public License v3.0
45 stars 21 forks source link

Update Block validation to support error context #2511

Closed martynmjones closed 1 month ago

martynmjones commented 1 month ago

Changes proposed in this Pull Request:

Closes #2507

Updates Block validation to return an object containing the error message and the clientId as context to support the new link displayed in the snackbar.

Screenshot 2024-08-07 at 16 09 11

Additionally, with WooCommerce 9.2.0-rc.1 the Multipack field validation changes so if a decimal value was entered a blank error message was displayed:

Screenshot 2024-08-07 at 21 58 27

As it's not possible to either set a default validation error message or add custom rules outside of the supported few, the field has been updated to use a text field instead of number. A pattern is then supplied with a custom error message to prevent users from entering non numeric values, decimal values, or negative values.

Screenshot 2024-08-08 at 12 06 32

Detailed test instructions:

  1. npm run wp-env:up
  2. npm run -- wp-env run tests-cli -- wp plugin update woocommerce --version=9.2.0-rc.1
  3. npm run -- wp-env run tests-cli -- wp wc update
  4. npm run test:e2e
  5. Confirm tests pass
  6. Enable the new product editor in WooCommerce > Settings > Advanced > Features
  7. Edit a product and test different values in the Multipack field under the Google for WooCommerce tab
  8. Confirm only whole numbers are accepted input

Additional

⚠️ Please merge once approved as this PR is required before GLA can be released with the 9.2.0 compat bump.

Changelog entry

Update - Block validation to support error context

codecov[bot] commented 1 month ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 64.7%. Comparing base (b3545b5) to head (ea781f6). Report is 33 commits behind head on develop.

Additional details and impacted files [![Impacted file tree graph](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511/graphs/tree.svg?width=650&height=150&src=pr&token=UROWUPF1LX&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) ```diff @@ Coverage Diff @@ ## develop #2511 +/- ## ============================================ + Coverage 63.5% 64.7% +1.2% - Complexity 0 4580 +4580 ============================================ Files 322 801 +479 Lines 5043 22976 +17933 Branches 1220 1229 +9 ============================================ + Hits 3204 14875 +11671 - Misses 1672 7934 +6262 Partials 167 167 ``` | [Flag](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [js-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `63.8% <ø> (+0.3%)` | :arrow_up: | | [php-unit-tests](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | `65.0% <100.0%> (?)` | | Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#carryforward-flags-in-the-pull-request-comment) to find out more. | [Files](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce) | Coverage Δ | | |---|---|---| | [src/Admin/Input/Integer.php](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511?src=pr&el=tree&filepath=src%2FAdmin%2FInput%2FInteger.php&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce#diff-c3JjL0FkbWluL0lucHV0L0ludGVnZXIucGhw) | `100.0% <100.0%> (ø)` | | ... and [480 files with indirect coverage changes](https://app.codecov.io/gh/woocommerce/google-listings-and-ads/pull/2511/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=woocommerce)