2023-03-03 17:02:46 +00:00
/ * *
* External dependencies
* /
import { render , screen } from '@testing-library/react' ;
import userEvent from '@testing-library/user-event' ;
/ * *
* Internal dependencies
* /
2023-03-22 10:38:43 +00:00
import { useCampaignTypes , useRecommendedChannels } from '~/marketing/hooks' ;
2023-03-03 17:02:46 +00:00
import { CreateNewCampaignModal } from './CreateNewCampaignModal' ;
jest . mock ( '@woocommerce/components' , ( ) = > {
const originalModule = jest . requireActual ( '@woocommerce/components' ) ;
return {
__esModule : true ,
. . . originalModule ,
Spinner : ( ) = > < div data - testid = "spinner" > Spinner < / div > ,
} ;
} ) ;
jest . mock ( '~/marketing/hooks' , ( ) = > ( {
2023-03-09 13:52:11 +00:00
useCampaignTypes : jest.fn ( ) ,
2023-03-03 17:02:46 +00:00
useRecommendedChannels : jest.fn ( ) ,
2023-03-22 10:38:43 +00:00
useRegisteredChannels : jest.fn ( ( ) = > ( { } ) ) ,
useInstalledPluginsWithoutChannels : jest.fn ( ( ) = > ( { } ) ) ,
2023-03-03 17:02:46 +00:00
} ) ) ;
2023-03-09 14:31:51 +00:00
const google = {
id : 'google-ads' ,
2024-04-09 08:50:15 +00:00
icon : 'https://woocommerce.com/wp-content/uploads/2021/06/woo-GoogleListingsAds-jworee.png' ,
2023-03-09 14:31:51 +00:00
name : 'Google Ads' ,
description :
'Boost your product listings with a campaign that is automatically optimized to meet your goals.' ,
createUrl :
'https://wc1.test/wp-admin/admin.php?page=wc-admin&path=/google/dashboard&subpath=/campaigns/create' ,
2024-07-22 14:59:43 +00:00
channelName : 'Google for WooCommerce' ,
2023-03-09 14:31:51 +00:00
channelSlug : 'google-listings-and-ads' ,
} ;
const pinterest = {
title : 'Pinterest for WooCommerce' ,
description :
'Grow your business on Pinterest! Use this official plugin to allow shoppers to Pin products while browsing your store, track conversions, and advertise on Pinterest.' ,
2024-04-09 08:50:15 +00:00
url : 'https://woocommerce.com/products/pinterest-for-woocommerce/?utm_source=marketingtab&utm_medium=product&utm_campaign=wcaddons' ,
2023-03-09 14:31:51 +00:00
direct_install : true ,
2024-04-09 08:50:15 +00:00
icon : 'https://woocommerce.com/wp-content/plugins/wccom-plugins/marketing-tab-rest-api/icons/pinterest.svg' ,
2023-03-09 14:31:51 +00:00
product : 'pinterest-for-woocommerce' ,
plugin : 'pinterest-for-woocommerce/pinterest-for-woocommerce.php' ,
categories : [ 'marketing' ] ,
subcategories : [ { slug : 'sales-channels' , name : 'Sales channels' } ] ,
tags : [
{
slug : 'built-by-woocommerce' ,
name : 'Built by WooCommerce' ,
} ,
] ,
show_extension_promotions : true ,
} ;
2023-03-03 17:02:46 +00:00
describe ( 'CreateNewCampaignModal component' , ( ) = > {
it ( 'renders new campaign types with recommended channels' , async ( ) = > {
2023-03-09 13:52:11 +00:00
( useCampaignTypes as jest . Mock ) . mockReturnValue ( {
2023-03-09 14:31:51 +00:00
data : [ google ] ,
2023-03-03 17:02:46 +00:00
} ) ;
( useRecommendedChannels as jest . Mock ) . mockReturnValue ( {
2023-11-16 08:22:33 +00:00
data : [ pinterest ] ,
2023-03-03 17:02:46 +00:00
} ) ;
render ( < CreateNewCampaignModal onRequestClose = { ( ) = > { } } / > ) ;
expect ( screen . getByText ( 'Google Ads' ) ) . toBeInTheDocument ( ) ;
expect (
screen . getByText (
'Boost your product listings with a campaign that is automatically optimized to meet your goals.'
)
) . toBeInTheDocument ( ) ;
// Click button to expand recommended channels section.
await userEvent . click (
screen . getByRole ( 'button' , {
name : 'Add channels for other campaign types' ,
} )
) ;
expect (
screen . getByText ( 'Pinterest for WooCommerce' )
) . toBeInTheDocument ( ) ;
} ) ;
it ( 'does not render recommended channels section when there are no recommended channels' , async ( ) = > {
2023-03-09 13:52:11 +00:00
( useCampaignTypes as jest . Mock ) . mockReturnValue ( {
2023-03-09 14:31:51 +00:00
data : [ google ] ,
2023-03-03 17:02:46 +00:00
} ) ;
( useRecommendedChannels as jest . Mock ) . mockReturnValue ( {
data : [ ] ,
} ) ;
render ( < CreateNewCampaignModal onRequestClose = { ( ) = > { } } / > ) ;
// The expand button should not be there.
expect (
screen . queryByRole ( 'button' , {
name : 'Add channels for other campaign types' ,
} )
) . not . toBeInTheDocument ( ) ;
} ) ;
} ) ;