Add tests for load sample products
This commit is contained in:
parent
be50584b67
commit
95a319b36d
|
@ -0,0 +1,16 @@
|
|||
/**
|
||||
* External dependencies
|
||||
*/
|
||||
import { render } from '@testing-library/react';
|
||||
|
||||
/**
|
||||
* Internal dependencies
|
||||
*/
|
||||
import LoadSampleProductModal from '../load-sample-product-modal';
|
||||
|
||||
describe( 'LoadSampleProductModal', () => {
|
||||
it( 'should render LoadSampleProductModal', () => {
|
||||
const { queryByText } = render( <LoadSampleProductModal /> );
|
||||
expect( queryByText( 'Loading sample products' ) ).toBeInTheDocument();
|
||||
} );
|
||||
} );
|
|
@ -20,6 +20,13 @@ jest.mock( '~/utils/admin-settings', () => ( {
|
|||
getAdminSetting: jest.fn(),
|
||||
} ) );
|
||||
|
||||
global.fetch = jest.fn().mockImplementation( () =>
|
||||
Promise.resolve( {
|
||||
json: () => Promise.resolve( {} ),
|
||||
status: 200,
|
||||
} )
|
||||
);
|
||||
|
||||
describe( 'Products', () => {
|
||||
beforeEach( () => {
|
||||
jest.clearAllMocks();
|
||||
|
@ -75,4 +82,27 @@ describe( 'Products', () => {
|
|||
|
||||
expect( queryByText( 'View less product types' ) ).toBeInTheDocument();
|
||||
} );
|
||||
|
||||
it( 'should send a request to load sample products when the link is clicked', async () => {
|
||||
const fetchMock = jest.spyOn( global, 'fetch' );
|
||||
const { queryByText, getByRole } = render( <Products /> );
|
||||
|
||||
expect( queryByText( 'Load Sample Products' ) ).toBeInTheDocument();
|
||||
|
||||
userEvent.click(
|
||||
getByRole( 'link', { name: 'Load Sample Products' } )
|
||||
);
|
||||
|
||||
await waitFor( () =>
|
||||
expect( fetchMock ).toHaveBeenCalledWith(
|
||||
'/wc-admin/onboarding/tasks/import_sample_products?_locale=user',
|
||||
{
|
||||
body: undefined,
|
||||
credentials: 'include',
|
||||
headers: { Accept: 'application/json, */*;q=0.1' },
|
||||
method: 'POST',
|
||||
}
|
||||
)
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
|
Loading…
Reference in New Issue