Skip to content

Commit

Permalink
tests for GoogleSiteKitIntegration
Browse files Browse the repository at this point in the history
And renaming

tests links
  • Loading branch information
vraja-pro committed Jan 6, 2025
1 parent be33a54 commit 657eccc
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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( () => {
Expand All @@ -88,6 +85,7 @@ export const GoogleSiteKitIntegration = () => {
button.as = "button";
} else if ( isConnected ) {
button.children = buttonLabels.disconnect;
button.as = "button";
button.variant = "secondary";
}

Expand Down
6 changes: 3 additions & 3 deletions packages/js/src/integrations-page/recommended-integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) => {
Expand All @@ -82,8 +82,8 @@ const RecommendedIntegrations = [
];


if( isGoogleSiteKitFeatureEnabled ) {
if ( isGoogleSiteKitFeatureEnabled ) {
RecommendedIntegrations.push( <GoogleSiteKitIntegration key={ integrations.length } /> );
}

export { RecommendedIntegrations };
export { RecommendedIntegrations };
Original file line number Diff line number Diff line change
@@ -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( <GoogleSiteKitIntegration /> );
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( <GoogleSiteKitIntegration /> );
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( <GoogleSiteKitIntegration /> );
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( <GoogleSiteKitIntegration /> );
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( <GoogleSiteKitIntegration /> );
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( <GoogleSiteKitIntegration /> );
expect( screen.getByRole( "button", { name: "Disconnect" } ) ).toBeInTheDocument();
expect( screen.getByText( "Successfully connected" ) ).toBeInTheDocument();
} );
} );
4 changes: 4 additions & 0 deletions packages/js/tests/setupTests.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ global.wpApiSettings = {
root: "http://example.com",
};

global.wpseoScriptData = {
isPremium: 0,
};

/* Mock the IntersectionObserver. */
global.IntersectionObserver = class {
/**
Expand Down
10 changes: 5 additions & 5 deletions src/integrations/admin/integrations-page.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
],
]
Expand Down

0 comments on commit 657eccc

Please sign in to comment.