2024-06-07 07:14:26 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2024-06-12 06:39:21 +00:00
|
|
|
import { render, fireEvent, screen } from '@testing-library/react';
|
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
|
|
|
import { useState } from '@wordpress/element';
|
2024-06-07 07:14:26 +00:00
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import ConnectAccountPage from '..';
|
2024-06-12 06:39:21 +00:00
|
|
|
import { getAdminSetting } from '~/utils/admin-settings';
|
2024-06-07 07:14:26 +00:00
|
|
|
|
2024-06-12 06:39:21 +00:00
|
|
|
jest.mock( '@wordpress/data', () => ( {
|
|
|
|
...jest.requireActual( '@wordpress/data' ),
|
|
|
|
useDispatch: jest.fn(),
|
|
|
|
useSelect: jest.fn(),
|
|
|
|
} ) );
|
2024-06-07 07:14:26 +00:00
|
|
|
jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
|
2024-06-12 06:39:21 +00:00
|
|
|
jest.mock( '~/utils/admin-settings', () => ( { getAdminSetting: jest.fn() } ) );
|
|
|
|
jest.mock( '@wordpress/element', () => ( {
|
|
|
|
...jest.requireActual( '@wordpress/element' ),
|
|
|
|
useState: jest.fn(),
|
|
|
|
} ) );
|
|
|
|
jest.mock( '../apms', () => jest.fn().mockReturnValue( null ) );
|
|
|
|
jest.mock( '../banner', () =>
|
|
|
|
jest.fn().mockImplementation( ( { handleSetup } ) => (
|
|
|
|
<div>
|
|
|
|
<button onClick={ handleSetup }>Handle Setup Button</button>
|
|
|
|
</div>
|
|
|
|
) )
|
|
|
|
);
|
2024-06-07 07:14:26 +00:00
|
|
|
|
|
|
|
describe( 'Connect Account Page', () => {
|
2024-06-12 06:39:21 +00:00
|
|
|
const setupMocks = () => {
|
|
|
|
( useDispatch as jest.Mock ).mockReturnValue( {
|
|
|
|
updateOptions: jest.fn(),
|
|
|
|
installAndActivatePlugins: jest.fn(),
|
|
|
|
} );
|
|
|
|
( useState as jest.Mock )
|
|
|
|
.mockImplementationOnce( () => [ false, jest.fn() ] ) // isSubmitted state
|
|
|
|
.mockImplementationOnce( () => [ '', jest.fn() ] ) // errorMessage state
|
|
|
|
.mockImplementationOnce( () => [ new Set(), jest.fn() ] ); // enabledApms state
|
|
|
|
( useSelect as jest.Mock ).mockReturnValue( {
|
|
|
|
isJetpackConnected: true,
|
|
|
|
connectUrl: '',
|
|
|
|
} );
|
|
|
|
( getAdminSetting as jest.Mock ).mockReturnValue( {
|
|
|
|
id: 'incentiveId',
|
|
|
|
} );
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
setupMocks();
|
|
|
|
} );
|
|
|
|
|
2024-06-07 07:14:26 +00:00
|
|
|
it( 'should fire custom page_view track when viewing', async () => {
|
|
|
|
render( <ConnectAccountPage /> );
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith( 'page_view', {
|
|
|
|
path: 'payments_connect_core_test',
|
2024-06-12 06:39:21 +00:00
|
|
|
incentive_id: 'incentiveId',
|
2024-06-07 07:14:26 +00:00
|
|
|
} );
|
|
|
|
} );
|
2024-06-12 06:39:21 +00:00
|
|
|
|
|
|
|
it( 'should trigger wcpay_connect_account_clicked event when clicking connect', async () => {
|
|
|
|
render( <ConnectAccountPage /> );
|
|
|
|
fireEvent.click( screen.getByText( 'Handle Setup Button' ) );
|
|
|
|
expect( recordEvent ).toHaveBeenNthCalledWith(
|
|
|
|
2,
|
|
|
|
'wcpay_connect_account_clicked',
|
|
|
|
{
|
|
|
|
wpcom_connection: 'Yes',
|
|
|
|
incentive_id: 'incentiveId',
|
|
|
|
}
|
|
|
|
);
|
|
|
|
} );
|
2024-06-07 07:14:26 +00:00
|
|
|
} );
|