/** * External dependencies */ import { render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; /** * Internal dependencies */ import LocalPickupSelect from '..'; describe( 'LocalPickupSelect', () => { const TestComponent = ( { selectedOptionOverride = null, onSelectRateOverride = null, }: { selectedOptionOverride?: null | ( ( value: string ) => void ); onSelectRateOverride?: null | ( ( value: string ) => void ); } ) => ( { return { value: `${ location.rate_id }`, onChange: jest.fn(), label: `${ location.name }`, description: `${ location.description }`, }; } } /> ); it( 'Does not render the title if only one package is present on the page', () => { render( ); expect( screen.queryByText( 'Package 1' ) ).not.toBeInTheDocument(); } ); it( 'Does render the title if more than one package is present on the page', () => { const { rerender } = render(
); // Render twice so our component can check the DOM correctly. rerender( <>
); rerender( <>
); expect( screen.getByText( 'Package 1' ) ).toBeInTheDocument(); } ); it( 'Calls the correct functions when changing selected option', () => { const setSelectedOption = jest.fn(); const onSelectRate = jest.fn(); render( ); userEvent.click( screen.getByText( 'Store 2' ) ); expect( setSelectedOption ).toHaveBeenLastCalledWith( '2' ); expect( onSelectRate ).toHaveBeenLastCalledWith( '2' ); userEvent.click( screen.getByText( 'Store 1' ) ); expect( setSelectedOption ).toHaveBeenLastCalledWith( '1' ); expect( onSelectRate ).toHaveBeenLastCalledWith( '1' ); } ); } );