/** * External dependencies */ import { render } from '@testing-library/react'; import { addFilter, removeAllFilters } from '@wordpress/hooks'; /** * Internal dependencies */ import { HelpPanel, SETUP_TASK_HELP_ITEMS_FILTER } from '../panels/help'; describe( 'Activity Panels', () => { describe( 'Help', () => { it( 'only shows links for suggested payment gateways', () => { const fixtures = [ { id: 'woocommerce_payments', text: 'WooPayments', }, { id: 'stripe', text: 'Stripe', }, { id: 'kco', text: 'Klarna', }, { id: 'klarna_payments', text: 'Klarna', }, { id: 'ppcp-gateway', text: 'PayPal Checkout', }, { id: 'square_credit_card', text: 'Square', }, { id: 'payfast', text: 'Payfast', }, { id: 'eway', text: 'Eway', }, ]; const noSuggestions = render( [] } taskName="payments" /> ); fixtures.forEach( ( method ) => { expect( noSuggestions.queryAllByText( ( text ) => text.includes( method.text ) ) ).toHaveLength( 0 ); } ); fixtures.forEach( ( method ) => { const { queryAllByText } = render( ); expect( queryAllByText( ( text ) => text.includes( method.text ) ) .length ).toBeGreaterThanOrEqual( 1 ); } ); } ); it( 'only shows links for automated tax when supported', () => { const taxjarPluginEnabled = render( ); expect( taxjarPluginEnabled.queryByText( /WooCommerce Tax/ ) ).toBeNull(); const unSupportedCountry = render( ); expect( unSupportedCountry.queryByText( /WooCommerce Tax/ ) ).toBeNull(); const supportedCountry = render( ); expect( supportedCountry.getByText( /WooCommerce Tax/ ) ).toBeDefined(); } ); it( 'only shows links for WooCommerce Shipping when supported', () => { const wcsActive = render( ); expect( wcsActive.queryByText( /WooCommerce Shipping/ ) ).toBeNull(); const unSupportedCountry = render( ); expect( unSupportedCountry.queryByText( /WooCommerce Shipping/ ) ).toBeNull(); const supportedCountry = render( ); expect( supportedCountry.getByText( /WooCommerce Shipping/ ) ).toBeDefined(); } ); it( 'only shows links for home screen when supported', () => { const homescreen = render( ); const homescreenLinkTitles = [ 'Get Support', 'Home Screen', 'Inbox', 'Stats Overview', 'Store Management', 'Store Setup Checklist', ]; homescreenLinkTitles.forEach( ( title ) => { expect( homescreen.getByText( title ) ).toBeDefined(); } ); } ); describe( 'Filters', () => { const testNamespace = 'wc/admin/tests'; afterEach( () => { removeAllFilters( SETUP_TASK_HELP_ITEMS_FILTER, testNamespace ); } ); it( 'defaults to generic link with non-arrays', () => { // Return a non-array. addFilter( SETUP_TASK_HELP_ITEMS_FILTER, testNamespace, () => ( {} ) ); const nonArray = render( ); // Verify non-arrays default to generic docs link. expect( nonArray.getByText( 'WooCommerce Docs' ) ).toBeDefined(); } ); it( 'defaults to generic link with empty arrays', () => { // Return an empty array. addFilter( SETUP_TASK_HELP_ITEMS_FILTER, testNamespace, () => [] ); const emptyArray = render( ); // Verify empty arrays default to generic docs link. expect( emptyArray.getByText( 'WooCommerce Docs' ) ).toBeDefined(); } ); it( 'defaults to generic link with malformed arrays', () => { // Return an malformed array. addFilter( SETUP_TASK_HELP_ITEMS_FILTER, testNamespace, () => [ { title: 'missing a link!', }, ] ); const badArray = render( ); // Verify malformed arrays default to generic docs link. expect( badArray.getByText( 'WooCommerce Docs' ) ).toBeDefined(); } ); it( 'allows help items to be replaced', () => { // Replace all help items. addFilter( SETUP_TASK_HELP_ITEMS_FILTER, testNamespace, () => [ { title: 'There can only be one', link: 'https://www.google.com/search?q=highlander', }, ] ); const replacedArray = render( ); // Verify filtered array. expect( replacedArray.queryByText( 'WooCommerce Docs' ) ).toBeNull(); expect( replacedArray.getByText( 'There can only be one' ) ).toBeDefined(); } ); } ); } ); } );