woocommerce/plugins/woocommerce-admin/client/task-lists/progress-title/test/default-progress-title.test...

111 lines
3.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { DefaultProgressTitle } from '../default-progress-title';
jest.mock( '@wordpress/data', () => ( {
...jest.requireActual( '@wordpress/data' ),
useSelect: jest.fn(),
} ) );
describe( 'default-progress-title', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [],
} ),
hasFinishedResolution: () => true,
} ) )
);
it( 'should render "Welcome to your store" when no tasks are completed and visited', () => {
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Welcome to your store' )
).toBeInTheDocument();
} );
it( 'should render "Welcome to your store" when all tasks are completed', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Welcome to your store' )
).toBeInTheDocument();
} );
it( 'should render "Lets get you started" when has task visited and task completed count <= 3', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [ { isVisited: true, isComplete: false } ],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Lets get you started', { exact: false } )
).toBeInTheDocument();
} );
it( 'should render "Youre on the right track" when has task visited and task completed count > 3', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: false },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Youre on the right track', { exact: false } )
).toBeInTheDocument();
} );
it( 'should render "Youre almost there" when has task visited and task completed count > 5', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: false },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Youre almost there', { exact: false } )
).toBeInTheDocument();
} );
} );