Skip to content

Commit

Permalink
Update tests to also mock the canInstallPlugins
Browse files Browse the repository at this point in the history
Similar to the other mocks in these tests.
  • Loading branch information
renatho committed Oct 24, 2024
1 parent 456d3aa commit 3b1a5e6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions client/hosting/overview/components/test/migration-overview.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
/**
* @jest-environment jsdom
*/
import { canInstallPlugins } from '@automattic/sites';
import { render } from '@testing-library/react';
import React from 'react';
import { getMigrationStatus, getMigrationType } from 'calypso/sites-dashboard/utils';
import MigrationOverview from '../migration-overview';
import type { SiteDetails, SiteDetailsPlan } from '@automattic/data-stores';
import type { SiteDetails } from '@automattic/data-stores';

jest.mock( '@automattic/sites' );
jest.mock( 'calypso/sites-dashboard/utils' );
jest.mock( '@automattic/calypso-products' );

describe( 'MigrationOverview', () => {
beforeEach( () => {
( getMigrationStatus as jest.Mock ).mockReturnValue( 'pending' );
} );
const baseSite = {
ID: 123,
slug: 'example.com',
} as SiteDetails;

describe( 'MigrationOverview', () => {
it.each( [
[
'diy',
Expand Down Expand Up @@ -48,18 +50,12 @@ describe( 'MigrationOverview', () => {
],
] )(
'should set continueMigrationUrl correctly for migrationType: %s and isFreePlan: %s',
( migrationType, canInstallPlugins, expectedUrl ) => {
( migrationType, siteCanInstallPlugins, expectedUrl ) => {
( getMigrationType as jest.Mock ).mockReturnValue( migrationType );
( getMigrationStatus as jest.Mock ).mockReturnValue( 'pending' );
( canInstallPlugins as jest.Mock ).mockReturnValue( siteCanInstallPlugins );

const site = {
ID: 123,
slug: 'example.com',
plan: {
features: { active: canInstallPlugins ? [ 'install-plugins' ] : [] },
} as SiteDetailsPlan,
} as SiteDetails;

const { getByText } = render( <MigrationOverview site={ site } /> );
const { getByText } = render( <MigrationOverview site={ baseSite } /> );
const button = getByText( 'Start your migration' );

expect( button ).toHaveAttribute( 'href', expectedUrl );
Expand Down

0 comments on commit 3b1a5e6

Please sign in to comment.