From 617b51c91d77a1e31e5e0a33569ba873a0cfac8f Mon Sep 17 00:00:00 2001 From: Gan Eng Chin Date: Tue, 20 Jun 2023 23:03:56 +0800 Subject: [PATCH] Add and fix tests for Campaigns component. --- .../Campaigns/Campaigns.test.tsx | 39 ++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.test.tsx b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.test.tsx index aaa59396728..cfa9088b95b 100644 --- a/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.test.tsx +++ b/plugins/woocommerce-admin/client/marketing/overview-multichannel/Campaigns/Campaigns.test.tsx @@ -158,7 +158,7 @@ describe( 'Campaigns component', () => { expect( screen.getByText( 'Campaign 6' ) ).toBeInTheDocument(); } ); - it( 'renders a "Create new campaign" button in the card header, and upon clicking, displays the "Create a new campaign" modal', async () => { + it( 'does not render a "Create new campaign" button in the card header when there are no campaign types', async () => { ( useCampaigns as jest.Mock ).mockReturnValue( { loading: false, error: undefined, @@ -169,6 +169,43 @@ describe( 'Campaigns component', () => { } ); ( useCampaignTypes as jest.Mock ).mockReturnValue( { loading: false, + data: [], + } ); + + render( ); + + expect( + screen.queryByRole( 'button', { name: 'Create new campaign' } ) + ).not.toBeInTheDocument(); + } ); + + it( 'renders a "Create new campaign" button in the card header when there are campaign types, and upon clicking, displays the "Create a new campaign" modal', async () => { + ( useCampaigns as jest.Mock ).mockReturnValue( { + loading: false, + error: undefined, + data: [ createTestCampaign( '1' ) ], + meta: { + total: 1, + }, + } ); + ( useCampaignTypes as jest.Mock ).mockReturnValue( { + loading: false, + data: [ + { + id: 'google-ads', + name: 'Google Ads', + description: + 'Boost your product listings with a campaign that is automatically optimized to meet your goals.', + channel: { + slug: 'google-listings-and-ads', + name: 'Google Listings & Ads', + }, + create_url: + 'https://wc1.test/wp-admin/admin.php?page=wc-admin&path=/google/dashboard&subpath=/campaigns/create', + icon_url: + 'https://woocommerce.com/wp-content/uploads/2021/06/woo-GoogleListingsAds-jworee.png', + }, + ], } ); render( );