jest.mock( '@woocommerce/tracks', () => ( {
...jest.requireActual( '@woocommerce/tracks' ),
recordEvent: jest.fn(),
} ) );
jest.mock( '@woocommerce/wc-admin-settings', () => ( {
...jest.requireActual( '@woocommerce/wc-admin-settings' ),
getSetting: jest.fn( () => 'https://fake-site-url.com' ),
} ) );
/**
* External dependencies
*/
import { recordEvent } from '@woocommerce/tracks';
import { render } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
/**
* Internal dependencies
*/
import {
StoreManagementLinks,
getLinkTypeAndHref,
getItemsByCategory,
generateExtensionLinks,
} from '..';
describe( 'getLinkTypeAndHref', () => {
it( 'generates the correct link for wc-admin links', () => {
const result = getLinkTypeAndHref( {
type: 'wc-admin',
path: 'foo/bar',
} );
expect( result.linkType ).toEqual( 'wc-admin' );
expect( result.href ).toEqual(
'admin.php?page=wc-admin&path=%2Ffoo/bar'
);
} );
it( 'generates the correct link for wp-admin links', () => {
const result = getLinkTypeAndHref( {
type: 'wp-admin',
path: '/foo/bar',
} );
expect( result.linkType ).toEqual( 'wp-admin' );
expect( result.href ).toEqual( '/foo/bar' );
} );
it( 'generates the correct link for wc-settings links', () => {
const result = getLinkTypeAndHref( {
type: 'wc-settings',
tab: 'foo',
} );
expect( result.linkType ).toEqual( 'wp-admin' );
expect( result.href ).toEqual( 'admin.php?page=wc-settings&tab=foo' );
} );
it( 'generates the an external link if there is no provided type', () => {
const result = getLinkTypeAndHref( {
href: 'http://example.com',
} );
expect( result.linkType ).toEqual( 'external' );
expect( result.href ).toEqual( 'http://example.com' );
} );
} );
describe( 'StoreManagementLinks', () => {
it( 'records a track when a link is clicked', () => {
const { queryByText } = render(