2022-09-14 07:43:30 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2023-03-21 13:13:19 +00:00
|
|
|
import { useRecommendedPluginsWithoutChannels } from './useRecommendedPluginsWithoutChannels';
|
2022-09-14 07:43:30 +00:00
|
|
|
import { DiscoverTools } from './DiscoverTools';
|
|
|
|
|
|
|
|
jest.mock( '@woocommerce/components', () => {
|
|
|
|
const originalModule = jest.requireActual( '@woocommerce/components' );
|
|
|
|
|
|
|
|
return {
|
|
|
|
__esModule: true,
|
|
|
|
...originalModule,
|
|
|
|
Spinner: () => <div data-testid="spinner">Spinner</div>,
|
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2023-03-21 13:13:19 +00:00
|
|
|
jest.mock( './useRecommendedPluginsWithoutChannels', () => ( {
|
2023-03-21 13:12:00 +00:00
|
|
|
useRecommendedPluginsWithoutChannels: jest.fn(),
|
2022-09-14 07:43:30 +00:00
|
|
|
} ) );
|
|
|
|
|
2023-03-21 11:08:13 +00:00
|
|
|
jest.mock( '~/marketing/hooks', () => ( {
|
2023-03-22 08:07:51 +00:00
|
|
|
useInstalledPluginsWithoutChannels: jest.fn( () => ( {} ) ),
|
2022-11-24 13:46:08 +00:00
|
|
|
} ) );
|
|
|
|
|
2022-09-14 07:43:30 +00:00
|
|
|
describe( 'DiscoverTools component', () => {
|
|
|
|
it( 'should render a Spinner when loading is in progress', () => {
|
2023-03-21 13:12:00 +00:00
|
|
|
( useRecommendedPluginsWithoutChannels as jest.Mock ).mockReturnValue( {
|
2022-11-24 13:46:08 +00:00
|
|
|
isInitializing: true,
|
2022-09-14 07:43:30 +00:00
|
|
|
isLoading: true,
|
2023-03-21 13:12:00 +00:00
|
|
|
data: [],
|
2022-09-14 07:43:30 +00:00
|
|
|
} );
|
|
|
|
render( <DiscoverTools /> );
|
|
|
|
|
|
|
|
expect( screen.getByTestId( 'spinner' ) ).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should render message and link when loading is finish and there are no plugins', () => {
|
2023-03-21 13:12:00 +00:00
|
|
|
( useRecommendedPluginsWithoutChannels as jest.Mock ).mockReturnValue( {
|
2022-11-24 13:46:08 +00:00
|
|
|
isInitializing: false,
|
2022-09-14 07:43:30 +00:00
|
|
|
isLoading: false,
|
2023-03-21 13:12:00 +00:00
|
|
|
data: [],
|
2022-09-14 07:43:30 +00:00
|
|
|
} );
|
|
|
|
render( <DiscoverTools /> );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
'Continue to reach the right audiences and promote your products in ways that matter to them with our range of marketing solutions.'
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByText( 'Explore more marketing extensions' )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
2022-11-24 13:46:08 +00:00
|
|
|
describe( 'With plugins loaded', () => {
|
2023-07-06 15:50:56 +00:00
|
|
|
it( 'should render `direct_install: true` plugins with "Install extension" button', () => {
|
2023-03-21 13:12:00 +00:00
|
|
|
(
|
|
|
|
useRecommendedPluginsWithoutChannels as jest.Mock
|
|
|
|
).mockReturnValue( {
|
2022-11-24 13:46:08 +00:00
|
|
|
isInitializing: false,
|
|
|
|
isLoading: false,
|
2023-03-21 13:12:00 +00:00
|
|
|
data: [
|
2022-11-24 13:46:08 +00:00
|
|
|
{
|
|
|
|
title: 'Google Listings and Ads',
|
|
|
|
description:
|
|
|
|
'Get in front of shoppers and drive traffic so you can grow your business with Smart Shopping Campaigns and free listings.',
|
2023-11-06 11:45:26 +00:00
|
|
|
url: 'https://woo.com/products/google-listings-and-ads/?utm_source=marketingtab&utm_medium=product&utm_campaign=wcaddons',
|
2022-11-24 13:46:08 +00:00
|
|
|
direct_install: true,
|
2023-11-06 11:45:26 +00:00
|
|
|
icon: 'https://woo.com/wp-content/plugins/wccom-plugins/marketing-tab-rest-api/icons/google.svg',
|
2022-11-24 13:46:08 +00:00
|
|
|
product: 'google-listings-and-ads',
|
|
|
|
plugin: 'google-listings-and-ads/google-listings-and-ads.php',
|
|
|
|
categories: [ 'marketing' ],
|
|
|
|
subcategories: [
|
|
|
|
{
|
|
|
|
slug: 'sales-channels',
|
|
|
|
name: 'Sales channels',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tags: [
|
|
|
|
{
|
|
|
|
slug: 'built-by-woocommerce',
|
|
|
|
name: 'Built by WooCommerce',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} );
|
|
|
|
render( <DiscoverTools /> );
|
|
|
|
|
2023-07-06 15:50:56 +00:00
|
|
|
// Assert that we have the "Sales channels" tab, the plugin name, the "Built by WooCommerce" pill, and the "Install extension" button.
|
2022-11-24 13:46:08 +00:00
|
|
|
expect( screen.getByText( 'Sales channels' ) ).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByText( 'Google Listings and Ads' )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByText( 'Built by WooCommerce' )
|
|
|
|
).toBeInTheDocument();
|
2023-07-06 15:50:56 +00:00
|
|
|
expect(
|
|
|
|
screen.getByText( 'Install extension' )
|
|
|
|
).toBeInTheDocument();
|
2022-09-14 07:43:30 +00:00
|
|
|
} );
|
|
|
|
|
2022-11-24 13:46:08 +00:00
|
|
|
it( 'should render `direct_install: false` plugins with "View details" button', () => {
|
2023-03-21 13:12:00 +00:00
|
|
|
(
|
|
|
|
useRecommendedPluginsWithoutChannels as jest.Mock
|
|
|
|
).mockReturnValue( {
|
2022-11-24 13:46:08 +00:00
|
|
|
isInitializing: false,
|
|
|
|
isLoading: false,
|
2023-03-21 13:12:00 +00:00
|
|
|
data: [
|
2022-11-24 13:46:08 +00:00
|
|
|
{
|
|
|
|
title: 'WooCommerce Zapier',
|
|
|
|
description:
|
|
|
|
'Integrate your WooCommerce store with 5000+ cloud apps and services today. Trusted by 11,000+ users.',
|
2023-11-06 11:45:26 +00:00
|
|
|
url: 'https://woo.com/products/woocommerce-zapier/?utm_source=marketingtab&utm_medium=product&utm_campaign=wcaddons',
|
2022-11-24 13:46:08 +00:00
|
|
|
direct_install: false,
|
2023-11-06 11:45:26 +00:00
|
|
|
icon: 'https://woo.com/wp-content/plugins/wccom-plugins/marketing-tab-rest-api/icons/zapier.png',
|
2022-11-24 13:46:08 +00:00
|
|
|
product: 'woocommerce-zapier',
|
|
|
|
plugin: 'woocommerce-zapier/woocommerce-zapier.php',
|
|
|
|
categories: [ 'marketing' ],
|
|
|
|
subcategories: [
|
|
|
|
{
|
|
|
|
slug: 'crm',
|
|
|
|
name: 'CRM',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
tags: [],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
} );
|
|
|
|
render( <DiscoverTools /> );
|
|
|
|
|
|
|
|
// Assert that we have the CRM tab, plugin name, and "View details" button.
|
|
|
|
expect( screen.getByText( 'CRM' ) ).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
screen.getByText( 'WooCommerce Zapier' )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect( screen.getByText( 'View details' ) ).toBeInTheDocument();
|
|
|
|
} );
|
2022-09-14 07:43:30 +00:00
|
|
|
} );
|
|
|
|
} );
|