2023-10-04 12:24:51 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import React from 'react';
|
|
|
|
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
|
|
|
import '@testing-library/jest-dom/extend-expect';
|
|
|
|
import { AnyInterpreter } from 'xstate';
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { Intro } from '../';
|
|
|
|
|
|
|
|
jest.mock( '../../assembler-hub/site-hub', () => ( {
|
|
|
|
SiteHub: jest.fn( () => null ),
|
|
|
|
} ) );
|
|
|
|
jest.mock( '~/utils/react-hooks/use-network-status', () => ( {
|
|
|
|
useNetworkStatus: jest.fn(),
|
|
|
|
} ) );
|
|
|
|
describe( 'Intro Modals', () => {
|
|
|
|
it( 'should display DesignChangeWarningModal when activeThemeHasMods and button is clicked', async () => {
|
|
|
|
const sendEventMock = jest.fn();
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ sendEventMock }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
|
|
|
activeTheme: '',
|
2023-10-05 13:33:50 +00:00
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2023-10-04 12:24:51 +00:00
|
|
|
activeThemeHasMods: true,
|
|
|
|
customizeStoreTaskCompleted: false,
|
|
|
|
currentThemeIsAiGenerated: false,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
|
|
|
} }
|
2023-10-05 13:33:50 +00:00
|
|
|
currentState={ 'intro' }
|
2023-10-04 12:24:51 +00:00
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const bannerButton = screen.getByRole( 'button', {
|
|
|
|
name: /Design with AI/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( bannerButton );
|
|
|
|
|
|
|
|
await waitFor( () => {
|
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
/Are you sure you want to start a new design?/i
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
const modalButton = screen.getByRole( 'button', {
|
|
|
|
name: /Design with AI/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( modalButton );
|
|
|
|
|
|
|
|
expect( sendEventMock ).toHaveBeenCalledWith( {
|
|
|
|
type: 'DESIGN_WITH_AI',
|
|
|
|
} );
|
|
|
|
} );
|
2023-10-09 05:19:08 +00:00
|
|
|
|
|
|
|
it( 'should display StartOverWarningModal when customizeStoreTaskCompleted and currentThemeIsAiGenerated and button is clicked', async () => {
|
|
|
|
const sendEventMock = jest.fn();
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ sendEventMock }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
|
|
|
activeTheme: '',
|
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeThemeHasMods: false,
|
|
|
|
customizeStoreTaskCompleted: true,
|
|
|
|
currentThemeIsAiGenerated: true,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
|
|
|
} }
|
|
|
|
currentState={ 'intro' }
|
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const bannerButton = screen.getByRole( 'button', {
|
|
|
|
name: /Create a new one/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( bannerButton );
|
|
|
|
|
|
|
|
await waitFor( () => {
|
|
|
|
expect(
|
|
|
|
screen.getByText( /Are you sure you want to start over?/i )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
const modalButton = screen.getByRole( 'button', {
|
|
|
|
name: /Start again/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( modalButton );
|
|
|
|
|
|
|
|
expect( sendEventMock ).toHaveBeenCalledWith( {
|
|
|
|
type: 'DESIGN_WITH_AI',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should display StartNewDesignWarningModal when customizeStoreTaskCompleted and not currentThemeIsAiGenerated and button is clicked', async () => {
|
|
|
|
const sendEventMock = jest.fn();
|
|
|
|
render(
|
|
|
|
<Intro
|
|
|
|
sendEvent={ sendEventMock }
|
|
|
|
context={ {
|
|
|
|
intro: {
|
|
|
|
hasErrors: false,
|
|
|
|
activeTheme: '',
|
|
|
|
themeData: {
|
|
|
|
themes: [],
|
|
|
|
_links: {
|
|
|
|
browse_all: {
|
|
|
|
href: '',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
activeThemeHasMods: false,
|
|
|
|
customizeStoreTaskCompleted: true,
|
|
|
|
currentThemeIsAiGenerated: false,
|
|
|
|
},
|
|
|
|
themeConfiguration: {},
|
|
|
|
} }
|
|
|
|
currentState={ 'intro' }
|
|
|
|
parentMachine={ null as unknown as AnyInterpreter }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const bannerButton = screen.getByRole( 'button', {
|
|
|
|
name: /Design with AI/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( bannerButton );
|
|
|
|
|
|
|
|
await waitFor( () => {
|
|
|
|
expect(
|
|
|
|
screen.getByText(
|
|
|
|
/Are you sure you want to start a new design?/i
|
|
|
|
)
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
const modalButton = screen.getByRole( 'button', {
|
|
|
|
name: /Design with AI/i,
|
|
|
|
} );
|
|
|
|
fireEvent.click( modalButton );
|
|
|
|
|
|
|
|
expect( sendEventMock ).toHaveBeenCalledWith( {
|
|
|
|
type: 'DESIGN_WITH_AI',
|
|
|
|
} );
|
|
|
|
} );
|
2023-10-04 12:24:51 +00:00
|
|
|
} );
|