/** * External dependencies */ import { render } from '@testing-library/react'; import { addFilter } from '@wordpress/hooks'; /** * Internal dependencies */ import { EmbeddedBodyLayout } from '../embedded-body-layout'; jest.mock( '@woocommerce/data', () => ( { useUser: () => ( { currentUserCan: jest.fn(), } ), } ) ); jest.mock( '../../payments', () => ( { PaymentRecommendations: ( { page, tab, section, }: { page: string; tab: string; section?: string; } ) => (
payment_recommendations page:{ page } tab:{ tab } section:{ section || '' }
), } ) ); const stubLocation = ( location: string ) => { jest.spyOn( window, 'location', 'get' ).mockReturnValue( { ...window.location, search: location, } ); }; describe( 'Embedded layout', () => { it( 'should render a fill component with matching name, and provide query params', async () => { stubLocation( '?page=settings&tab=test' ); const { queryByText } = render( ); expect( queryByText( 'payment_recommendations' ) ).toBeInTheDocument(); expect( queryByText( 'page:settings' ) ).toBeInTheDocument(); expect( queryByText( 'tab:test' ) ).toBeInTheDocument(); expect( queryByText( 'section:' ) ).toBeInTheDocument(); } ); it( 'should render a component added through the filter - woocommerce_admin_embedded_layout_components', () => { addFilter( 'woocommerce_admin_embedded_layout_components', 'namespace', ( components ) => { return [ ...components, () => { return
new_component
; }, ]; } ); stubLocation( '?page=settings&tab=test' ); const { queryByText } = render( ); expect( queryByText( 'new_component' ) ).toBeInTheDocument(); } ); } );