2020-09-11 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-01-27 18:40:02 +00:00
|
|
|
import {
|
|
|
|
act,
|
|
|
|
render,
|
|
|
|
findByText,
|
|
|
|
fireEvent,
|
|
|
|
queryByTestId,
|
|
|
|
} from '@testing-library/react';
|
2020-11-06 17:53:03 +00:00
|
|
|
import userEvent from '@testing-library/user-event';
|
2021-04-16 13:29:54 +00:00
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
|
|
|
import { SlotFillProvider } from '@wordpress/components';
|
|
|
|
import { recordEvent } from '@woocommerce/tracks';
|
2021-04-27 15:23:34 +00:00
|
|
|
import { useDispatch, useSelect } from '@wordpress/data';
|
2020-09-11 06:09:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2021-04-27 15:23:34 +00:00
|
|
|
import TaskDashboard from '../';
|
2021-05-03 17:13:47 +00:00
|
|
|
import { TaskList } from '../task-list';
|
2020-11-06 17:53:03 +00:00
|
|
|
import { getAllTasks } from '../tasks';
|
2021-04-16 13:29:54 +00:00
|
|
|
import { DisplayOption } from '../../header/activity-panel/display-options';
|
2020-09-11 06:09:17 +00:00
|
|
|
|
|
|
|
jest.mock( '@wordpress/api-fetch' );
|
2021-04-27 15:23:34 +00:00
|
|
|
jest.mock( '../tasks', () => ( {
|
2021-05-05 17:43:46 +00:00
|
|
|
...jest.requireActual( '../tasks' ),
|
2021-04-27 15:23:34 +00:00
|
|
|
recordTaskViewEvent: jest.fn(),
|
|
|
|
getAllTasks: jest.fn(),
|
|
|
|
} ) );
|
|
|
|
jest.mock( '../../dashboard/components/cart-modal', () => null );
|
2021-04-16 13:29:54 +00:00
|
|
|
jest.mock( '@woocommerce/tracks', () => ( { recordEvent: jest.fn() } ) );
|
2021-04-27 15:23:34 +00:00
|
|
|
jest.mock( '@woocommerce/data', () => ( {} ) );
|
|
|
|
jest.mock( '@wordpress/data', () => ( {
|
|
|
|
...jest.requireActual( '@wordpress/data' ),
|
|
|
|
useSelect: jest.fn().mockReturnValue( {
|
|
|
|
profileItems: {},
|
|
|
|
} ),
|
|
|
|
useDispatch: jest.fn(),
|
|
|
|
} ) );
|
2021-04-16 13:29:54 +00:00
|
|
|
|
|
|
|
const TASK_LIST_HEADING = 'Get ready to start selling';
|
|
|
|
const EXTENDED_TASK_LIST_HEADING = 'Things to do next';
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
describe( 'TaskDashboard and TaskList', () => {
|
2021-04-27 15:23:34 +00:00
|
|
|
const updateOptions = jest.fn();
|
|
|
|
const createNotice = jest.fn();
|
|
|
|
beforeEach( () => {
|
|
|
|
useDispatch.mockImplementation( () => ( {
|
|
|
|
updateOptions,
|
|
|
|
createNotice,
|
|
|
|
installAndActivatePlugins: jest.fn(),
|
|
|
|
} ) );
|
|
|
|
} );
|
2020-11-06 17:53:03 +00:00
|
|
|
afterEach( () => jest.clearAllMocks() );
|
2021-01-14 16:59:31 +00:00
|
|
|
const MockTask = () => {
|
|
|
|
return <div>mock task</div>;
|
|
|
|
};
|
2020-12-11 02:29:45 +00:00
|
|
|
const tasks = {
|
|
|
|
setup: [
|
|
|
|
{
|
|
|
|
key: 'optional',
|
|
|
|
title: 'This task is optional',
|
2021-01-14 16:59:31 +00:00
|
|
|
container: <MockTask />,
|
2020-12-11 02:29:45 +00:00
|
|
|
completed: false,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'setup',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'required',
|
|
|
|
title: 'This task is required',
|
|
|
|
container: null,
|
|
|
|
completed: false,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: false,
|
|
|
|
type: 'setup',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'completed',
|
|
|
|
title: 'This task is completed',
|
|
|
|
container: null,
|
|
|
|
completed: true,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'setup',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
extension: [
|
|
|
|
{
|
|
|
|
key: 'extension',
|
|
|
|
title: 'This task is an extension',
|
|
|
|
container: null,
|
|
|
|
completed: false,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'extension',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
};
|
2020-12-03 21:16:04 +00:00
|
|
|
const shorterTasksList = [
|
|
|
|
{
|
|
|
|
key: 'completed-1',
|
|
|
|
title: 'This task is completed',
|
|
|
|
container: null,
|
|
|
|
completed: true,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'setup',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'completed-2',
|
|
|
|
title: 'This task is completed',
|
|
|
|
container: null,
|
|
|
|
completed: true,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'setup',
|
|
|
|
},
|
|
|
|
];
|
2021-01-27 18:40:02 +00:00
|
|
|
const notVisibleTask = {
|
|
|
|
key: 'not-visible',
|
|
|
|
title: 'This task is not visible',
|
|
|
|
container: <MockTask />,
|
|
|
|
completed: false,
|
|
|
|
visible: false,
|
|
|
|
time: '2 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
};
|
2021-04-16 13:29:54 +00:00
|
|
|
const completedExtensionTask = {
|
|
|
|
key: 'extension2',
|
|
|
|
title: 'This completed task is an extension',
|
|
|
|
container: null,
|
|
|
|
completed: true,
|
|
|
|
visible: true,
|
|
|
|
time: '2 minutes',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'extension',
|
|
|
|
};
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
it( 'renders the "Get ready to start selling" and "Things to do next" tasks lists', async () => {
|
2020-12-03 21:16:04 +00:00
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
2021-04-27 15:23:34 +00:00
|
|
|
const { container } = render( <TaskDashboard query={ {} } /> );
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
// Wait for the setup task list to render.
|
2021-02-10 23:57:51 +00:00
|
|
|
expect(
|
2021-04-16 13:29:54 +00:00
|
|
|
await findByText( container, TASK_LIST_HEADING )
|
2021-02-10 23:57:51 +00:00
|
|
|
).toBeDefined();
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
// Wait for the extension task list to render.
|
|
|
|
expect(
|
2021-04-16 13:29:54 +00:00
|
|
|
await findByText( container, EXTENDED_TASK_LIST_HEADING )
|
2020-12-03 21:16:04 +00:00
|
|
|
).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'renders a dismiss button for tasks that are optional and incomplete', async () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
2021-04-27 15:23:34 +00:00
|
|
|
const { container } = render( <TaskDashboard query={ {} } /> );
|
2020-12-03 21:16:04 +00:00
|
|
|
|
2020-09-11 06:09:17 +00:00
|
|
|
// The `optional` task has a dismiss button.
|
|
|
|
expect(
|
|
|
|
queryByTestId( container, 'optional-dismiss-button' )
|
|
|
|
).toBeDefined();
|
|
|
|
|
|
|
|
// The `required` task does not have a dismiss button.
|
|
|
|
expect(
|
|
|
|
queryByTestId( container, 'required-dismiss-button' )
|
|
|
|
).toBeNull();
|
|
|
|
|
|
|
|
// The `completed` task does not have a dismiss button.
|
|
|
|
expect(
|
|
|
|
queryByTestId( container, 'completed-dismiss-button' )
|
|
|
|
).toBeNull();
|
|
|
|
} );
|
2020-11-06 17:53:03 +00:00
|
|
|
|
2021-01-14 16:59:31 +00:00
|
|
|
it( 'renders the selected task', async () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
|
|
|
const { container } = render(
|
2021-04-27 15:23:34 +00:00
|
|
|
<TaskDashboard query={ { task: 'optional' } } />
|
2021-01-14 16:59:31 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
// Wait for the task to render.
|
|
|
|
expect( await findByText( container, 'mock task' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'renders only the extended task list', () => {
|
2021-04-27 15:23:34 +00:00
|
|
|
useSelect.mockImplementation( () => ( {
|
|
|
|
dismissedTasks: [],
|
|
|
|
isSetupTaskListHidden: true,
|
|
|
|
profileItems: {},
|
|
|
|
} ) );
|
2021-01-14 16:59:31 +00:00
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
2021-04-27 15:23:34 +00:00
|
|
|
const { queryByText } = render( <TaskDashboard query={ {} } /> );
|
2021-01-14 16:59:31 +00:00
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
expect( queryByText( TASK_LIST_HEADING ) ).toBeNull();
|
2021-01-14 16:59:31 +00:00
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
expect( queryByText( EXTENDED_TASK_LIST_HEADING ) ).not.toBeNull();
|
2021-01-14 16:59:31 +00:00
|
|
|
} );
|
|
|
|
|
2021-05-03 17:13:47 +00:00
|
|
|
it( 'renders only the extended task list with expansion', () => {
|
|
|
|
useSelect.mockImplementation( () => ( {
|
|
|
|
dismissedTasks: [],
|
|
|
|
isSetupTaskListHidden: true,
|
|
|
|
profileItems: {},
|
|
|
|
} ) );
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( {
|
|
|
|
setup: [],
|
|
|
|
extension: [ ...tasks.setup, ...tasks.extension ],
|
|
|
|
} );
|
|
|
|
const { queryByText } = render( <TaskDashboard query={ {} } /> );
|
|
|
|
|
|
|
|
expect( queryByText( TASK_LIST_HEADING ) ).toBeNull();
|
|
|
|
|
|
|
|
expect( queryByText( EXTENDED_TASK_LIST_HEADING ) ).not.toBeNull();
|
|
|
|
const taskLength = tasks.setup.length + tasks.extension.length;
|
|
|
|
expect(
|
|
|
|
queryByText( `Show ${ taskLength - 2 } more tasks.` )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
it( 'sets homescreen layout default when dismissed', () => {
|
|
|
|
const { getByRole } = render(
|
2020-12-03 21:16:04 +00:00
|
|
|
<TaskList
|
2020-11-06 17:53:03 +00:00
|
|
|
query={ {} }
|
2021-04-27 15:23:34 +00:00
|
|
|
dismissedTasks={ [] }
|
2020-12-03 21:16:04 +00:00
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ shorterTasksList }
|
2020-11-06 17:53:03 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
userEvent.click( getByRole( 'button', { name: 'Task List Options' } ) );
|
|
|
|
userEvent.click( getByRole( 'button', { name: 'Hide this' } ) );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_hidden: 'yes',
|
|
|
|
woocommerce_task_list_prompt_shown: true,
|
|
|
|
woocommerce_default_homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets homescreen layout default when completed', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
act( () => {
|
|
|
|
render(
|
2020-12-03 21:16:04 +00:00
|
|
|
<TaskList
|
2020-11-06 17:53:03 +00:00
|
|
|
query={ {} }
|
2021-04-27 15:23:34 +00:00
|
|
|
dismissedTasks={ [] }
|
2020-12-03 21:16:04 +00:00
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ shorterTasksList }
|
2020-11-06 17:53:03 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_complete: 'yes',
|
|
|
|
woocommerce_default_homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
} );
|
2020-12-03 21:16:04 +00:00
|
|
|
|
2021-01-27 18:40:02 +00:00
|
|
|
it( 'hides the setup task list if there are no visible tasks', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { setup } = tasks;
|
|
|
|
const { queryByText } = render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [ 'optional', 'required', 'completed' ] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ [ ...setup, notVisibleTask ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
expect( queryByText( TASK_LIST_HEADING ) ).toBeNull();
|
2021-01-27 18:40:02 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'hides the extended task list if there are no visible tasks', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { extension } = tasks;
|
|
|
|
const { queryByText } = render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [ 'extension' ] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ [ ...extension, notVisibleTask ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-04-16 13:29:54 +00:00
|
|
|
expect( queryByText( EXTENDED_TASK_LIST_HEADING ) ).toBeNull();
|
2021-01-27 18:40:02 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets setup tasks list as completed', () => {
|
2020-12-03 21:16:04 +00:00
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
2021-01-27 18:40:02 +00:00
|
|
|
isComplete={ false }
|
2020-12-03 21:16:04 +00:00
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ shorterTasksList }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_complete: 'yes',
|
|
|
|
woocommerce_default_homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets extended tasks list as completed', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ shorterTasksList }
|
|
|
|
name={ 'extended_task_list' }
|
2020-12-03 21:16:04 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_extended_task_list_complete: 'yes',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
2021-01-27 18:40:02 +00:00
|
|
|
it( 'sets setup tasks list (with only dismissed tasks) as completed', () => {
|
2020-12-03 21:16:04 +00:00
|
|
|
apiFetch.mockResolvedValue( {} );
|
2021-01-27 18:40:02 +00:00
|
|
|
const { setup } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [ 'optional', 'required', 'completed' ] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ setup }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_complete: 'yes',
|
|
|
|
woocommerce_default_homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets extended tasks list (with only dismissed tasks) as completed', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { extension } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [ 'extension' ] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ extension }
|
|
|
|
name={ 'extended_task_list' }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_extended_task_list_complete: 'yes',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets setup tasks list as incomplete', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { setup } = tasks;
|
2020-12-03 21:16:04 +00:00
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
2021-01-27 18:40:02 +00:00
|
|
|
isComplete={ true }
|
2020-12-03 21:16:04 +00:00
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2021-01-27 18:40:02 +00:00
|
|
|
tasks={ [ ...setup ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_complete: 'no',
|
|
|
|
woocommerce_default_homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'sets extended tasks list as incomplete', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { extension } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isComplete={ true }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
|
|
|
tasks={ extension }
|
|
|
|
name={ 'extended_task_list' }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_extended_task_list_complete: 'no',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'adds an untracked completed task', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { setup, extension } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ [ ...setup, ...extension ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_tracked_completed_tasks: [ 'completed' ],
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'removes an incomplete but already tracked task from tracked tasks list', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { setup, extension } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [ 'completed', 'extension' ] }
|
|
|
|
tasks={ [ ...setup, ...extension ] }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_tracked_completed_tasks: [ 'completed' ],
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'adds an untracked completed task and removes an incomplete but already tracked task from tracked tasks list', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { setup, extension } = tasks;
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [ 'extension' ] }
|
|
|
|
tasks={ [ ...setup, ...extension ] }
|
2020-12-03 21:16:04 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_tracked_completed_tasks: [ 'completed' ],
|
|
|
|
} );
|
|
|
|
} );
|
2021-01-27 18:40:02 +00:00
|
|
|
|
|
|
|
it( 'does not add untracked completed (but dismissed) tasks', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [ 'completed-1' ] }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ shorterTasksList }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_tracked_completed_tasks: [ 'completed-2' ],
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'dismisses a task', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const { extension } = tasks;
|
|
|
|
const { getByText } = render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ extension }
|
|
|
|
name={ 'extended_task_list' }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.click( getByText( 'Dismiss' ) );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_dismissed_tasks: [ 'extension' ],
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'calls the "onDismiss" callback after dismissing a task', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const callback = jest.fn();
|
|
|
|
const { extension } = tasks;
|
|
|
|
extension[ 0 ].onDismiss = callback;
|
|
|
|
const { getByText } = render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isComplete={ false }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
tasks={ extension }
|
|
|
|
name={ 'extended_task_list' }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
fireEvent.click( getByText( 'Dismiss' ) );
|
|
|
|
expect( callback ).toHaveBeenCalledWith();
|
|
|
|
} );
|
2021-04-16 13:29:54 +00:00
|
|
|
|
|
|
|
it( 'sorts the extended task list tasks by completion status', () => {
|
2021-04-27 15:23:34 +00:00
|
|
|
useSelect.mockImplementation( () => ( {
|
|
|
|
dismissedTasks: [],
|
|
|
|
isSetupTaskListHidden: true,
|
|
|
|
profileItems: {},
|
|
|
|
} ) );
|
2021-04-16 13:29:54 +00:00
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( {
|
|
|
|
extension: [ completedExtensionTask, ...tasks.extension ],
|
|
|
|
} );
|
2021-04-27 15:23:34 +00:00
|
|
|
const { queryByText, container } = render(
|
|
|
|
<TaskDashboard query={ {} } />
|
2021-04-16 13:29:54 +00:00
|
|
|
);
|
|
|
|
|
2021-04-27 15:23:34 +00:00
|
|
|
const visibleTasks = container.querySelectorAll( 'li' );
|
2021-04-16 13:29:54 +00:00
|
|
|
expect( queryByText( EXTENDED_TASK_LIST_HEADING ) ).not.toBeNull();
|
|
|
|
|
|
|
|
expect( visibleTasks ).toHaveLength( 2 );
|
|
|
|
expect( visibleTasks[ 0 ] ).toHaveTextContent(
|
|
|
|
'This task is an extension'
|
|
|
|
);
|
|
|
|
expect( visibleTasks[ 1 ] ).toHaveTextContent(
|
|
|
|
'This completed task is an extension'
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'correctly toggles the extension task list', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<SlotFillProvider>
|
|
|
|
<DisplayOption.Slot />
|
2021-04-27 15:23:34 +00:00
|
|
|
<TaskDashboard query={ {} } />
|
2021-04-16 13:29:54 +00:00
|
|
|
</SlotFillProvider>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Verify the task list is initially shown.
|
|
|
|
expect(
|
|
|
|
getByText( 'Show things to do next', { selector: 'button' } )
|
|
|
|
).toBeChecked();
|
|
|
|
// Toggle it off.
|
|
|
|
fireEvent.click(
|
|
|
|
getByText( 'Show things to do next', { selector: 'button' } )
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( recordEvent ).toHaveBeenCalledWith( 'extended_tasklist_hide' );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_extended_task_list_hidden: 'yes',
|
|
|
|
} );
|
|
|
|
} );
|
2020-09-11 06:09:17 +00:00
|
|
|
} );
|