/** * 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 available payment methods', () => { const fixtures = [ { key: 'wcpay', text: 'WooCommerce Payments', }, { key: 'stripe', text: 'Stripe', }, { key: 'klarna_checkout', text: 'Klarna', }, { key: 'klarna_payments', text: 'Klarna', }, { key: 'paypal', text: 'PayPal Checkout', }, { key: 'square', text: 'Square', }, { key: 'payfast', text: 'PayFast', }, { key: 'eway', text: 'eWAY', }, ]; const noMethods = render( [] } taskName="payments" /> ); fixtures.forEach( ( method ) => { expect( noMethods.queryAllByText( ( text ) => text.includes( method.text ) ) ).toHaveLength( 0 ); } ); fixtures.forEach( ( method ) => { const { queryAllByText } = render( [ method ] } taskName="payments" /> ); expect( queryAllByText( ( text ) => text.includes( method.text ) ) .length ).toBeGreaterThanOrEqual( 1 ); } ); } ); it( 'only shows links for automated tax when supported', () => { const taxjarPluginEnabled = render( ( { automatedTaxSupportedCountries: [ 'US' ], taxJarActivated: true, } ) } taskName="tax" /> ); expect( taxjarPluginEnabled.queryByText( /WooCommerce Tax/ ) ).toBeNull(); const unSupportedCountry = render( ( { automatedTaxSupportedCountries: [ 'US' ], taxJarActivated: false, } ) } taskName="tax" /> ); expect( unSupportedCountry.queryByText( /WooCommerce Tax/ ) ).toBeNull(); const supportedCountry = render( ( { automatedTaxSupportedCountries: [ 'US' ], taxJarActivated: false, } ) } taskName="tax" /> ); 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(); } ); } ); } ); } );