diff --git a/.github/workflows/e2e.yml b/.github/workflows/e2e.yml index 9234bdc7..ccb4e0ab 100644 --- a/.github/workflows/e2e.yml +++ b/.github/workflows/e2e.yml @@ -20,7 +20,10 @@ jobs: env: CYPRESS_MAILCHIMP_USERNAME: ${{ secrets.MAILCHIMP_USERNAME }} CYPRESS_MAILCHIMP_PASSWORD: ${{ secrets.MAILCHIMP_PASSWORD }} + CYPRESS_MAILCHIMP_API_KEY: ${{ secrets.MAILCHIMP_API_KEY }} + CYPRESS_MAILCHIMP_API_SERVER_PREFIX: ${{ secrets.MAILCHIMP_API_SERVER_PREFIX }} strategy: + max-parallel: 1 matrix: core: - {name: 'WP latest', version: 'latest'} diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c1739e7..dcc3acac 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,14 +4,51 @@ All notable changes to this project will be documented in this file, per [the Ke ## [Unreleased] - TBD +## [1.7.0] - 2025-04-08 + +### Changed + +- Enhance the Mailchimp List Subscribe Form block to allow for selecting an audience list, reorder fields, toggle field and group visibility, and various other improvements (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +- Plugin settings page success and error messages will now use WP admin notices (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@iamdharmesh](https://github.com/iamdharmesh) via [#85](https://github.com/mailchimp/wordpress/pull/85)). +- Renamed `mailchimp_sf_global_msg` function to `mailchimp_sf_frontend_msg` to differentiate functionality from WP admin notices that are used exclusively in the WP Admin (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@iamdharmesh](https://github.com/iamdharmesh) via [#85](https://github.com/mailchimp/wordpress/pull/85)). +- Make the form field visibility dependent on the WordPress "Include?" settings instead of the Mailchimp settings (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#137](https://github.com/mailchimp/wordpress/pull/137)). + +### Fixed + +- Ensure that form data persists when validation fails (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#130](https://github.com/mailchimp/wordpress/pull/130)). +- Display an error message informing users that they must subscribe through the hosted form if they were previously unsubscribed (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#131](https://github.com/mailchimp/wordpress/pull/131), [#140](https://github.com/mailchimp/wordpress/pull/140)). + +### Removed + +- The "CSS Cheat Sheet" section from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +- The "Use JavaScript Support?" option from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +- The "Use JavaScript Datepicker?" option from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +- The "Custom Styling" settings from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +- The "Remove Mailchimp CSS" settings from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). + +### Security + +- Bump `express` from 4.21.0 to 4.21.2 (props [@dependabot](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter) via [#125](https://github.com/mailchimp/wordpress/pull/125)). + +### Developer + +- New tests to cover E2E critical flows (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@iamdharmesh](https://github.com/iamdharmesh) via [#87](https://github.com/mailchimp/wordpress/pull/87), [#99](https://github.com/mailchimp/wordpress/pull/99)). +- Update existing tests to more robustly cover E2E critical flows. Modularized reusable testing code (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@iamdharmesh](https://github.com/iamdharmesh) via [#87](https://github.com/mailchimp/wordpress/pull/87), [#99](https://github.com/mailchimp/wordpress/pull/99)). +- Update all third-party actions our workflows rely on to use versions based on specific commit hashes (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul), [@iamdharmesh](https://github.com/iamdharmesh) via [#128](https://github.com/mailchimp/wordpress/pull/128)). +- Prevent overwriting the release content with the body text provided in the GitHub Action workflow file (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter) via [#129](https://github.com/mailchimp/wordpress/pull/129)). + ## [1.6.3] - 2025-01-30 + ### Added + - Transform the `mailchimp_sf_shortcode` shortcode to the Mailchimp List Subscribe Form block (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#84](https://github.com/mailchimp/wordpress/pull/84)). ### Removed + - Deprecated Sopresto code (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#98](https://github.com/mailchimp/wordpress/pull/98)). ### Fixed + - Fatal PHP error that would occur when the phone merge field was set to US format, but the merge field was not included in the Mailchimp plugin (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#108](https://github.com/mailchimp/wordpress/pull/108)). - Bug causing merge fields on the Mailchimp WP admin page to incorrectly display as not required when they were, in fact, required (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#109](https://github.com/mailchimp/wordpress/pull/109)). - Fix an issue that allows a user to select merge fields that were not selected as visible in the Mailchimp account (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#110](https://github.com/mailchimp/wordpress/pull/110)). @@ -20,41 +57,53 @@ All notable changes to this project will be documented in this file, per [the Ke - Pending contacts will now still be required to confirm their original confirmation email if they try to update their contact while "Update Existing Subscribers?" and "Double Opt-in" are both enabled (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#115](https://github.com/mailchimp/wordpress/pull/115)). ### Security + - Bump `nanoid` from 3.3.7 to 3.3.8 (props [@dependabot](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh) via [#111](https://github.com/mailchimp/wordpress/pull/111)). ### Developer + - Add autoloading using composer (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#95](https://github.com/mailchimp/wordpress/pull/95)). - Updated GitHub Action step for generating the release assets (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#97](https://github.com/mailchimp/wordpress/pull/97)). ## [1.6.2] - 2024-11-12 + **Note that this release bumps the WordPress minimum version from 6.1 to 6.3.** ### Changed + - Bump WordPress "tested up to" version 6.7 (props [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@vikrampm1](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter) via [#71](https://github.com/mailchimp/wordpress/pull/71)). - Bump WordPress minimum supported version from 6.1 to 6.3 (props [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@vikrampm1](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter) via [#71](https://github.com/mailchimp/wordpress/pull/71)). ### Fixed + - Ensure the field name is properly added to the error message when the email address is blank (props [@iamdharmesh](https://github.com/iamdharmesh), [@jerclarke](https://github.com/jerclarke), [@dkotter](https://github.com/dkotter) via [#74](https://github.com/mailchimp/wordpress/pull/74)). ### Developer + - Remove the Advanced Section from our readme files (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter) via [#77](https://github.com/mailchimp/wordpress/pull/77)). ## [1.6.1] - 2024-10-14 + ### Changed + - Improved migration flow from API Key to OAuth authentication for a better user experience (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#67](https://github.com/mailchimp/wordpress/pull/67)). - Updated the menu SVG icon (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#65](https://github.com/mailchimp/wordpress/pull/65)). ### Fixed + - Ensure that the settings remain persistent between logging out of the account and logging in again (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#66](https://github.com/mailchimp/wordpress/pull/66)). ### Security + - Bump `serve-static` from 1.15.0 to 1.16.2 and `express` from 4.19.2 to 4.21.0 (props [@dependabot](https://github.com/apps/dependabot), [@dkotter](https://github.com/dkotter) via [#55](https://github.com/mailchimp/wordpress/pull/55)). - Bump `webpack` from 5.91.0 to 5.94.0 (props [@dependabot](https://github.com/apps/dependabot), [@dkotter](https://github.com/dkotter) via [#59](https://github.com/mailchimp/wordpress/pull/59)). ## [1.6.0] - 2024-09-24 + **Note this version increased the WordPress minimum version to 6.1 and the PHP minimum version to 7.0.** ### Added + - Mailchimp List Subscribe Form custom block (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#35](https://github.com/mailchimp/wordpress/pull/35), [#38](https://github.com/mailchimp/wordpress/pull/38)). - PHP 8.3 compatibility and minimum PHP version of 7.0 (props [@nateconley](https://github.com/nateconley), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#26](https://github.com/mailchimp/wordpress/pull/26)). - WordPress 6.6 compatibility (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#27](https://github.com/mailchimp/wordpress/pull/27)). @@ -64,6 +113,7 @@ All notable changes to this project will be documented in this file, per [the Ke - Plugin icon and banner assets (props [@eddieshrake](https://github.com/eddieshrake), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#28](https://github.com/mailchimp/wordpress/pull/28)). ### Changed + - Bump WordPress "tested up to" version 6.6 (props [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@vikrampm1](https://github.com/vikrampm1), [@jeffpaul](https://github.com/jeffpaul) via [#43](https://github.com/mailchimp/wordpress/pull/43)). - Ensure the signup form is only visible when a list is selected in the settings (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#54](https://github.com/mailchimp/wordpress/pull/54)). - Moved settings page and link to top-level WP Admin menu item (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#29](https://github.com/mailchimp/wordpress/pull/29), [#33](https://github.com/mailchimp/wordpress/pull/33)). @@ -74,16 +124,19 @@ All notable changes to this project will be documented in this file, per [the Ke - Moved translations to [GlotPress](https://translate.wordpress.org/projects/wp-plugins/mailchimp/) (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#39](https://github.com/mailchimp/wordpress/pull/39)). ### Deprecated + - Function `mailchimpSF_signup_form` deprecated in favor of `mailchimp_sf_signup_form` (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter) via [#24](https://github.com/mailchimp/wordpress/pull/24)). - jQuery scrollTo (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#27](https://github.com/mailchimp/wordpress/pull/27)). ### Removed + - Support for WordPress < 6.1.1 (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#27](https://github.com/mailchimp/wordpress/pull/27)). - Polyfills for WordPress < 2.8.0 (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#27](https://github.com/mailchimp/wordpress/pull/27)). - Monkey Rewards integration (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#30](https://github.com/mailchimp/wordpress/pull/30)). - IE-specific admin stylesheet (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul), [@eddieshrake](https://github.com/eddieshrake) via [#31](https://github.com/mailchimp/wordpress/pull/31)). ### Fixed + - Formatting from linting checks (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter) via [#23](https://github.com/mailchimp/wordpress/pull/23)). - Datepicker display on frontend (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#25](https://github.com/mailchimp/wordpress/pull/25)). - Accessibility for admin settings page (props [@nateconley](https://github.com/nateconley), [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul), [@eddieshrake](https://github.com/eddieshrake) via [#31](https://github.com/mailchimp/wordpress/pull/31)). @@ -92,6 +145,7 @@ All notable changes to this project will be documented in this file, per [the Ke - Address some PHP warnings when a form submission happens (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#54](https://github.com/mailchimp/wordpress/pull/54)). ### Developer + - Created a `README.md` file from the `readme.txt` content (props [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#14](https://github.com/mailchimp/wordpress/pull/14), [#22](https://github.com/mailchimp/wordpress/pull/22)). - Created `CODE_OF_CONDUCT.md`, `CONTRIBUTING.md`, `SECURITY.md`, Issue and PR templates, Dependabot config file, and `composer.json` and `package.json` base files (props [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter) via [#15](https://github.com/mailchimp/wordpress/pull/15)). - Added WordPress Version Checker and Build Release Zip GitHub Action Workflows (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#16](https://github.com/mailchimp/wordpress/pull/16)). @@ -102,92 +156,117 @@ All notable changes to this project will be documented in this file, per [the Ke - Added Standard GitHub Action Workflows (props [@dkotter](https://github.com/dkotter), [@jeffpaul](https://github.com/jeffpaul) via [#21](https://github.com/mailchimp/wordpress/pull/21)). ## 1.5.8 - 2022-09-26 + ### Changed + - Updated `readme.txt` link. ### Fixed + - PHP warning for merge tags. - Double slashes on resources being loaded. ## 1.5.7 + - Fix undefined variable notice. - Fix HTML submission message. ## 1.5.6 + - Fixes short array notation which caused a fatal error in older PHP versions. ## 1.5.5 + - Fix timeout error on activation. ## 1.5.4 + - Set optional value for API wrapper. ## 1.5.3 - 2016-11-01 + - Fix PHP7 compatibility issue - Cut down on size of API requests for users with large lists. - Fix CSS issue on removing Mailchimp style. ## 1.5.2 - 206-08-17 + - General bugfixes for merge fields. - When re-initializing, update merge field values. ## 1.5.1 + - Bugfix for fatal error in Mailchimp lib. ## 1.5 - 2016-07-13 + - Upgrade to Mailchimp API v3.0 - Remove OAuth2 middle layer and use Mailchimp API keys. - Include double/single opt-in toggle. ## 1.4.2 - 2014-09-19 + - Updated for WordPress 4.0 postback compatibility. ## 1.4.1 - 2013-11-21 + - Update styles to be compatible with upcoming 3.8 wp-admin changes. ## 1.4 - 2013-11-19 + - Developer Mode "Kitchen Sink" takes over plugin for local development. - Developer Mode has filters of changeable content. - Fix bug related to required US phone validation. ## 1.3 - 2013-10-03 + - Now using OAuth flow for user authentication. - Admin UI refresh. ## 1.2.14 - 2013-04-01 + - Add link to edit profile within error when duplicate signup occurs. ## 1.2.13 - 2012-11-26 + - Fixed bug preventing address fields from submitting correctly. ## 1.2.12 - 2012-10-23 + - Update spanish language files (es_ES and es_MX). ## 1.2.11 - 2012-09-20 + - Updating translation strings. ## 1.2.10 - 2012-08-27 + - Invalid group fix. ## 1.2.9 - 2012-04-17 + - Fixed bug where multiple checkbox type interest groups were returning an invalid error. - Fixed bug where assets were not enqueueing properly if the plugin directory was not set to 'mailchimp'. Now supports any directory name. ## 1.2.8 - 2012-03-12 + - Fixed bug where entire phone numbers were only being deposited in the area code portion. ## 1.2.7 - 2012-02-21 + - CSS should now always load correctly on the front end. - Adding Hebrew and Romanian language support. - Updating translation contribution instructions. - Tested version is now 3.3.1. ## 1.2.6 - 2011-11-10 + - Fixed bug with "Settings" link appearing on all plugins (props Jason Lane). - Resolved issue with unnecessary calls to the Mailchimp API during upgrade check. - Resolved PHP warning when there weren't any interest groups. ## 1.2.5 - 2011-09-22 + - Field formatting based on type - Support for multiple interest groups (a data upgrade procedure must be run by visiting the WordPress dashboard). - Added jQuery datepicker option to be used with dates. @@ -195,25 +274,31 @@ All notable changes to this project will be documented in this file, per [the Ke - Fixing various PHP notices and deprecated functions (props Jeffry Ghazally). ## 1.2.4 - 2011-04-14 + - Version bump for proper listing on wordpress.org. ## 1.2.3 - 2011-04-11 + - Change mailchimp_sf_where_am_i() to use plugins_url() in place of WP_PLUGIN_URL to take SSL into account when delivering assets (props John LeBlanc). - Update MCAPI wrapper to bring back PHP4 support (note: PHP 5.2 to be required starting with WordPress 3.2). ## 1.2.2 - 2011-02-09 + - Change MCAPI wrapper to use a more unique class name, v1.3 of the API, and a much lighter client library. ## 1.2.1 - 2010-11-09 + - Fixed internationalization path bug. - Fixed instances where i18n functions weren't necessary in admin. - Added more strings to be translated. ## 1.2 - 2010-10-14 + - Recommended Upgrade, please see "Upgrading" section of readme. - Security and various other improvements [Unreleased]: https://github.com/mailchimp/wordpress/compare/main...develop +[1.7.0]: https://github.com/mailchimp/wordpress/compare/1.6.3...1.7.0 [1.6.3]: https://github.com/mailchimp/wordpress/compare/1.6.2...1.6.3 [1.6.2]: https://github.com/mailchimp/wordpress/compare/1.6.1...1.6.2 [1.6.1]: https://github.com/mailchimp/wordpress/compare/1.6.0...1.6.1 diff --git a/includes/blocks/class-mailchimp-list-subscribe-form-blocks.php b/includes/blocks/class-mailchimp-list-subscribe-form-blocks.php index e5a0a22f..fbc13408 100644 --- a/includes/blocks/class-mailchimp-list-subscribe-form-blocks.php +++ b/includes/blocks/class-mailchimp-list-subscribe-form-blocks.php @@ -13,7 +13,7 @@ /** * Class Mailchimp_List_Subscribe_Form_Blocks * - * @since x.x.x + * @since 1.7.0 */ class Mailchimp_List_Subscribe_Form_Blocks { diff --git a/includes/class-mailchimp-admin.php b/includes/class-mailchimp-admin.php index a700d8e4..53f675d9 100644 --- a/includes/class-mailchimp-admin.php +++ b/includes/class-mailchimp-admin.php @@ -509,7 +509,7 @@ public function enqueue_admin_page_scripts( $hook_suffix ) { /** * Add the create account page. * - * @since x.x.x + * @since 1.6.0 */ public function add_create_account_page() { add_submenu_page( @@ -525,7 +525,7 @@ public function add_create_account_page() { /** * Create account page. * - * @since x.x.x + * @since 1.6.0 * * @return void */ @@ -544,7 +544,7 @@ public function create_account_page() { /** * Get a list of timezones. * - * @since x.x.x + * @since 1.6.0 * * @return array */ @@ -555,7 +555,7 @@ private function get_timezones() { /** * Get a list of countries. * - * @since x.x.x + * @since 1.6.0 * * @return array */ @@ -816,7 +816,7 @@ public function get_countries() { /** * Display the Mailchimp footer text on the Mailchimp admin pages. * - * @since x.x.x + * @since 1.6.0 * * @param string $text The current footer text. * @return string The modified footer text. diff --git a/includes/class-mailchimp-block-form-submission.php b/includes/class-mailchimp-block-form-submission.php index fbb9c911..3a203e6c 100644 --- a/includes/class-mailchimp-block-form-submission.php +++ b/includes/class-mailchimp-block-form-submission.php @@ -13,7 +13,7 @@ /** * Class Mailchimp_Block_Form_Submission * - * @since x.x.x + * @since 1.7.0 */ class Mailchimp_Block_Form_Submission { diff --git a/mailchimp.php b/mailchimp.php index b4563ffc..babb9572 100644 --- a/mailchimp.php +++ b/mailchimp.php @@ -4,7 +4,7 @@ * Plugin URI: https://mailchimp.com/help/connect-or-disconnect-list-subscribe-for-wordpress/ * Description: Add a Mailchimp signup form block, widget or shortcode to your WordPress site. * Text Domain: mailchimp - * Version: 1.6.3 + * Version: 1.7.0 * Requires at least: 6.3 * Requires PHP: 7.0 * PHP tested up to: 8.3 @@ -67,7 +67,7 @@ function () { use function Mailchimp\WordPress\Includes\Admin\{admin_notice_error, admin_notice_success}; // Version constant for easy CSS refreshes -define( 'MCSF_VER', '1.6.3' ); +define( 'MCSF_VER', '1.7.0' ); // What's our permission (capability) threshold define( 'MCSF_CAP_THRESHOLD', 'manage_options' ); @@ -987,7 +987,7 @@ function mailchimp_sf_merge_submit( $mv ) { */ case 'phone': if ( - 'on' === get_option( $opt ) + ( 'on' === get_option( $opt ) || $mv_var['required'] ) && isset( $mv_var['options']['phone_format'] ) && 'US' === $mv_var['options']['phone_format'] ) { @@ -1006,7 +1006,7 @@ function mailchimp_sf_merge_submit( $mv ) { * - Merge field is an array (address contains multiple elements) */ case 'address': - if ( 'on' === get_option( $opt ) && is_array( $opt_val ) ) { + if ( ( 'on' === get_option( $opt ) || $mv_var['required'] ) && is_array( $opt_val ) ) { $validate = mailchimp_sf_merge_validate_address( $opt_val, $mv_var ); if ( is_wp_error( $validate ) ) { return $validate; diff --git a/mailchimp_widget.php b/mailchimp_widget.php index 6f179b8d..1a57912e 100644 --- a/mailchimp_widget.php +++ b/mailchimp_widget.php @@ -184,7 +184,7 @@ function mailchimp_sf_signup_form( $args = array() ) {
-
+
diff --git a/package-lock.json b/package-lock.json index ceedfbe7..102bd95c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@mailchimp/wordpress", - "version": "1.6.3", + "version": "1.7.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@mailchimp/wordpress", - "version": "1.6.3", + "version": "1.7.0", "license": "GPL-2.0-or-later", "dependencies": { "@wordpress/block-editor": "^13.2.0", diff --git a/package.json b/package.json index 92eaaf8a..ebe36650 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@mailchimp/wordpress", - "version": "1.6.3", + "version": "1.7.0", "description": "Add a Mailchimp signup form widget to your WordPress site.", "homepage": "https://github.com/mailchimp/wordpress", "bugs": { diff --git a/readme.txt b/readme.txt index 13d03dc4..5e43b2e0 100644 --- a/readme.txt +++ b/readme.txt @@ -2,7 +2,7 @@ Contributors: Mailchimp Tags: mailchimp, email, newsletter, signup, marketing Tested up to: 6.7 -Stable tag: 1.6.3 +Stable tag: 1.7.0 License: GPL-2.0-or-later License URI: https://spdx.org/licenses/GPL-2.0-or-later.html @@ -81,6 +81,20 @@ If you are upgrading to version 1.2.1 and you used the widget in your sidebar pr == Changelog == += 1.7.0 - 2025-04-08 = +* **Changed:** Enhance the Mailchimp List Subscribe Form block to allow for selecting an audience list, reorder fields, toggle field and group visibility, and various other improvements (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Changed:** Plugin settings page success and error messages will now use WP admin notices (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@iamdharmesh](https://github.com/iamdharmesh) via [#85](https://github.com/mailchimp/wordpress/pull/85)). +* **Changed:** Renamed `mailchimp_sf_global_msg` function to `mailchimp_sf_frontend_msg` to differentiate functionality from WP admin notices that are used exclusively in the WP Admin (props [@MaxwellGarceau](https://github.com/MaxwellGarceau), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@iamdharmesh](https://github.com/iamdharmesh) via [#85](https://github.com/mailchimp/wordpress/pull/85)). +* **Changed:** Make the form field visibility dependent on the WordPress "Include?" settings instead of the Mailchimp settings (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#137](https://github.com/mailchimp/wordpress/pull/137)). +* **Fixed:** Ensure that form data persists when validation fails (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#130](https://github.com/mailchimp/wordpress/pull/130)). +* **Fixed:** Display an error message informing users that they must subscribe through the hosted form if they were previously unsubscribed (props [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya), [@MaxwellGarceau](https://github.com/MaxwellGarceau) via [#131](https://github.com/mailchimp/wordpress/pull/131), [#140](https://github.com/mailchimp/wordpress/pull/140)). +* **Removed:** The "CSS Cheat Sheet" section from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Removed:** The "Use JavaScript Support?" option from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Removed:** The "Use JavaScript Datepicker?" option from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Removed:** The "Custom Styling" settings from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Removed:** The "Remove Mailchimp CSS" settings from the Mailchimp settings page (props [@iamdharmesh](https://github.com/iamdharmesh), [@jeffpaul](https://github.com/jeffpaul), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#126](https://github.com/mailchimp/wordpress/pull/126)). +* **Security:** Bump `express` from 4.21.0 to 4.21.2 (props [@dependabot](https://github.com/apps/dependabot), [@iamdharmesh](https://github.com/iamdharmesh), [@dkotter](https://github.com/dkotter) via [#125](https://github.com/mailchimp/wordpress/pull/125)). + = 1.6.3 - 2025-01-30 = * **Added:** Transform the `mailchimp_sf_shortcode` shortcode to the Mailchimp List Subscribe Form block (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter), [@qasumitbagthariya](https://github.com/qasumitbagthariya) via [#84](https://github.com/mailchimp/wordpress/pull/84)). * **Removed:** Deprecated Sopresto code (props [@MaxwellGarceau](https://github.com/qasumitbagthariya), [@jeffpaul](https://github.com/vikrampm1), [@dkotter](https://github.com/dkotter) via [#98](https://github.com/mailchimp/wordpress/pull/98)). diff --git a/tests/cypress/config.js b/tests/cypress/config.js index 07b91585..0c7ef460 100644 --- a/tests/cypress/config.js +++ b/tests/cypress/config.js @@ -1,9 +1,9 @@ -const { defineConfig } = require( 'cypress' ); -const { loadConfig } = require( '@wordpress/env/lib/config' ); -const getCacheDirectory = require( '@wordpress/env/lib/config/get-cache-directory' ); +const { defineConfig } = require('cypress'); +const { loadConfig } = require('@wordpress/env/lib/config'); +const getCacheDirectory = require('@wordpress/env/lib/config/get-cache-directory'); const dotenvPlugin = require('cypress-dotenv'); -module.exports = defineConfig( { +module.exports = defineConfig({ chromeWebSecurity: false, fixturesFolder: 'tests/cypress/fixtures', screenshotsFolder: 'tests/cypress/screenshots', @@ -13,21 +13,24 @@ module.exports = defineConfig( { reporter: 'mochawesome', reporterOptions: { mochaFile: 'mochawesome-[name]', - reportDir: __dirname + '/reports', + reportDir: `${__dirname}/reports`, overwrite: false, html: false, json: true, }, e2e: { - setupNodeEvents( on, config ) { + setupNodeEvents(on, config) { config = dotenvPlugin(config, { path: '../../.env.test' }); // Load .env variables into Cypress - return setBaseUrl( on, config ); + return setBaseUrl(on, config); }, specPattern: [ - 'tests/cypress/e2e/admin.test.js', + 'tests/cypress/e2e/settings/admin.test.js', 'tests/cypress/e2e/connect.test.js', - 'tests/cypress/e2e/settings.test.js', - 'tests/cypress/e2e/mailchimp-block.test.js', + 'tests/cypress/e2e/settings/list.test.js', + 'tests/cypress/e2e/settings/settings.test.js', + 'tests/cypress/e2e/submission/**.test.js', + 'tests/cypress/e2e/validation/**.test.js', + 'tests/cypress/e2e/block.test.js', 'tests/cypress/e2e/logout.test.js', ], supportFile: 'tests/cypress/support/index.js', @@ -38,23 +41,23 @@ module.exports = defineConfig( { runMode: 2, openMode: 0, }, -} ); +}); /** * Set WP URL as baseUrl in Cypress config. * * @param {Function} on function that used to register listeners on various events. - * @param {Object} config Cypress Config object. - * @return {Object} Updated Cypress Config object. + * @param {object} config Cypress Config object. + * @returns {object} Updated Cypress Config object. */ -const setBaseUrl = async ( on, config ) => { +const setBaseUrl = async (on, config) => { const cacheDirectory = await getCacheDirectory(); - const wpEnvConfig = await loadConfig( cacheDirectory ); + const wpEnvConfig = await loadConfig(cacheDirectory); - if ( wpEnvConfig ) { + if (wpEnvConfig) { const port = wpEnvConfig.env.tests.port || null; - if ( port ) { + if (port) { config.baseUrl = wpEnvConfig.env.tests.config.WP_SITEURL; } } diff --git a/tests/cypress/e2e/mailchimp-block.test.js b/tests/cypress/e2e/block.test.js similarity index 97% rename from tests/cypress/e2e/mailchimp-block.test.js rename to tests/cypress/e2e/block.test.js index ee3638c1..89dd5670 100644 --- a/tests/cypress/e2e/mailchimp-block.test.js +++ b/tests/cypress/e2e/block.test.js @@ -4,6 +4,13 @@ describe('Block Tests', () => { before(() => { cy.login(); + cy.mailchimpLoginIfNotAlreadyLoggedIn(); + cy.toggleMergeFields('check'); + + // Hide all interest groups + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); + cy.get('input[id^="mc_show_interest_groups_"]').uncheck(); + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); }); it('Admin can create a Signup form using Mailchimp block', () => { diff --git a/tests/cypress/e2e/settings.test.js b/tests/cypress/e2e/settings.test.js deleted file mode 100644 index 30acba27..00000000 --- a/tests/cypress/e2e/settings.test.js +++ /dev/null @@ -1,200 +0,0 @@ -/* eslint-disable no-undef */ -describe('Admin can update plugin settings', () => { - let shortcodePostURL = '/mailchimp-signup-form-shortcode'; - let blockPostPostURL = '/mailchimp-signup-form-block'; - - before(() => { - cy.login(); - }); - - it('Admin can see list and save it', () => { - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - - cy.get('.mc-h2').contains('Your Lists'); - cy.get('#mc_list_id').select('10up'); - cy.get('input[value="Update List"]').click(); - cy.get('#mailchimp-sf-settings-page .notice.notice-success p').contains('Success!'); - }); - - it('Admin can create a Signup form using the shortcode', () => { - const postTitle = 'Mailchimp signup form - shortcode'; - const beforeSave = () => { - cy.insertBlock('core/shortcode').then((id) => { - cy.getBlockEditor() - .find(`#${id} .blocks-shortcode__textarea`) - .clear() - .type('[mailchimpsf_form]'); - }); - }; - cy.createPost({ title: postTitle, content: '', beforeSave }).then((post) => { - if (post) { - shortcodePostURL = `/?p=${post.id}`; - cy.visit(shortcodePostURL); - cy.get('#mc_signup').should('exist'); - cy.get('#mc_mv_EMAIL').should('exist'); - cy.get('#mc_signup_submit').should('exist'); - cy.get('#mc_signup_submit').click(); - cy.get('.mc_error_msg').should('exist'); - cy.get('.mc_error_msg').contains('Email Address: This value should not be blank.'); - } - }); - }); - - it('Admin can create a Signup form using Mailchimp block', () => { - const postTitle = 'Mailchimp signup form - Block'; - // Creating a post with Mailchimp block using wpCLI to test the backward compatibility of the existing block. - cy.wpCli( - `wp post create --post_title='${postTitle}' --post_content='' --post_status='publish' --porcelain`, - ).then((response) => { - blockPostPostURL = `/?p=${response.stdout}`; - cy.visit(blockPostPostURL); - cy.get('#mc_signup').should('exist'); - cy.get('#mc_mv_EMAIL').should('exist'); - cy.get('#mc_signup_submit').should('exist'); - cy.get('#mc_signup_submit').click(); - cy.get('.mc_error_msg').should('exist'); - cy.get('.mc_error_msg').contains('Email Address: This value should not be blank.'); - }); - }); - - it('Admin can set content options for signup form', () => { - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - - // Set content options - const header = 'Subscribe to our newsletter'; - const subHeader = - 'Join our mailing list to receive the latest news and updates from our team.'; - const button = 'Subscribe Now'; - cy.get('#mc_header_content').clear().type(header); - cy.get('#mc_subheader_content').clear().type(subHeader); - cy.get('#mc_submit_text').clear().type(button); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify content options - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('.mc_custom_border_hdr').contains(header); - cy.get('#mc_subheader').contains(subHeader); - cy.get('#mc_signup_submit').contains(button); - }); - }); - - it('Admin can set Merge Fields Included settings', () => { - // Remove mailchimp CSS. - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_mv_FNAME').uncheck(); - cy.get('#mc_mv_LNAME').uncheck(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_mv_FNAME').should('not.exist'); - cy.get('#mc_mv_LNAME').should('not.exist'); - }); - - // Reset - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_mv_FNAME').check(); - cy.get('#mc_mv_LNAME').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_mv_FNAME').should('exist'); - cy.get('#mc_mv_LNAME').should('exist'); - }); - }); - - it('Admin can update groups settings', () => { - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('input[id^="mc_show_interest_groups_"]').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('.mc_interests_header').should('exist'); - cy.get('.mc_interest').should('exist'); - }); - - // Reset - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('input[id^="mc_show_interest_groups_"]').uncheck(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('.mc_interests_header').should('not.exist'); - cy.get('.mc_interest').should('not.exist'); - }); - }); - - it('Admin can set list options settings', () => { - // display unsubscribe link. - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_use_unsub_link').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_unsub_link').should('exist'); - }); - - // Reset - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_use_unsub_link').uncheck(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_unsub_link').should('not.exist'); - }); - }); - - it('Proper error message should display if unsubscribed user try to subscribe', () => { - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_double_optin').uncheck(); - cy.get('#mc_update_existing').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_mv_EMAIL').should('exist'); - cy.get('#mc_mv_EMAIL').clear().type('unsubscribed_user@gmail.com'); - cy.get('#mc_signup_submit').should('exist'); - cy.get('#mc_signup_submit').click(); - cy.get('.mc_error_msg').should('exist'); - cy.get('.mc_error_msg').contains( - 'The email address cannot be subscribed because it was previously unsubscribed, bounced, or is under review. Please sign up here.', - ); - }); - - // Reset - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_double_optin').check(); - cy.get('#mc_update_existing').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - }); - - it('Form data should persist if validation fails', () => { - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - const firstName = 'John'; - const lastName = 'Doe'; - cy.visit(url); - cy.get('#mc_mv_EMAIL').should('exist'); - cy.get('#mc_mv_FNAME').clear().type(firstName); - cy.get('#mc_mv_LNAME').clear().type(lastName); - cy.get('#mc_signup_submit').should('exist'); - cy.get('#mc_signup_submit').click(); - cy.get('.mc_error_msg').should('exist'); - cy.get('.mc_error_msg').contains('Email Address: This value should not be blank.'); - cy.get('#mc_mv_FNAME').should('have.value', firstName); - cy.get('#mc_mv_LNAME').should('have.value', lastName); - }); - }); -}); diff --git a/tests/cypress/e2e/settings/list.test.js b/tests/cypress/e2e/settings/list.test.js index 311e3c21..2c1d76f6 100644 --- a/tests/cypress/e2e/settings/list.test.js +++ b/tests/cypress/e2e/settings/list.test.js @@ -6,8 +6,7 @@ describe('Mailchimp lists ', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - shortcodePostURL = urls.shortcodePostURL; - blockPostPostURL = urls.blockPostPostURL; + ({ shortcodePostURL, blockPostPostURL } = urls); }); cy.login(); // WP @@ -40,7 +39,7 @@ describe('Mailchimp lists ', () => { // Verify that list can be saved cy.get('.mc-h2').contains('Your Lists'); cy.selectList('10up'); - cy.get('#mc-message .success_msg b').contains('Success!'); + cy.get('.notice.notice-success.is-dismissible').first().contains('Success!'); // Verify that the settings are visible if a list is saved cy.get('input[value="Update Subscribe Form Settings"]').should('exist'); diff --git a/tests/cypress/e2e/settings/settings.test.js b/tests/cypress/e2e/settings/settings.test.js index 40b0e98b..acfcd152 100644 --- a/tests/cypress/e2e/settings/settings.test.js +++ b/tests/cypress/e2e/settings/settings.test.js @@ -36,97 +36,6 @@ describe('Admin can update plugin settings', () => { }); }); - it('Admin can remove mailchimp CSS', () => { - // Remove mailchimp CSS. - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_nuke_all_styles').check(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_subheader').should('not.have.css', 'margin-bottom', '18px'); - }); - - // Enable mailchimp CSS. - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_nuke_all_styles').uncheck(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_subheader').should('have.css', 'margin-bottom', '18px'); - }); - }); - - it('Admin can set custom styling on signup form', () => { - // Enable custom styling and set values. - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_custom_style').check(); - cy.get('#mc_form_border_width').clear().type('10'); - cy.get('#mc_form_border_color').clear().type('000000'); - cy.get('#mc_form_text_color').clear().type('FF0000'); - cy.get('#mc_form_background').clear().type('00FF00'); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_signup form').should('have.css', 'border-width', '10px'); - cy.get('#mc_signup form').should('have.css', 'border-color', 'rgb(0, 0, 0)'); - cy.get('#mc_signup form').should('have.css', 'color', 'rgb(255, 0, 0)'); - cy.get('#mc_signup form').should('have.css', 'background-color', 'rgb(0, 255, 0)'); - - // Form is able to be submitted with custom styles - cy.get('#mc_signup_submit') - .scrollIntoView({ offset: { top: -100, left: 0 } }) - .should('be.visible') // Check if the button is visible - .and('not.be.disabled'); // Ensure the button is not disabled - - // Ensure that custom CSS does not cover submit button - cy.get('#mc_signup_submit').then(($el) => { - const rect = $el[0].getBoundingClientRect(); - - // Check that the element is within the viewport - cy.window().then((win) => { - const windowHeight = win.innerHeight; - const windowWidth = win.innerWidth; - - expect(rect.top).to.be.greaterThan(0); - expect(rect.left).to.be.greaterThan(0); - expect(windowHeight).to.be.greaterThan(0); - expect(windowWidth).to.be.greaterThan(0); - expect(rect.bottom).to.be.lessThan(windowHeight); - expect(rect.right).to.be.lessThan(windowWidth); - }); - - // Check if the center of the element is not covered by another element - const centerX = rect.x + $el[0].offsetWidth / 2; - const centerY = rect.y + $el[0].offsetHeight / 2; - - cy.document().then((doc) => { - const topElement = doc.elementFromPoint(centerX, centerY); - expect(topElement).to.equal($el[0]); - }); - }); - }); - - // Reset - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_custom_style').uncheck(); - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Verify base styles - [shortcodePostURL, blockPostPostURL].forEach((url) => { - cy.visit(url); - cy.get('#mc_signup form').should('not.have.css', 'border-width', '10px'); - cy.get('#mc_signup form').should('not.have.css', 'border-color', 'rgb(0, 0, 0)'); - cy.get('#mc_signup form').should('not.have.css', 'color', 'rgb(255, 0, 0)'); - cy.get('#mc_signup form').should('not.have.css', 'background-color', 'rgb(0, 255, 0)'); - }); - }); - it('Admin can set Merge Fields Included settings', () => { // Ensure that all current merge tags are up to date and saved cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); @@ -140,7 +49,6 @@ describe('Admin can update plugin settings', () => { cy.get('#mc_mv_ADDRESS').uncheck(); cy.get('#mc_mv_BIRTHDAY').uncheck(); cy.get('#mc_mv_COMPANY').uncheck(); - cy.get('#mc_mv_PHONE').uncheck(); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); // Verify @@ -151,7 +59,6 @@ describe('Admin can update plugin settings', () => { cy.get('#mc_mv_ADDRESS-addr1').should('not.exist'); // The address field has several inputs cy.get('#mc_mv_BIRTHDAY').should('not.exist'); cy.get('#mc_mv_COMPANY').should('not.exist'); - cy.get('#mc_mv_PHONE').should('not.exist'); }); // Reset and recheck all merge fields @@ -161,7 +68,6 @@ describe('Admin can update plugin settings', () => { cy.get('#mc_mv_ADDRESS').check(); cy.get('#mc_mv_BIRTHDAY').check(); cy.get('#mc_mv_COMPANY').check(); - cy.get('#mc_mv_PHONE').check(); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); // Verify @@ -172,7 +78,30 @@ describe('Admin can update plugin settings', () => { cy.get('#mc_mv_ADDRESS-addr1').should('exist'); // The address field has several inputs cy.get('#mc_mv_BIRTHDAY').should('exist'); cy.get('#mc_mv_COMPANY').should('exist'); - cy.get('#mc_mv_PHONE').should('exist'); + }); + }); + + it('Admin can update groups settings', () => { + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); + cy.get('input[id^="mc_show_interest_groups_"]').check(); + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); + + // Verify + [shortcodePostURL, blockPostPostURL].forEach((url) => { + cy.visit(url); + cy.get('.mc_interests_header').should('exist'); + cy.get('.mc_interest').should('exist'); + }); + + // Reset + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); + cy.get('input[id^="mc_show_interest_groups_"]').uncheck(); + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); + + [shortcodePostURL, blockPostPostURL].forEach((url) => { + cy.visit(url); + cy.get('.mc_interests_header').should('not.exist'); + cy.get('.mc_interest').should('not.exist'); }); }); @@ -183,38 +112,70 @@ describe('Admin can update plugin settings', () => { it('Admin can set list options settings', () => { // Remove mailchimp JavaScript support. cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_use_javascript').uncheck(); - cy.get('#mc_use_datepicker').uncheck(); cy.get('#mc_use_unsub_link').check(); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); // Verify [shortcodePostURL, blockPostPostURL].forEach((url) => { cy.visit(url); - cy.get('#mc_submit_type').should('have.value', 'html'); - cy.get('#mc_mv_BIRTHDAY').should('not.have.class', 'hasDatepicker'); - cy.get('#mc_mv_BIRTHDAY').click(); - cy.get('#ui-datepicker-div').should('not.exist'); cy.get('#mc_unsub_link').should('exist'); }); // Reset cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_use_javascript').check(); - cy.get('#mc_use_datepicker').check(); cy.get('#mc_use_unsub_link').uncheck(); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); [shortcodePostURL, blockPostPostURL].forEach((url) => { cy.visit(url); - cy.get('#mc_submit_type').should('have.value', 'js'); - cy.get('#mc_mv_BIRTHDAY').should('have.class', 'hasDatepicker'); - cy.get('#mc_mv_BIRTHDAY').click(); - cy.get('#ui-datepicker-div').should('exist'); cy.get('#mc_unsub_link').should('not.exist'); }); }); + it('Proper error message should display if unsubscribed user try to subscribe', () => { + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); + cy.get('#mc_double_optin').uncheck(); + cy.get('#mc_update_existing').check(); + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); + + // Verify + [shortcodePostURL, blockPostPostURL].forEach((url) => { + cy.visit(url); + cy.get('#mc_mv_EMAIL').should('exist'); + cy.get('#mc_mv_EMAIL').clear().type('unsubscribed_user@gmail.com'); + cy.get('#mc_signup_submit').should('exist'); + cy.get('#mc_signup_submit').click(); + cy.get('.mc_error_msg').should('exist'); + cy.get('.mc_error_msg').contains( + 'The email address cannot be subscribed because it was previously unsubscribed, bounced, or is under review. Please sign up here.', + ); + }); + + // Reset + cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); + cy.get('#mc_double_optin').check(); + cy.get('#mc_update_existing').check(); + cy.get('input[value="Update Subscribe Form Settings"]').first().click(); + }); + + it('Form data should persist if validation fails', () => { + // Verify + [shortcodePostURL, blockPostPostURL].forEach((url) => { + const firstName = 'John'; + const lastName = 'Doe'; + cy.visit(url); + cy.get('#mc_mv_EMAIL').should('exist'); + cy.get('#mc_mv_FNAME').clear().type(firstName); + cy.get('#mc_mv_LNAME').clear().type(lastName); + cy.get('#mc_signup_submit').should('exist'); + cy.get('#mc_signup_submit').click(); + cy.get('.mc_error_msg').should('exist'); + cy.get('.mc_error_msg').contains('Email Address: This value should not be blank.'); + cy.get('#mc_mv_FNAME').should('have.value', firstName); + cy.get('#mc_mv_LNAME').should('have.value', lastName); + }); + }); + // TODO: Add case for separate account login and settings get reset. it('Ensure settings persist between logging out and logging back in of Mailchimp account', () => { // Step 1: Visit Mailchimp settings page @@ -227,9 +188,9 @@ describe('Admin can update plugin settings', () => { cy.get('input[value="Update Subscribe Form Settings"]').first().click(); // Verify the custom header is saved - cy.get('#mc-message .success_msg').contains( - 'Successfully Updated your List Subscribe Form Settings!', - ); + cy.get('.notice.notice-success.is-dismissible') + .last() + .contains('Successfully Updated your List Subscribe Form Settings!'); cy.get('#mc_header_content').should('have.value', customHeader); // Step 3: Log out of the Mailchimp account @@ -287,12 +248,6 @@ describe('Admin can update plugin settings', () => { cy.get('#mc_header_content').should('have.value', 'Sign up for 10up'); cy.get('#mc_subheader_content').should('have.value', ''); cy.get('#mc_submit_text').should('have.value', 'Subscribe'); - cy.get('#mc_nuke_all_styles').should('not.be.checked'); - cy.get('#mc_custom_style').should('not.be.checked'); - cy.get('#mc_form_border_width').should('have.value', '1'); - cy.get('#mc_form_border_color').should('have.value', 'E0E0E0'); - cy.get('#mc_form_background').should('have.value', 'FFFFFF'); - cy.get('#mc_form_text_color').should('have.value', '3F3F3f'); cy.get('#mc_update_existing').should('not.be.checked'); cy.get('#mc_double_optin').should('be.checked'); cy.get('#mc_use_unsub_link').should('not.be.checked'); diff --git a/tests/cypress/e2e/submission/double-opt-in-subscribe.test.js b/tests/cypress/e2e/submission/double-opt-in-subscribe.test.js index f89f011e..fa14de4c 100644 --- a/tests/cypress/e2e/submission/double-opt-in-subscribe.test.js +++ b/tests/cypress/e2e/submission/double-opt-in-subscribe.test.js @@ -7,8 +7,7 @@ describe.skip('Double Opt-in Subscriptions', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - shortcodePostURL = urls.shortcodePostURL; - blockPostPostURL = urls.blockPostPostURL; + ({ shortcodePostURL, blockPostPostURL } = urls); }); cy.login(); // WP diff --git a/tests/cypress/e2e/submission/js-submission.test.js b/tests/cypress/e2e/submission/js-submission.test.js index 11fbaeef..5a43d455 100644 --- a/tests/cypress/e2e/submission/js-submission.test.js +++ b/tests/cypress/e2e/submission/js-submission.test.js @@ -7,7 +7,7 @@ describe('JavaScript submission', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - blockPostPostURL = urls.blockPostPostURL; + ({ blockPostPostURL } = urls); }); cy.login(); // WP @@ -15,9 +15,6 @@ describe('JavaScript submission', () => { cy.selectList('10up'); // Ensure list is selected, refreshes Mailchimp data with WP - // Set JS support to enabled - cy.setJavaScriptOption(true); - // Disable double opt-in cy.setDoubleOptInOption(false); @@ -25,12 +22,7 @@ describe('JavaScript submission', () => { cy.toggleMergeFields('uncheck'); }); - beforeEach(() => { - cy.visit(blockPostPostURL); - setUpForm(); - }); - - function setUpForm() { + function setUpForm() { // Step 1: Assert form contains setup elements // Email cy.get('#mc_signup').should('exist'); @@ -49,6 +41,11 @@ describe('JavaScript submission', () => { cy.get('#mc_signup_submit').click(); } + beforeEach(() => { + cy.visit(blockPostPostURL); + setUpForm(); + }); + it('Disables the submit button before attempting submission', () => { submitEmail('invalidemail@--'); // Submit blank email @@ -98,10 +95,9 @@ describe('JavaScript submission', () => { cy.get('.mc_success_msg').should('exist').contains('success', { matchCase: false }); // Step 6: Verify that the contact was added to the Mailchimp account via the Mailchimp API - cy.wait(5000) - .verifyContactInMailchimp(email); + cy.wait(5000).verifyContactInMailchimp(email); // Step 7: Cleanup and delete contact cy.deleteContactFromList(email); }); -}); \ No newline at end of file +}); diff --git a/tests/cypress/e2e/submission/resubscribe.test.js b/tests/cypress/e2e/submission/resubscribe.test.js index a38d0cf8..ababde48 100644 --- a/tests/cypress/e2e/submission/resubscribe.test.js +++ b/tests/cypress/e2e/submission/resubscribe.test.js @@ -6,8 +6,7 @@ describe.skip('Resubscribe actions', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - shortcodePostURL = urls.shortcodePostURL; - blockPostPostURL = urls.blockPostPostURL; + ({ shortcodePostURL, blockPostPostURL } = urls); }); cy.login(); // WP @@ -23,4 +22,4 @@ describe.skip('Resubscribe actions', () => { it.skip('Subscribers who have previously unsubscribed should receive a link to the Mailchimp self hosted sign up form', () => { // Write test... }); -}); \ No newline at end of file +}); diff --git a/tests/cypress/e2e/submission/unsubscribe.test.js b/tests/cypress/e2e/submission/unsubscribe.test.js index 76f79883..acd2b9ba 100644 --- a/tests/cypress/e2e/submission/unsubscribe.test.js +++ b/tests/cypress/e2e/submission/unsubscribe.test.js @@ -8,8 +8,7 @@ describe('Unsubscribe form', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - shortcodePostURL = urls.shortcodePostURL; - blockPostPostURL = urls.blockPostPostURL; + ({ shortcodePostURL, blockPostPostURL } = urls); }); cy.login(); // WP @@ -40,7 +39,7 @@ describe('Unsubscribe form', () => { // Assert unsubscribe link exists cy.get('a[href*="/unsubscribe"]').should('exist'); }); - }) + }); it('unsubscribes valid emails that were previously subscribed to a list', () => { const email = generateRandomEmail('previously-subscribed-email'); @@ -58,8 +57,7 @@ describe('Unsubscribe form', () => { // Extract the base URL const urlObject = new URL(url); baseUrl = `${urlObject.protocol}//${urlObject.host}`; - }); - + }); // Assert unsubscribe link exists cy.get('a[href*="/unsubscribe"]').should('exist'); @@ -75,8 +73,7 @@ describe('Unsubscribe form', () => { cy.get('body').should('contain', 'Unsubscribe Successful'); // Navigate back to the website button exists - cy.contains('a', 'return to our website') - .should('exist'); + cy.contains('a', 'return to our website').should('exist'); // Verify contact exists in Mailchimp with status 'unsubscribed' cy.verifyContactInMailchimp(email, '10up', 'unsubscribed').then((contact) => { @@ -85,7 +82,7 @@ describe('Unsubscribe form', () => { // Delete contact to clean up cy.deleteContactFromList(email); }); - + // Navigate to back website // NOTE: The website URL is site in Mailchimp and it won't accept localhost or our test URL // TODO: Assert that we're back on our website (we currently have no way to set this) @@ -132,6 +129,6 @@ describe('Unsubscribe form', () => { }); // NOTE: We can not set the "return to website" URL from the Mailchimp plugin or through the API. - // Alternative proposals on issue #91 and #92 to add a user tutorial + // Alternative proposals on issue #91 and #92 to add a user tutorial // it.skip('redirects the user back to the website when the user is finished unsubscribing and clicks the back link', () => {}); -}); \ No newline at end of file +}); diff --git a/tests/cypress/e2e/submission/update-subscribers.test.js b/tests/cypress/e2e/submission/update-subscribers.test.js index 59cc9794..b27974c5 100644 --- a/tests/cypress/e2e/submission/update-subscribers.test.js +++ b/tests/cypress/e2e/submission/update-subscribers.test.js @@ -6,7 +6,7 @@ describe('Update Existing Subscriber?', () => { before(() => { // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - blockPostPostURL = urls.blockPostPostURL; + ({ blockPostPostURL } = urls); }); cy.login(); // WP diff --git a/tests/cypress/e2e/validation/address.test.js b/tests/cypress/e2e/validation/address.test.js index 03bc31fd..5ddc2942 100644 --- a/tests/cypress/e2e/validation/address.test.js +++ b/tests/cypress/e2e/validation/address.test.js @@ -23,9 +23,9 @@ describe('Address Field Validation', () => { cy.login(); // Log into WordPress cy.mailchimpLoginIfNotAlreadyLoggedIn(); // Log into Mailchimp - // Load post URLs for shortcode and block post tests + // Load the post URLs from the JSON file cy.fixture('postUrls').then((urls) => { - blockPostPostURL = urls.blockPostPostURL; + ({ blockPostPostURL } = urls); }); // Set address fields (Addr 1 and City) as required @@ -34,9 +34,6 @@ describe('Address Field Validation', () => { cy.selectList('10up'); // Refresh list in WordPress }); }); - - // Test validation without JS to ensure error handling mechanism for all scenarios - cy.setJavaScriptOption(false); }); after(() => { @@ -46,7 +43,6 @@ describe('Address Field Validation', () => { cy.selectList('10up'); // Refresh list in WordPress }); }); - cy.setJavaScriptOption(true); }); it('Valid addresses submit', () => { diff --git a/tests/cypress/e2e/validation/email.test.js b/tests/cypress/e2e/validation/email.test.js index 9a88f32d..7d5246a8 100644 --- a/tests/cypress/e2e/validation/email.test.js +++ b/tests/cypress/e2e/validation/email.test.js @@ -28,13 +28,6 @@ describe('General merge field validation', () => { // Disable all merge fields cy.toggleMergeFields('uncheck'); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Test validation without JS to ensure error handling mechanism for all scenarios - cy.setJavaScriptOption(false); - }); - - after(() => { - cy.setJavaScriptOption(true); }); it('Invalid email addresses fail validation', () => { diff --git a/tests/cypress/e2e/validation/us-phone.test.js b/tests/cypress/e2e/validation/us-phone.test.js index 5cb4290e..a523a7fc 100644 --- a/tests/cypress/e2e/validation/us-phone.test.js +++ b/tests/cypress/e2e/validation/us-phone.test.js @@ -37,28 +37,25 @@ describe.skip('US Multi-Input Phone Number Validation', () => { ({ blockPostPostURL } = urls); }); - cy.getListId('10up').then((listId) => { - cy.updateMergeFieldByTag(listId, 'PHONE', { - required: true, - options: { phone_format: 'US' }, - }).then(() => { - cy.selectList('10up'); - }); - }); - - // Test validation without JS to ensure error handling mechanism for all scenarios - cy.setJavaScriptOption(false); + // cy.getListId('10up').then((listId) => { + // cy.updateMergeFieldByTag(listId, 'PHONE', { + // required: true, + // options: { phone_format: 'US' }, + // }).then(() => { + // cy.selectList('10up'); + // }); + // }); }); after(() => { - cy.getListId('10up').then((listId) => { - cy.updateMergeFieldByTag(listId, 'PHONE', { - required: false, - options: { phone_format: 'none' }, - }); - }); - cy.selectList('10up'); - cy.setJavaScriptOption(true); + // cy.getListId('10up').then((listId) => { + // cy.updateMergeFieldByTag(listId, 'PHONE', { + // required: false, + // options: { phone_format: 'none' }, + // }).then(() => { + // cy.selectList('10up'); + // }); + // }); }); function fillPhoneInputs(phone) { diff --git a/tests/cypress/e2e/validation/validate-required-fields.test.js b/tests/cypress/e2e/validation/validate-required-fields.test.js index e42612c0..9bbff306 100644 --- a/tests/cypress/e2e/validation/validate-required-fields.test.js +++ b/tests/cypress/e2e/validation/validate-required-fields.test.js @@ -46,10 +46,20 @@ describe('Validate required fields', () => { cy.mailchimpLoginIfNotAlreadyLoggedIn(); // Set all merge fields to required in the Mailchimp test user account - cy.setMergeFieldsRequired(true); - - // Test validation without JS to ensure error handling mechanism for all scenarios - cy.setJavaScriptOption(false); + cy.setMergeFieldsRequired(true, '10up', [ + 'FNAME', + 'LNAME', + 'ADDRESS', + 'BIRTHDAY', + 'COMPANY', + 'MMERGE8', + 'MMERGE9', + 'MMERGE10', + 'MMERGE11', + 'MMERGE7', + 'MMERGE6', + 'PHONE', + ]); }); after(() => { @@ -57,13 +67,23 @@ describe('Validate required fields', () => { cy.login(); // WordPress login // Cleanup: Set all merge fields to not required in the Mailchimp test user account - cy.setMergeFieldsRequired(false); + cy.setMergeFieldsRequired(false, '10up', [ + 'FNAME', + 'LNAME', + 'ADDRESS', + 'BIRTHDAY', + 'COMPANY', + 'MMERGE8', + 'MMERGE9', + 'MMERGE10', + 'MMERGE11', + 'MMERGE7', + 'MMERGE6', + 'PHONE', + ]); // Cleanup: Uncheck all optional merge fields cy.toggleMergeFields('uncheck'); - - // Cleanup: Re-enable JS support - cy.setJavaScriptOption(true); }); // TODO: Validation errors clear the entire form. We should fix this. @@ -72,7 +92,14 @@ describe('Validate required fields', () => { cy.get('#mc_mv_EMAIL').clear().type(email); // Email is always required requiredFields.forEach((field) => { - cy.get(field.selector).clear().type(field.input); + if (field.selector === '#mc_mv_PHONE') { + const phone = field.input.split('-'); + cy.get('#mc_mv_PHONE-area').clear().type(phone[0]); + cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]); + cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]); + } else { + cy.get(field.selector).clear().type(field.input); + } cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal }); @@ -94,13 +121,19 @@ describe('Validate required fields', () => { // Ensure the form exists cy.get('#mc_signup').should('exist'); + // Fill out entire form everytime so we can narrow tests to one input at a time + fillOutAllFields(); + // Test validation for each required field requiredFields.forEach((field) => { - // Fill out entire form everytime so we can narrow tests to one input at a time - fillOutAllFields(); - // Submit the form without input to trigger validation - cy.get(field.selector).clear(); // Ensure field is empty + if (field.selector === '#mc_mv_PHONE') { + cy.get('#mc_mv_PHONE-area').clear(); + cy.get('#mc_mv_PHONE-detail1').clear(); + cy.get('#mc_mv_PHONE-detail2').clear(); + } else { + cy.get(field.selector).clear(); // Ensure field is empty + } cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal cy.get('#mc_signup_submit').click(); @@ -109,7 +142,15 @@ describe('Validate required fields', () => { cy.get('.mc_error_msg').should('include.text', field.errorMessage); // Fill in the field - cy.get(field.selector).type(field.input); + if (field.selector === '#mc_mv_PHONE') { + const phone = field.input.split('-'); + cy.get('#mc_mv_PHONE-area').clear().type(phone[0]); + cy.get('#mc_mv_PHONE-detail1').clear().type(phone[1]); + cy.get('#mc_mv_PHONE-detail2').clear().type(phone[2]); + } else { + cy.get(field.selector).type(field.input); + } + cy.get('body').click(0, 0); // Click outside the field to clear the datepicker modal }); }); }); diff --git a/tests/cypress/e2e/validation/validate-unrequired-fields.test.js b/tests/cypress/e2e/validation/validate-unrequired-fields.test.js index 98f3426c..d14bf41b 100644 --- a/tests/cypress/e2e/validation/validate-unrequired-fields.test.js +++ b/tests/cypress/e2e/validation/validate-unrequired-fields.test.js @@ -20,9 +20,6 @@ describe('Validate unrequired fields', () => { // Enable all merge fields cy.toggleMergeFields('check'); cy.get('input[value="Update Subscribe Form Settings"]').first().click(); - - // Test validation without JS to ensure error handling mechanism for all scenarios - cy.setJavaScriptOption(false); }); after(() => { @@ -32,8 +29,6 @@ describe('Validate unrequired fields', () => { // Cleanup cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); cy.toggleMergeFields('uncheck'); // TODO: Do I need to uncheck all merge fields? - - cy.setJavaScriptOption(true); }); it('Unrequired fields can be submitted while blank', () => { @@ -55,7 +50,6 @@ describe('Validate unrequired fields', () => { cy.get('#mc_mv_ADDRESS-country').should('exist'); // Country cy.get('#mc_mv_BIRTHDAY').should('exist'); cy.get('#mc_mv_COMPANY').should('exist'); - cy.get('#mc_mv_PHONE').should('exist'); // Validation assertions diff --git a/tests/cypress/support/commands/mailchimpApi.js b/tests/cypress/support/commands/mailchimpApi.js index c09c009a..8596b31e 100644 --- a/tests/cypress/support/commands/mailchimpApi.js +++ b/tests/cypress/support/commands/mailchimpApi.js @@ -148,10 +148,15 @@ function getContactFromList(email, listName = '10up') { * @returns {Promise} - A promise that resolves when all merge fields are updated */ Cypress.Commands.add('updateMergeFieldsByList', updateMergeFieldsByList); -async function updateMergeFieldsByList(listId, data) { +async function updateMergeFieldsByList(listId, data, fields = []) { const mergeFields = await getMergeFields(listId); const updatedMergeFields = mergeFields.map((field) => { - return updateMergeField(listId, field.merge_id, field.name, data); + // If fields are provided, check if the field is in the list + if (fields.length > 0 && !fields.includes(field.tag)) { + return Promise.resolve(); // Skip this field + } else { + return updateMergeField(listId, field.merge_id, field.name, data); + } }); return await Promise.all(updatedMergeFields); diff --git a/tests/cypress/support/commands/mailchimpLogin.js b/tests/cypress/support/commands/mailchimpLogin.js index 64c221dc..e439639f 100644 --- a/tests/cypress/support/commands/mailchimpLogin.js +++ b/tests/cypress/support/commands/mailchimpLogin.js @@ -16,9 +16,9 @@ Cypress.Commands.add('mailchimpLogout', () => { * Not sure we should put this much logic into one command, but we need * the Mailchimp login functionality to test settings.test.js independently */ -Cypress.Commands.add('mailchimpLogin', (username = null, password = null) => { - username = username ?? Cypress.env('MAILCHIMP_USERNAME'); - password = password ?? Cypress.env('MAILCHIMP_PASSWORD'); +Cypress.Commands.add('mailchimpLogin', (user = null, pass = null) => { + const username = user ?? Cypress.env('MAILCHIMP_USERNAME'); + const password = pass ?? Cypress.env('MAILCHIMP_PASSWORD'); cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); @@ -39,21 +39,18 @@ Cypress.Commands.add('mailchimpLogin', (username = null, password = null) => { const acceptButtonSelector = '#onetrust-accept-btn-handler'; // Check if the accept button is visible and click it - if ($popup.find(acceptButtonSelector).length > 0 && $popup.find(acceptButtonSelector).is(':visible')) { + if ( + $popup.find(acceptButtonSelector).length > 0 && + $popup.find(acceptButtonSelector).is(':visible') + ) { $popup.find(acceptButtonSelector).click(); } else { cy.log('Cookie consent popup not found or not visible.'); } }); - cy.popup() - .find('input#username') - .clear() - .type(username, { force: true }); - cy.popup() - .find('input#password') - .clear() - .type(password, { force: true }); + cy.popup().find('input#username').clear().type(username, { force: true }); + cy.popup().find('input#password').clear().type(password, { force: true }); cy.popup().find('button[type="submit"]').click({ force: true }); cy.wait(10000); // Not a best practice, but did not find a better way to handle this. diff --git a/tests/cypress/support/commands/settings.js b/tests/cypress/support/commands/settings.js index f235f580..107ae5d9 100644 --- a/tests/cypress/support/commands/settings.js +++ b/tests/cypress/support/commands/settings.js @@ -13,39 +13,10 @@ */ Cypress.Commands.add('selectList', (listName) => { cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - cy.get('#mc_list_id').select(listName, {force: true}); + cy.get('#mc_list_id').select(listName, { force: true }); cy.get('input[value="Update List"]').click(); }); -/** - * Custom Cypress command to enable or disable the JavaScript option in Mailchimp WordPress admin settings. - * - * This command visits the Mailchimp plugin settings page in the WordPress admin, - * toggles the "Use JavaScript" option based on the specified parameter, and - * updates the settings by submitting the form. It is helpful for testing scenarios - * that depend on JavaScript behavior in the plugin. - * - * @param {boolean} enabled - A flag to enable (`true`) or disable (`false`) the JavaScript option. - * - * @example - * // Enable the JavaScript option - * cy.setJavaScriptOption(true); - * - * @example - * // Disable the JavaScript option - * cy.setJavaScriptOption(false); - */ -Cypress.Commands.add('setJavaScriptOption', setJavaScriptOption); -function setJavaScriptOption(enabled) { - cy.visit('/wp-admin/admin.php?page=mailchimp_sf_options'); - if (enabled) { - cy.get('#mc_use_javascript').check(); - } else { - cy.get('#mc_use_javascript').uncheck(); - } - cy.get('input[value="Update Subscribe Form Settings"]').first().click(); -} - /** * Custom Cypress command to enable or disable the Double Opt-In option in Mailchimp WordPress admin settings. * @@ -143,11 +114,11 @@ function toggleMergeFields(action) { * // Set merge fields for a specific list * cy.setMergeFieldsRequired(true, 'Custom List'); */ -Cypress.Commands.add('setMergeFieldsRequired', (required, listName = '10up') => { +Cypress.Commands.add('setMergeFieldsRequired', (required, listName = '10up', fields = []) => { // Set all merge fields to required in the Mailchimp test user account cy.getListId(listName).then((listId) => { - cy.updateMergeFieldsByList(listId, { required: required }).then(() => { + cy.updateMergeFieldsByList(listId, { required }, fields).then(() => { cy.selectList(listName); // Ensure list is selected, refreshes Mailchimp data with WP }); }); -}) \ No newline at end of file +}); diff --git a/tests/cypress/support/index.js b/tests/cypress/support/index.js index a0364cee..76d9fdaf 100644 --- a/tests/cypress/support/index.js +++ b/tests/cypress/support/index.js @@ -33,7 +33,6 @@ before(() => { cy.selectList('10up'); cy.setDoubleOptInOption(false); - cy.setJavaScriptOption(true); cy.setSettingsOption('#mc_update_existing', false); // Merge fields @@ -43,8 +42,8 @@ before(() => { cy.log('Default testing options set!'); }); -beforeEach( () => { - cy.session( 'login', cy.login, { +beforeEach(() => { + cy.session('login', cy.login, { cacheAcrossSpecs: true, - } ); -} ); + }); +});