2023-09-19 03:37:46 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2023-12-06 12:49:28 +00:00
|
|
|
import { createContext } from '@wordpress/element';
|
2023-09-19 03:37:46 +00:00
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { OnboardingTour } from '../index';
|
2024-01-11 14:32:16 +00:00
|
|
|
import { FlowType } from '~/customize-store/types';
|
2023-09-19 03:37:46 +00:00
|
|
|
|
|
|
|
jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
|
2023-12-06 12:49:28 +00:00
|
|
|
jest.mock( '../../', () => ( {
|
|
|
|
CustomizeStoreContext: createContext( {
|
|
|
|
context: {
|
|
|
|
aiOnline: true,
|
|
|
|
},
|
|
|
|
} ),
|
|
|
|
} ) );
|
2023-09-19 03:37:46 +00:00
|
|
|
|
|
|
|
describe( 'OnboardingTour', () => {
|
|
|
|
let props: {
|
|
|
|
onClose: jest.Mock;
|
2023-12-21 15:56:22 +00:00
|
|
|
skipTour: jest.Mock;
|
|
|
|
takeTour: jest.Mock;
|
2023-09-19 03:37:46 +00:00
|
|
|
setShowWelcomeTour: jest.Mock;
|
|
|
|
showWelcomeTour: boolean;
|
2024-01-11 14:32:16 +00:00
|
|
|
flowType: FlowType.AIOnline | FlowType.noAI;
|
2023-10-26 10:15:30 +00:00
|
|
|
setIsResizeHandleVisible: ( isVisible: boolean ) => void;
|
2023-09-19 03:37:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach( () => {
|
|
|
|
props = {
|
|
|
|
onClose: jest.fn(),
|
2023-12-21 15:56:22 +00:00
|
|
|
skipTour: jest.fn(),
|
|
|
|
takeTour: jest.fn(),
|
2023-09-19 03:37:46 +00:00
|
|
|
setShowWelcomeTour: jest.fn(),
|
|
|
|
showWelcomeTour: true,
|
2023-10-26 10:15:30 +00:00
|
|
|
setIsResizeHandleVisible: jest.fn(),
|
2024-01-11 14:32:16 +00:00
|
|
|
flowType: FlowType.AIOnline,
|
2023-09-19 03:37:46 +00:00
|
|
|
};
|
|
|
|
} );
|
|
|
|
|
2024-01-11 14:32:16 +00:00
|
|
|
it( 'should render welcome tour mentioning the AI when the flowType is AIOnline', () => {
|
2023-09-19 03:37:46 +00:00
|
|
|
render( <OnboardingTour { ...props } /> );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText( /Welcome to your AI-generated store!/i )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
2024-01-11 14:32:16 +00:00
|
|
|
it( 'should render welcome tour not mentioning the AI when the flowType is AIOnline', () => {
|
|
|
|
render( <OnboardingTour { ...props } flowType={ FlowType.noAI } /> );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
/Discover what's possible with the store designer/i
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
2023-09-19 03:37:46 +00:00
|
|
|
it( 'should render step 1', () => {
|
|
|
|
render( <OnboardingTour { ...props } showWelcomeTour={ false } /> );
|
|
|
|
|
|
|
|
expect(
|
|
|
|
screen.getByText( /View your changes in real time/i )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should record an event when clicking on "Take a tour" button', () => {
|
|
|
|
render( <OnboardingTour { ...props } /> );
|
|
|
|
|
|
|
|
screen
|
|
|
|
.getByRole( 'button', {
|
|
|
|
name: /Take a tour/i,
|
|
|
|
} )
|
|
|
|
.click();
|
|
|
|
|
2023-12-21 15:56:22 +00:00
|
|
|
expect( props.takeTour ).toHaveBeenCalled();
|
2023-09-19 03:37:46 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should record an event when clicking on "Skip" button', () => {
|
|
|
|
render( <OnboardingTour { ...props } /> );
|
|
|
|
|
|
|
|
screen
|
|
|
|
.getByRole( 'button', {
|
|
|
|
name: /Skip/i,
|
|
|
|
} )
|
|
|
|
.click();
|
|
|
|
|
2023-12-21 15:56:22 +00:00
|
|
|
expect( props.skipTour ).toHaveBeenCalled();
|
2023-09-19 03:37:46 +00:00
|
|
|
} );
|
|
|
|
|
2023-12-21 15:56:22 +00:00
|
|
|
it( 'should record an event when clicking on the "Close Tour" button', () => {
|
2023-09-19 03:37:46 +00:00
|
|
|
render( <OnboardingTour { ...props } showWelcomeTour={ false } /> );
|
|
|
|
|
|
|
|
screen
|
|
|
|
.getByRole( 'button', {
|
|
|
|
name: 'Close Tour',
|
|
|
|
} )
|
|
|
|
.click();
|
|
|
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith(
|
|
|
|
'customize_your_store_assembler_hub_tour_close'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should record an event when complete the tour', () => {
|
|
|
|
render( <OnboardingTour { ...props } showWelcomeTour={ false } /> );
|
|
|
|
|
|
|
|
screen
|
|
|
|
.getByRole( 'button', {
|
|
|
|
name: 'Next',
|
|
|
|
} )
|
|
|
|
.click();
|
|
|
|
|
|
|
|
screen
|
|
|
|
.getByRole( 'button', {
|
|
|
|
name: 'Done',
|
|
|
|
} )
|
|
|
|
.click();
|
|
|
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith(
|
|
|
|
'customize_your_store_assembler_hub_tour_complete'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
} );
|