diff --git a/packages/js/src/integrations-page/google-site-kit-integration.js b/packages/js/src/integrations-page/google-site-kit-integration.js
index 3d8387838ba..249476c9316 100644
--- a/packages/js/src/integrations-page/google-site-kit-integration.js
+++ b/packages/js/src/integrations-page/google-site-kit-integration.js
@@ -60,10 +60,7 @@ const buttonLabels = {
* @returns {WPElement} The Site Kit integration component.
*/
export const GoogleSiteKitIntegration = () => {
- const isActive = get( window, "wpseoIntegrationsData.google_site_kit.active", false );
- const afterSetup = get( window, "wpseoIntegrationsData.google_site_kit.setup", false );
- const isInstalled = get( window, "wpseoIntegrationsData.google_site_kit.installed", false );
- const isConnected = get( window, "wpseoIntegrationsData.google_site_kit.connected", false );
+ const { isActive, afterSetup, isInstalled, isConnected } = get( window, "wpseoIntegrationsData.googleSiteKit", { isActive: false, afterSetup: false, isInstalled: false, isConnected: false } );
const [ isModalOpen, toggleModal ] = useToggleState( false );
const getButtonConfig = useCallback( () => {
@@ -88,6 +85,7 @@ export const GoogleSiteKitIntegration = () => {
button.as = "button";
} else if ( isConnected ) {
button.children = buttonLabels.disconnect;
+ button.as = "button";
button.variant = "secondary";
}
diff --git a/packages/js/src/integrations-page/recommended-integrations.js b/packages/js/src/integrations-page/recommended-integrations.js
index 2fc4e60eb24..bd4de0d59d3 100644
--- a/packages/js/src/integrations-page/recommended-integrations.js
+++ b/packages/js/src/integrations-page/recommended-integrations.js
@@ -63,7 +63,7 @@ const integrations = [
},
];
-const isGoogleSiteKitFeatureEnabled = get( window, "wpseoIntegrationsData.google_site_kit.featureEnabled", false );
+const isGoogleSiteKitFeatureEnabled = get( window, "wpseoIntegrationsData.googleSiteKit.featureEnabled", false );
const RecommendedIntegrations = [
integrations.map( ( integration, index ) => {
@@ -82,8 +82,8 @@ const RecommendedIntegrations = [
];
-if( isGoogleSiteKitFeatureEnabled ) {
+if ( isGoogleSiteKitFeatureEnabled ) {
RecommendedIntegrations.push( );
}
-export { RecommendedIntegrations };
\ No newline at end of file
+export { RecommendedIntegrations };
diff --git a/packages/js/tests/integrations-page/GoogleSiteKitIntegration.test.js b/packages/js/tests/integrations-page/GoogleSiteKitIntegration.test.js
new file mode 100644
index 00000000000..3a835f6d737
--- /dev/null
+++ b/packages/js/tests/integrations-page/GoogleSiteKitIntegration.test.js
@@ -0,0 +1,87 @@
+import React from "react";
+import { render, screen } from "../test-utils";
+import { GoogleSiteKitIntegration } from "../../src/integrations-page/google-site-kit-integration";
+import { expect } from "@jest/globals";
+
+describe( "GoogleSiteKitIntegration", () => {
+ it( "renders the integration component", () => {
+ render( );
+ expect( screen.getByText( "Site Kit by Google" ) ).toBeInTheDocument();
+ } );
+
+ it( "shows 'Install Site Kit by Google' link when not installed", () => {
+ window.wpseoIntegrationsData = {
+ googleSiteKit: {
+ isActive: false,
+ afterSetup: false,
+ isInstalled: false,
+ isConnected: false,
+ },
+ };
+ render( );
+ const link = screen.getByRole( "link", { name: "Install Site Kit by Google" } );
+ expect( link ).toBeInTheDocument();
+ expect( link ).toHaveAttribute( "href", "/wp-admin/plugin-install.php?s=google%2520site%2520kit&tab=search&type=term" );
+ expect( screen.getByText( "Plugin not detected" ) ).toBeInTheDocument();
+ } );
+
+ it( "shows 'Activate Site Kit by Google' button when installed but not active", () => {
+ window.wpseoIntegrationsData = {
+ googleSiteKit: {
+ isActive: false,
+ afterSetup: false,
+ isInstalled: true,
+ isConnected: false,
+ },
+ };
+ render( );
+ const link = screen.getByRole( "link", { name: "Activate Site Kit by Google" } );
+ expect( link ).toBeInTheDocument();
+ expect( link ).toHaveAttribute( "href", "/wp-admin/plugins.php" );
+ expect( screen.getByText( "Plugin not detected" ) ).toBeInTheDocument();
+ } );
+
+ it( "shows 'Set up Site Kit by Google' button when active but not set up", () => {
+ window.wpseoIntegrationsData = {
+ googleSiteKit: {
+ isActive: true,
+ afterSetup: false,
+ isInstalled: true,
+ isConnected: false,
+ },
+ };
+ render( );
+ const link = screen.getByRole( "link", { name: "Set up Site Kit by Google" } );
+ expect( link ).toBeInTheDocument();
+ expect( link ).toHaveAttribute( "href", "/wp-admin/admin.php?page=googlesitekit-splash" );
+ expect( screen.getByText( "Not connected" ) ).toBeInTheDocument();
+ } );
+
+ it( "shows 'Connect Site Kit by Google' button when set up but not connected", () => {
+ window.wpseoIntegrationsData = {
+ googleSiteKit: {
+ isActive: true,
+ afterSetup: true,
+ isInstalled: true,
+ isConnected: false,
+ },
+ };
+ render( );
+ expect( screen.getByRole( "button", { name: "Connect Site Kit by Google" } ) ).toBeInTheDocument();
+ expect( screen.getByText( "Not connected" ) ).toBeInTheDocument();
+ } );
+
+ it( "shows 'Disconnect' button when connected", () => {
+ window.wpseoIntegrationsData = {
+ googleSiteKit: {
+ isActive: true,
+ afterSetup: true,
+ isInstalled: true,
+ isConnected: true,
+ },
+ };
+ render( );
+ expect( screen.getByRole( "button", { name: "Disconnect" } ) ).toBeInTheDocument();
+ expect( screen.getByText( "Successfully connected" ) ).toBeInTheDocument();
+ } );
+} );
diff --git a/packages/js/tests/setupTests.js b/packages/js/tests/setupTests.js
index c3eb5a5a55d..cfe2585aa9d 100644
--- a/packages/js/tests/setupTests.js
+++ b/packages/js/tests/setupTests.js
@@ -29,6 +29,10 @@ global.wpApiSettings = {
root: "http://example.com",
};
+global.wpseoScriptData = {
+ isPremium: 0,
+};
+
/* Mock the IntersectionObserver. */
global.IntersectionObserver = class {
/**
diff --git a/src/integrations/admin/integrations-page.php b/src/integrations/admin/integrations-page.php
index b5e4065be22..64544403a30 100644
--- a/src/integrations/admin/integrations-page.php
+++ b/src/integrations/admin/integrations-page.php
@@ -197,11 +197,11 @@ public function enqueue_assets() {
'mastodon_active' => $mastodon_active,
'is_multisite' => \is_multisite(),
'plugin_url' => \plugins_url( '', \WPSEO_FILE ),
- 'google_site_kit' => [
- 'installed' => \file_exists( \WP_PLUGIN_DIR . '/' . $google_site_kit_file ),
- 'active' => \is_plugin_active( $google_site_kit_file ),
- 'setup' => \get_option( 'googlesitekit_has_connected_admins', false ) === "1",
- 'connected' => $this->options_helper->get( 'google_site_kit_connected', false ),
+ 'googleSiteKit' => [
+ 'isInstalled' => \file_exists( \WP_PLUGIN_DIR . '/' . $google_site_kit_file ),
+ 'isActive' => \is_plugin_active( $google_site_kit_file ),
+ 'afterSetup' => \get_option( 'googlesitekit_has_connected_admins', false ) === "1",
+ 'isConnected' => $this->options_helper->get( 'google_site_kit_connected', false ),
'featureEnabled' => $google_site_kit_conditional->is_met(),
],
]