diff --git a/changelog.txt b/changelog.txt
index b957b5a935..c2651030a6 100644
--- a/changelog.txt
+++ b/changelog.txt
@@ -1,5 +1,12 @@
*** WooCommerce Google Listings and Ads Changelog ***
+= 2.5.2 - 2023-08-08 =
+* Fix - Remove `add_woocommerce_extended_task_list_item` and `remove_woocommerce_extended_task_list_item` hooks.
+* Fix - WordPress 6.3 compatibility: The forms and image selector may not work due to "setImmediate" deprecation.
+* Tweak - Use the latest API to add an item to the WC tasks list.
+* Tweak - WC 8.0 compatibility.
+* Tweak - WP 6.3 compatibility.
+
= 2.5.1 - 2023-08-01 =
* Dev - Setup wp-env for E2E tests.
* Dev - automate merging trunk to develop after a release.
diff --git a/google-listings-and-ads.php b/google-listings-and-ads.php
index 5ea08fc894..8dd3d58d06 100644
--- a/google-listings-and-ads.php
+++ b/google-listings-and-ads.php
@@ -3,17 +3,17 @@
* Plugin Name: Google Listings and Ads
* Plugin URL: https://wordpress.org/plugins/google-listings-and-ads/
* Description: Native integration with Google that allows merchants to easily display their products across Google’s network.
- * Version: 2.5.1
+ * Version: 2.5.2
* Author: WooCommerce
* Author URI: https://woocommerce.com/
* Text Domain: google-listings-and-ads
* Requires at least: 5.9
- * Tested up to: 6.2
+ * Tested up to: 6.3
* Requires PHP: 7.4
* Requires PHP Architecture: 64 bits
*
* WC requires at least: 6.9
- * WC tested up to: 7.9
+ * WC tested up to: 8.0
* Woo:
*
* @package WooCommerce\Admin
@@ -30,7 +30,7 @@
defined( 'ABSPATH' ) || exit;
-define( 'WC_GLA_VERSION', '2.5.1' ); // WRCS: DEFINED_VERSION.
+define( 'WC_GLA_VERSION', '2.5.2' ); // WRCS: DEFINED_VERSION.
define( 'WC_GLA_MIN_PHP_VER', '7.4' );
define( 'WC_GLA_MIN_WC_VER', '6.9' );
diff --git a/js/src/components/adaptive-form/adaptive-form.js b/js/src/components/adaptive-form/adaptive-form.js
index 7e72248acc..9194fd43af 100644
--- a/js/src/components/adaptive-form/adaptive-form.js
+++ b/js/src/components/adaptive-form/adaptive-form.js
@@ -196,12 +196,12 @@ function AdaptiveForm( { onSubmit, extendAdapter, children, ...props }, ref ) {
// Related to WC 6.9. Only one delegate can be consumed at a time in this render prop to
// ensure the updating states will always be the latest when calling.
if ( batchQueue.length ) {
- // Use `setImmediate` to avoid the warning of request state updates while rendering.
+ // Use `setTimeout` to avoid the warning of request state updates while rendering.
// Mutating a React hook state is an anti-pattern in most cases. Here is done intentionally
// because it's necessary to ensure this component will be triggered re-rendering through
// `setBatchQueue`, but also to avoid calling `setBatchQueue` here and triggering additional
// rendering again.
- setImmediate( () => setDelegation( batchQueue.shift() ) );
+ setTimeout( () => setDelegation( batchQueue.shift() ) );
}
/* === Start of enhancement-related codes === */
diff --git a/js/src/components/adaptive-form/adaptive-form.test.js b/js/src/components/adaptive-form/adaptive-form.test.js
index 3b343535c6..7c2b9a1eea 100644
--- a/js/src/components/adaptive-form/adaptive-form.test.js
+++ b/js/src/components/adaptive-form/adaptive-form.test.js
@@ -196,4 +196,113 @@ describe( 'AdaptiveForm', () => {
expect( inspect ).toHaveBeenLastCalledWith( false, 0 );
} );
+
+ describe( 'Compatibility patches', () => {
+ it( 'Should update all changes to values for the synchronous multiple calls to `setValue`', async () => {
+ render(
+
+ { ( { setValue, values } ) => {
+ return (
+ <>
+
+ );
+
+ const article = screen.getByRole( 'article' );
+
+ expect( article.textContent ).toBe( 'Foo Bar (empty)' );
+
+ await act( async () => {
+ await userEvent.click( screen.getByRole( 'button' ) );
+ jest.runAllTimers();
+ } );
+
+ expect( article.textContent ).toBe( 'Hey Howdy hi[at]greetings' );
+ } );
+
+ it( 'Should call back to `onChange` for the changed value only', async () => {
+ const onChange = jest.fn();
+
+ render(
+
+ { ( { setValue, getInputProps } ) => {
+ return (
+ <>
+
+ );
+
+ await act( async () => {
+ await userEvent.click( screen.getByRole( 'button' ) );
+ jest.runAllTimers();
+ } );
+
+ expect( onChange ).toHaveBeenCalledTimes( 1 );
+ expect( onChange ).toHaveBeenLastCalledWith(
+ { name: 'firstName', value: 'Hey' },
+ expect.any( Object ),
+ true
+ );
+
+ await userEvent.type( screen.getByRole( 'textbox' ), 'a' );
+
+ expect( onChange ).toHaveBeenCalledTimes( 2 );
+ expect( onChange ).toHaveBeenLastCalledWith(
+ { name: 'lastName', value: 'a' },
+ expect.any( Object ),
+ true
+ );
+
+ await userEvent.click( screen.getByRole( 'checkbox' ) );
+
+ expect( onChange ).toHaveBeenCalledTimes( 3 );
+ expect( onChange ).toHaveBeenLastCalledWith(
+ { name: 'agreedTerms', value: true },
+ expect.any( Object ),
+ true
+ );
+ } );
+ } );
} );
diff --git a/js/src/hooks/useCroppedImageSelector/useCroppedImageSelector.js b/js/src/hooks/useCroppedImageSelector/useCroppedImageSelector.js
index 478f3a9475..f3623709ac 100644
--- a/js/src/hooks/useCroppedImageSelector/useCroppedImageSelector.js
+++ b/js/src/hooks/useCroppedImageSelector/useCroppedImageSelector.js
@@ -315,7 +315,7 @@ export default function useCroppedImageSelector( {
// since `toolbar` will be triggered the refresh event at the end, so this function
// must be called after that.
if ( this === frame ) {
- setImmediate( handleSelectionToggle );
+ setTimeout( handleSelectionToggle );
return;
}
diff --git a/js/src/tasks/complete-setup/index.js b/js/src/tasks/complete-setup/index.js
deleted file mode 100644
index c5439c41ad..0000000000
--- a/js/src/tasks/complete-setup/index.js
+++ /dev/null
@@ -1,45 +0,0 @@
-/**
- * External dependencies
- */
-
-import { __ } from '@wordpress/i18n';
-import { addFilter } from '@wordpress/hooks';
-import { getHistory } from '@woocommerce/navigation';
-
-/**
- * Internal dependencies
- */
-import { getGetStartedUrl, getDashboardUrl } from '.~/utils/urls';
-
-/* global glaTaskData */
-
-/**
- * Use the 'woocommerce_admin_onboarding_task_list' filter to add a task.
- */
-addFilter(
- 'woocommerce_admin_onboarding_task_list',
- 'google-listings-and-ads',
- ( tasks ) => {
- return [
- ...tasks,
- {
- key: 'gla_complete_setup',
- title: __(
- 'Set up Google Listings & Ads',
- 'google-listings-and-ads'
- ),
- completed: glaTaskData.isComplete,
- onClick: () => {
- // Redirect to the GLA get started or dashboard page.
- const nextUrl = glaTaskData.isComplete
- ? getDashboardUrl()
- : getGetStartedUrl();
- getHistory().push( nextUrl );
- },
- visible: true,
- time: __( '20 minutes', 'google-listings-and-ads' ),
- isDismissable: true,
- },
- ];
- }
-);
diff --git a/package-lock.json b/package-lock.json
index ae7811bc1c..a1e116424f 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,6 +1,6 @@
{
"name": "google-listings-and-ads",
- "version": "2.5.1",
+ "version": "2.5.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
diff --git a/package.json b/package.json
index be0b563de6..697ce5b4a6 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "google-listings-and-ads",
"title": "Google Listings and Ads",
- "version": "2.5.1",
+ "version": "2.5.2",
"description": "google-listings-and-ads",
"author": "Automattic",
"license": "GPL-3.0-or-later",
@@ -89,6 +89,7 @@
"check-licenses": "wp-scripts check-licenses",
"dev": "NODE_ENV=development wp-scripts build",
"dewps:woo": "node bin/list-woo-dewped.mjs",
+ "doc:hooks": "php bin/HooksDocsGenerator.php",
"doc:tracking": "woocommerce-grow-jsdoc ./js/src",
"docker:up": "WP_VERSION=6.1 npx wc-e2e docker:up",
"docker:down": "npx wc-e2e docker:down",
diff --git a/readme.txt b/readme.txt
index 04eb8090a3..1bd3cd2d55 100644
--- a/readme.txt
+++ b/readme.txt
@@ -2,10 +2,10 @@
Contributors: automattic, google, woocommerce
Tags: woocommerce, google, listings, ads
Requires at least: 5.9
-Tested up to: 6.2
+Tested up to: 6.3
Requires PHP: 7.4
Requires PHP Architecture: 64 Bits
-Stable tag: 2.5.1
+Stable tag: 2.5.2
License: GPLv3
License URI: https://www.gnu.org/licenses/gpl-3.0.html
@@ -111,6 +111,13 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis
== Changelog ==
+= 2.5.2 - 2023-08-08 =
+* Fix - Remove `add_woocommerce_extended_task_list_item` and `remove_woocommerce_extended_task_list_item` hooks.
+* Fix - WordPress 6.3 compatibility: The forms and image selector may not work due to "setImmediate" deprecation.
+* Tweak - Use the latest API to add an item to the WC tasks list.
+* Tweak - WC 8.0 compatibility.
+* Tweak - WP 6.3 compatibility.
+
= 2.5.1 - 2023-08-01 =
* Dev - Setup wp-env for E2E tests.
* Dev - automate merging trunk to develop after a release.
@@ -123,19 +130,4 @@ Yes, you can run both at the same time, and we recommend it! In the US, advertis
* Tweak - Add Tip with information with Campaign assets are imported.
* Tweak - Provide more detailed error reasons when unable to complete site verification for the Google Merchant Center account being connected in the onboarding flow.
-= 2.4.11 - 2023-07-11 =
-* Add - Client name and plugin version to requests.
-* Dev - Enable unit testing for PHP 8.1.
-* Dev - Set engines for the repository.
-* Fix - Avoid continuing to save settings to Google Merchant Center after the shipping time save failed on the Edit Free Listings page.
-* Fix - Avoid errors when clearing all audience countries in the onboarding flow.
-* Fix - Incorrectly display South America in the audience location selector after selecting Saudi Arabia.
-* Fix - Remove deprecated $border-width-focus variable.
-* Fix - Show a general error message when the phone number verification request is failed.
-* Tweak - Add placeholder in the Attribute Mapping table when there are no rules available.
-* Tweak - Changes for title, descriptions and FAQ in PMAX Optimized Campaigns.
-* Tweak - Make some error messages clearer when errors occur in querying or modifying data.
-* Tweak - Make the error message clearer for errors that occur in getting or updating a Google Merchant Center account.
-* Tweak - WC 7.9 compatibility.
-
[See changelog for all versions](https://raw.githubusercontent.com/woocommerce/google-listings-and-ads/trunk/changelog.txt).
diff --git a/src/Admin/Admin.php b/src/Admin/Admin.php
index d7c995404b..1c9b5faf44 100644
--- a/src/Admin/Admin.php
+++ b/src/Admin/Admin.php
@@ -286,12 +286,12 @@ private function inject_fast_refresh_for_dev( $scripts ) {
$plugin_url = $this->get_plugin_url();
$scripts->add(
- 'gla-webpack-rumtime',
+ 'gla-webpack-runtime',
"{$plugin_url}/js/build/runtime.js",
[],
(string) filemtime( $runtime_path )
);
- $react_script->deps[] = 'gla-webpack-rumtime';
+ $react_script->deps[] = 'gla-webpack-runtime';
if ( ! in_array( 'wp-react-refresh-entry', $react_script->deps, true ) ) {
$scripts->add(
diff --git a/src/Google/GlobalSiteTag.php b/src/Google/GlobalSiteTag.php
index b948ad1019..c158001063 100644
--- a/src/Google/GlobalSiteTag.php
+++ b/src/Google/GlobalSiteTag.php
@@ -202,6 +202,7 @@ function () use ( $gtag_events ) {
]
);
+ $this->register_js_for_fast_refresh_dev();
$this->assets_handler->enqueue( $gtag_events );
}
);
@@ -485,4 +486,39 @@ private static function is_first_time_customer( $customer_email ): bool {
$orders = $query->get_orders();
return count( $orders ) === 1 ? true : false;
}
+
+ /**
+ * This method ONLY works during development in the Fast Refresh mode.
+ *
+ * The runtime.js and react-refresh-runtime.js files are created when the front-end development is
+ * running `npm run start:hot`, and they need to be loaded to make the gtag-events scrips work.
+ */
+ private function register_js_for_fast_refresh_dev() {
+ // This file exists only when running `npm run start:hot`
+ $runtime_path = "{$this->get_root_dir()}/js/build/runtime.js";
+
+ if ( ! file_exists( $runtime_path ) ) {
+ return;
+ }
+
+ $plugin_url = $this->get_plugin_url();
+
+ wp_enqueue_script(
+ 'gla-webpack-runtime',
+ "{$plugin_url}/js/build/runtime.js",
+ [],
+ (string) filemtime( $runtime_path ),
+ false
+ );
+
+ // This script is one of the gtag-events dependencies, and its handle is wp-react-refresh-runtime.
+ // Ref: js/build/gtag-events.asset.php
+ wp_register_script(
+ 'wp-react-refresh-runtime',
+ "{$plugin_url}/js/build-dev/react-refresh-runtime.js",
+ [ 'gla-webpack-runtime' ],
+ $this->get_version(),
+ false
+ );
+ }
}
diff --git a/src/Hooks/README.md b/src/Hooks/README.md
index 1a7caa7405..74feb0d3dc 100644
--- a/src/Hooks/README.md
+++ b/src/Hooks/README.md
@@ -2,14 +2,6 @@
A list of hooks, i.e `actions` and `filters`, that are defined or used in this project.
-## add_woocommerce_extended_task_list_item
-
-**Type**: action
-
-**Used in**:
-
-- CompleteSetup.php#L61
-
## bulk_edit_save_post
**Type**: action
@@ -18,14 +10,6 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
- BulkEditInitializer.php#L36
-## remove_woocommerce_extended_task_list_item
-
-**Type**: action
-
-**Used in**:
-
-- CompleteSetup.php#L102
-
## woocommerce_admin_disabled
**Type**: filter
@@ -82,8 +66,8 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- AttributesForm.php#L69
- AttributeManager.php#L295
+- AttributesForm.php#L69
## woocommerce_gla_attribute_hidden_product_types_$ATTRIBUTE_ID
@@ -228,6 +212,22 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
+- MerchantCenterService.php#L305
+- MerchantStatuses.php#L334
+- MerchantStatuses.php#L357
+- ProductMetaQueryHelper.php#L92
+- ProductMetaQueryHelper.php#L123
+- BatchProductHelper.php#L208
+- BatchProductHelper.php#L231
+- ProductHelper.php#L459
+- ProductHelper.php#L491
+- ProductRepository.php#L304
+- ProductSyncer.php#L149
+- ProductSyncer.php#L159
+- ProductSyncer.php#L235
+- ProductSyncer.php#L245
+- SyncerHooks.php#L197
+- WCProductAdapter.php#L203
- CouponHelper.php#L255
- CouponHelper.php#L292
- CouponSyncer.php#L102
@@ -240,26 +240,10 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
- CouponSyncer.php#L308
- CouponSyncer.php#L327
- SyncerHooks.php#L177
-- BatchProductHelper.php#L208
-- BatchProductHelper.php#L231
-- ProductHelper.php#L459
-- ProductHelper.php#L491
-- ProductRepository.php#L304
-- ProductSyncer.php#L149
-- ProductSyncer.php#L159
-- ProductSyncer.php#L235
-- ProductSyncer.php#L245
-- SyncerHooks.php#L197
-- WCProductAdapter.php#L203
-- ProductMetaQueryHelper.php#L92
-- ProductMetaQueryHelper.php#L123
-- IssuesController.php#L96
-- MerchantCenterService.php#L305
-- MerchantStatuses.php#L334
-- MerchantStatuses.php#L357
- ActionSchedulerJobMonitor.php#L117
- ActionSchedulerJobMonitor.php#L126
- CleanupSyncedProducts.php#L74
+- IssuesController.php#L96
## woocommerce_gla_deleted_promotions
@@ -323,10 +307,7 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- CouponMetaHandler.php#L220
-- CouponSyncer.php#L409
-- CouponSyncer.php#L447
-- CouponSyncer.php#L465
+- ProductMetaQueryHelper.php#L139
- BatchProductHelper.php#L248
- ProductHelper.php#L351
- ProductHelper.php#L567
@@ -336,10 +317,13 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
- ProductSyncer.php#L357
- ProductSyncer.php#L372
- AttributeManager.php#L269
+- CouponMetaHandler.php#L220
+- CouponSyncer.php#L409
+- CouponSyncer.php#L447
+- CouponSyncer.php#L465
- PHPView.php#L136
- PHPView.php#L164
- PHPView.php#L208
-- ProductMetaQueryHelper.php#L139
## woocommerce_gla_exception
@@ -347,26 +331,26 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
+- ScriptWithBuiltDependenciesAsset.php#L66
- WooCommercePreOrders.php#L111
- WooCommercePreOrders.php#L131
+- NoteInitializer.php#L74
+- NoteInitializer.php#L116
+- ProductSyncer.php#L134
+- ProductSyncer.php#L220
+- CouponSyncer.php#L202
+- CouponSyncer.php#L292
+- PHPView.php#L87
- DateTime.php#L44
- DateTime.php#L80
- ChannelVisibilityMetaBox.php#L190
- CouponChannelVisibilityMetaBox.php#L197
-- GoogleServiceProvider.php#L222
-- CouponSyncer.php#L202
-- CouponSyncer.php#L292
-- ProductSyncer.php#L134
-- ProductSyncer.php#L220
-- NoteInitializer.php#L74
-- NoteInitializer.php#L116
-- PHPView.php#L87
-- Connection.php#L95
+- PluginUpdate.php#L75
+- GoogleServiceProvider.php#L223
- ContactInformationController.php#L242
- ProductVisibilityController.php#L193
- SettingsSyncController.php#L79
-- PluginUpdate.php#L75
-- ScriptWithBuiltDependenciesAsset.php#L66
+- Connection.php#L95
- ClearProductStatsCache.php#L61
## woocommerce_gla_force_run_install
@@ -415,7 +399,7 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- GoogleServiceProvider.php#L246
+- GoogleServiceProvider.php#L247
- Connection.php#L70
- Connection.php#L91
- Connection.php#L126
@@ -502,13 +486,13 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- Merchant.php#L91
-- Merchant.php#L139
-- Merchant.php#L171
-- Merchant.php#L190
-- Merchant.php#L237
-- Merchant.php#L282
-- Merchant.php#L335
+- Merchant.php#L92
+- Merchant.php#L140
+- Merchant.php#L172
+- Merchant.php#L191
+- Merchant.php#L247
+- Merchant.php#L292
+- Merchant.php#L354
- MerchantReport.php#L95
## woocommerce_gla_mc_settings_sync
@@ -649,6 +633,14 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
- WCProductAdapter.php#L767
+## woocommerce_gla_product_query_args
+
+**Type**: filter
+
+**Used in**:
+
+- ProductRepository.php#L360
+
## woocommerce_gla_products_delete_retry_on_failure
**Type**: filter
@@ -679,9 +671,9 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- Middleware.php#L592
- RequestReviewController.php#L110
- RequestReviewController.php#L122
+- Middleware.php#L592
## woocommerce_gla_request_review_response
@@ -713,10 +705,10 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- Merchant.php#L92
+- AccountService.php#L365
+- Merchant.php#L93
- Middleware.php#L268
- Middleware.php#L274
-- AccountService.php#L365
## woocommerce_gla_site_claim_overwrite_required
@@ -732,7 +724,7 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- Merchant.php#L89
+- Merchant.php#L90
- Middleware.php#L263
## woocommerce_gla_site_url
@@ -741,7 +733,7 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- PluginHelper.php#L180
+- PluginHelper.php#L189
## woocommerce_gla_site_verify_failure
@@ -749,9 +741,9 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- SiteVerification.php#L56
-- SiteVerification.php#L64
-- SiteVerification.php#L85
+- SiteVerification.php#L58
+- SiteVerification.php#L66
+- SiteVerification.php#L87
## woocommerce_gla_site_verify_success
@@ -759,7 +751,7 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- SiteVerification.php#L83
+- SiteVerification.php#L85
## woocommerce_gla_supported_coupon_types
@@ -783,8 +775,8 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- SiteVerification.php#L118
-- SiteVerification.php#L154
+- SiteVerification.php#L120
+- SiteVerification.php#L162
## woocommerce_gla_tax_excluded
@@ -832,8 +824,8 @@ A list of hooks, i.e `actions` and `filters`, that are defined or used in this p
**Used in**:
-- PluginHelper.php#L165
-- PluginHelper.php#L169
+- PluginHelper.php#L174
+- PluginHelper.php#L178
## woocommerce_gla_weight_unit
diff --git a/src/Internal/DependencyManagement/CoreServiceProvider.php b/src/Internal/DependencyManagement/CoreServiceProvider.php
index 74347a6b2b..09af6495d0 100644
--- a/src/Internal/DependencyManagement/CoreServiceProvider.php
+++ b/src/Internal/DependencyManagement/CoreServiceProvider.php
@@ -108,7 +108,7 @@
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\ZoneMethodsParser;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\ShippingZone;
use Automattic\WooCommerce\GoogleListingsAndAds\Shipping\ZoneLocationsParser;
-use Automattic\WooCommerce\GoogleListingsAndAds\TaskList\CompleteSetup;
+use Automattic\WooCommerce\GoogleListingsAndAds\TaskList\CompleteSetupTask;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\ActivatedEvents;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\SiteClaimEvents;
use Automattic\WooCommerce\GoogleListingsAndAds\Tracking\Events\SiteVerificationEvents;
@@ -146,7 +146,7 @@ class CoreServiceProvider extends AbstractServiceProvider {
AssetsHandlerInterface::class => true,
BulkEditInitializer::class => true,
ContactInformationNote::class => true,
- CompleteSetup::class => true,
+ CompleteSetupTask::class => true,
CompleteSetupNote::class => true,
CouponBulkEdit::class => true,
CouponHelper::class => true,
@@ -299,7 +299,7 @@ function ( ...$arguments ) {
$this->conditionally_share_with_tags( EventTracking::class, ContainerInterface::class );
$this->conditionally_share_with_tags( RESTControllers::class, ContainerInterface::class );
$this->conditionally_share_with_tags( ConnectionTest::class, ContainerInterface::class );
- $this->conditionally_share_with_tags( CompleteSetup::class, AssetsHandlerInterface::class );
+ $this->share_with_tags( CompleteSetupTask::class );
$this->conditionally_share_with_tags( GlobalSiteTag::class, AssetsHandlerInterface::class, GoogleGtagJs::class, ProductHelper::class, WC::class, WP::class );
$this->share_with_tags( SiteVerificationMeta::class );
$this->conditionally_share_with_tags( MerchantSetupCompleted::class );
diff --git a/src/TaskList/CompleteSetup.php b/src/TaskList/CompleteSetup.php
deleted file mode 100644
index e2dbdda1de..0000000000
--- a/src/TaskList/CompleteSetup.php
+++ /dev/null
@@ -1,104 +0,0 @@
-assets_handler = $assets_handler;
- }
-
- /**
- * Register a service.
- */
- public function register(): void {
- $this->assets_handler->add_many( $this->get_assets() );
-
- add_action(
- 'admin_enqueue_scripts',
- function () {
- if ( ! $this->should_register_tasks() ) {
- return;
- }
-
- $this->assets_handler->enqueue_many( $this->get_assets() );
-
- // argument matches the task "key" property
- do_action( 'add_woocommerce_extended_task_list_item', 'gla_complete_setup' );
- }
- );
- }
-
- /**
- * Return an array of assets.
- *
- * @return Asset[]
- */
- protected function get_assets(): array {
- $assets[] = ( new AdminScriptWithBuiltDependenciesAsset(
- 'gla-task-complete-setup',
- 'js/build/task-complete-setup',
- "{$this->get_root_dir()}/js/build/task-complete-setup.asset.php",
- new BuiltScriptDependencyArray(
- [
- 'dependencies' => [],
- 'version' => (string) filemtime( "{$this->get_root_dir()}/js/build/task-complete-setup.js" ),
- ]
- ),
- function () {
- return $this->should_register_tasks();
- }
- ) )->add_localization(
- 'glaTaskData',
- [
- 'isComplete' => $this->merchant_center->is_setup_complete(),
- ]
- );
-
- return $assets;
- }
-
- /**
- * Deactivate the service.
- *
- * @return void
- */
- public function deactivate(): void {
- // argument matches the task "key" property
- do_action( 'remove_woocommerce_extended_task_list_item', 'gla_complete_setup' );
- }
-}
diff --git a/src/TaskList/CompleteSetupTask.php b/src/TaskList/CompleteSetupTask.php
new file mode 100644
index 0000000000..bdaf399d3e
--- /dev/null
+++ b/src/TaskList/CompleteSetupTask.php
@@ -0,0 +1,109 @@
+task_list = TaskLists::get_list( $list_id );
+ TaskLists::add_task( $list_id, $this );
+ }
+ );
+ }
+ /**
+ * Get the task id.
+ *
+ * @return string
+ */
+ public function get_id() {
+ return 'gla_complete_setup';
+ }
+
+ /**
+ * Get the task name.
+ *
+ * @return string
+ */
+ public function get_title() {
+ return __(
+ 'Set up Google Listings & Ads',
+ 'google-listings-and-ads'
+ );
+ }
+
+ /**
+ * Get the task description.
+ *
+ * @return string empty string
+ */
+ public function get_content() {
+ return '';
+ }
+
+ /**
+ * Get the task completion time.
+ *
+ * @return string
+ */
+ public function get_time() {
+ return __( '20 minutes', 'google-listings-and-ads' );
+ }
+
+ /**
+ * Always dismissable.
+ *
+ * @return bool
+ */
+ public function is_dismissable() {
+ return true;
+ }
+
+ /**
+ * Get completion status.
+ * Forwards from the merchant center setup status.
+ *
+ * @return bool
+ */
+ public function is_complete() {
+ return $this->merchant_center->is_setup_complete();
+ }
+
+ /**
+ * Get the action URL.
+ *
+ * @return string Start page or dashboard is the setup is completed.
+ */
+ public function get_action_url() {
+ if ( ! $this->is_complete() ) {
+ return admin_url( 'admin.php?page=wc-admin&path=/google/start' );
+ }
+
+ return admin_url( 'admin.php?page=wc-admin&path=/google/dashboard' );
+ }
+
+}
diff --git a/src/TaskList/TaskListTrait.php b/src/TaskList/TaskListTrait.php
deleted file mode 100644
index b0c427c261..0000000000
--- a/src/TaskList/TaskListTrait.php
+++ /dev/null
@@ -1,36 +0,0 @@
-check_should_show_tasks();
- }
-
- /**
- * Helper function to check if UI should show tasks.
- *
- * @return bool
- */
- private function check_should_show_tasks(): bool {
- $setup_list = TaskLists::get_list( 'setup' );
- $extended_list = TaskLists::get_list( 'extended' );
-
- return ( $setup_list && ! $setup_list->is_hidden() ) || ( $extended_list && ! $extended_list->is_hidden() );
- }
-}
diff --git a/tests/Unit/TaskList/CompleteSetupTaskTest.php b/tests/Unit/TaskList/CompleteSetupTaskTest.php
new file mode 100644
index 0000000000..6d7234f6d0
--- /dev/null
+++ b/tests/Unit/TaskList/CompleteSetupTaskTest.php
@@ -0,0 +1,97 @@
+merchant_center = $this->createMock( MerchantCenterService::class );
+
+ // Fetch the task from the global list.
+ $this->task = TaskLists::get_list( 'extended' )->get_task( 'gla_complete_setup' );
+ if ( ! $this->task ) {
+ $this->fail( '`gla_complete_setup` task not found in the extended list.' );
+ }
+ $this->task->set_merchant_center_object( $this->merchant_center );
+ }
+
+ /**
+ * Test a CompleteSetupTask is added to the `extended` list.
+ *
+ * The addition should happen in `register` method, then `init` called before the test was started.
+ * So, we do not precisely assert timing and exact instance, only the presence of a task.
+ */
+ public function test_register() {
+ $this->assertInstanceOf( CompleteSetupTask::class, TaskLists::get_list( 'extended' )->get_task( 'gla_complete_setup' ) );
+
+ }
+
+ public function test_id() {
+ $this->assertEquals( 'gla_complete_setup', $this->task->get_id() );
+ }
+
+ public function test_title() {
+ $this->assertEquals( 'Set up Google Listings & Ads', $this->task->get_title() );
+ }
+
+ public function test_content() {
+ $this->assertEquals( '', $this->task->get_content() );
+ }
+
+ public function test_time() {
+ $this->assertEquals( '20 minutes', $this->task->get_time() );
+ }
+
+ public function test_dismissable() {
+ $this->assertTrue( $this->task->is_dismissable() );
+ }
+
+ public function test_is_complete_and_mc_setup_not_complete() {
+ $this->merchant_center->method( 'is_setup_complete' )->willReturn( false );
+
+ $this->assertFalse( $this->task->is_complete() );
+ }
+
+ public function test_is_complete_and_mc_setup_complete() {
+ $this->merchant_center->method( 'is_setup_complete' )->willReturn( true );
+
+ $this->assertTrue( $this->task->is_complete() );
+ }
+
+ public function test_get_action_url_and_mc_setup_not_complete() {
+ $this->merchant_center->method( 'is_setup_complete' )->willReturn( false );
+
+ $this->assertStringContainsString( 'admin.php?page=wc-admin&path=/google/start', $this->task->get_action_url() );
+ }
+
+ public function test_get_action_url_and_mc_setup_complete() {
+ $this->merchant_center->method( 'is_setup_complete' )->willReturn( true );
+
+ $this->assertStringContainsString( 'admin.php?page=wc-admin&path=/google/dashboard', $this->task->get_action_url() );
+ }
+}
diff --git a/tests/e2e/docker/initialize.sh b/tests/e2e/docker/initialize.sh
index 93455fd437..7db4dbc694 100755
--- a/tests/e2e/docker/initialize.sh
+++ b/tests/e2e/docker/initialize.sh
@@ -19,6 +19,9 @@ wp plugin install https://github.com/WP-API/Basic-Auth/archive/master.zip --acti
# we just need to activate it here.
wp plugin activate google-listings-and-ads
+# Activate twentytwentyone theme. Currently e2e tests wich Blcoks are not supported.
+wp theme activate twentytwentyone
+
# GLA doesn't really need a customer account here,
# but we are leaving it intact here just in case we want to run full WooCommerce core e2e test.
wp user create customer customer@woocommercecoree2etestsuite.com --user_pass=password --role=customer --path=/var/www/html
diff --git a/webpack.config.js b/webpack.config.js
index a4efb2f4f1..553fa70d1b 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -136,11 +136,6 @@ const webpackConfig = {
],
entry: {
index: path.resolve( process.cwd(), 'js/src', 'index.js' ),
- 'task-complete-setup': path.resolve(
- process.cwd(),
- 'js/src/tasks/complete-setup',
- 'index.js'
- ),
'custom-inputs': path.resolve(
process.cwd(),
'js/src/custom-inputs',