2023-10-04 12:24:51 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import { render, screen, fireEvent } from '@testing-library/react';
|
|
|
|
import '@testing-library/jest-dom/extend-expect';
|
|
|
|
import { AnyInterpreter } from 'xstate';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Intro } from '../';
|
|
|
|
import { useNetworkStatus } from '~/utils/react-hooks/use-network-status';
|
2024-01-09 14:49:59 +00:00
|
|
|
import { FlowType } from '~/customize-store/types';
|
2023-10-04 12:24:51 +00:00
|
|
|
|
|
|
|
jest.mock( '../../assembler-hub/site-hub', () => ( {
|
|
|
|
SiteHub: jest.fn( () => null ),
|
|
|
|
} ) );
|
|
|
|
jest.mock( '~/utils/react-hooks/use-network-status', () => ( {
|
|
|
|
useNetworkStatus: jest.fn(),
|
|
|
|
} ) );
|
2024-07-24 10:07:42 +00:00
|
|
|
|
|
|
|
jest.mock( '@wordpress/data', () => {
|
|
|
|
const originalModule = jest.requireActual( '@wordpress/data' );
|
|
|
|
return {
|
|
|
|
...originalModule,
|
|
|
|
useSelect: jest.fn( () => ( {
|
|
|
|
is_block_theme: true,
|
|
|
|
} ) ),
|
|
|
|
};
|
|
|
|
} );
|
2023-10-04 12:24:51 +00:00
|
|
|
describe( 'Intro Banners', () => {
|
|
|
|
it( 'should display NetworkOfflineBanner when network is offline', () => {
|
|
|
|
( useNetworkStatus as jest.Mock ).mockImplementation( () => true );
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ jest.fn() }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
2024-08-02 15:50:13 +00:00
|
|
|
errorStatus: undefined,
|
2023-10-04 12:24:51 +00:00
|
|
|
activeTheme: '',
|
2023-10-05 13:33:50 +00:00
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-10-04 12:24:51 +00:00
|
|
|
customizeStoreTaskCompleted: false,
|
|
|
|
currentThemeIsAiGenerated: false,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
2023-11-10 08:35:46 +00:00
|
|
|
transitionalScreen: {
|
|
|
|
hasCompleteSurvey: false,
|
|
|
|
},
|
2024-01-09 14:49:59 +00:00
|
|
|
flowType: FlowType.AIOnline,
|
2024-02-01 11:30:50 +00:00
|
|
|
isFontLibraryAvailable: false,
|
2024-06-05 13:09:35 +00:00
|
|
|
isPTKPatternsAPIAvailable: false,
|
2024-02-05 11:36:33 +00:00
|
|
|
activeThemeHasMods: false,
|
2023-10-04 12:24:51 +00:00
|
|
|
} }
|
2023-10-05 13:33:50 +00:00
|
|
|
currentState={ 'intro' }
|
2023-10-04 12:24:51 +00:00
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect(
|
2023-10-12 02:49:25 +00:00
|
|
|
screen.getByText( /Please check your internet connection./i )
|
2023-10-04 12:24:51 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should display the default banner by default', () => {
|
|
|
|
const sendEventMock = jest.fn();
|
|
|
|
( useNetworkStatus as jest.Mock ).mockImplementation( () => false );
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ sendEventMock }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
2024-08-02 15:50:13 +00:00
|
|
|
errorStatus: undefined,
|
2023-10-04 12:24:51 +00:00
|
|
|
activeTheme: '',
|
2023-10-05 13:33:50 +00:00
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-10-04 12:24:51 +00:00
|
|
|
customizeStoreTaskCompleted: false,
|
|
|
|
currentThemeIsAiGenerated: false,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
2023-11-10 08:35:46 +00:00
|
|
|
transitionalScreen: {
|
|
|
|
hasCompleteSurvey: false,
|
|
|
|
},
|
2024-01-09 14:49:59 +00:00
|
|
|
flowType: FlowType.AIOnline,
|
2024-02-01 11:30:50 +00:00
|
|
|
isFontLibraryAvailable: false,
|
2024-06-05 13:09:35 +00:00
|
|
|
isPTKPatternsAPIAvailable: false,
|
2024-02-05 11:36:33 +00:00
|
|
|
activeThemeHasMods: false,
|
2023-10-04 12:24:51 +00:00
|
|
|
} }
|
2023-10-05 13:33:50 +00:00
|
|
|
currentState={ 'intro' }
|
2023-10-04 12:24:51 +00:00
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
screen.getByText( /Use the power of AI to design your store/i )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
const button = screen.getByRole( 'button', {
|
|
|
|
name: /Design with AI/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( button );
|
|
|
|
expect( sendEventMock ).toHaveBeenCalledWith( {
|
|
|
|
type: 'DESIGN_WITH_AI',
|
|
|
|
} );
|
|
|
|
} );
|
2023-10-09 05:19:08 +00:00
|
|
|
|
|
|
|
it( 'should display the existing ai theme banner when customizeStoreTaskCompleted and currentThemeIsAiGenerated', () => {
|
|
|
|
const sendEventMock = jest.fn();
|
|
|
|
( useNetworkStatus as jest.Mock ).mockImplementation( () => false );
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ sendEventMock }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
2024-08-02 15:50:13 +00:00
|
|
|
errorStatus: undefined,
|
2023-10-09 05:19:08 +00:00
|
|
|
activeTheme: '',
|
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
customizeStoreTaskCompleted: true,
|
|
|
|
currentThemeIsAiGenerated: true,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
2023-11-10 08:35:46 +00:00
|
|
|
transitionalScreen: {
|
|
|
|
hasCompleteSurvey: false,
|
|
|
|
},
|
2024-01-09 14:49:59 +00:00
|
|
|
flowType: FlowType.AIOnline,
|
2024-02-01 11:30:50 +00:00
|
|
|
isFontLibraryAvailable: false,
|
2024-06-05 13:09:35 +00:00
|
|
|
isPTKPatternsAPIAvailable: false,
|
2024-02-05 11:36:33 +00:00
|
|
|
activeThemeHasMods: false,
|
2023-10-09 05:19:08 +00:00
|
|
|
} }
|
|
|
|
currentState={ 'intro' }
|
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
expect(
|
|
|
|
screen.getByText( /Customize your custom theme/i )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
2023-10-04 12:24:51 +00:00
|
|
|
} );
|