2020-09-11 06:09:17 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2020-11-06 17:53:03 +00:00
|
|
|
import { act, render, findByText, queryByTestId } from '@testing-library/react';
|
2020-09-11 06:09:17 +00:00
|
|
|
import apiFetch from '@wordpress/api-fetch';
|
2020-11-06 17:53:03 +00:00
|
|
|
import userEvent from '@testing-library/user-event';
|
2020-09-11 06:09:17 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-11-06 17:53:03 +00:00
|
|
|
import { TaskDashboard } from '../index.js';
|
2020-12-03 21:16:04 +00:00
|
|
|
import { TaskList } from '../list';
|
2020-11-06 17:53:03 +00:00
|
|
|
import { getAllTasks } from '../tasks';
|
2020-09-11 06:09:17 +00:00
|
|
|
|
|
|
|
jest.mock( '@wordpress/api-fetch' );
|
2020-11-06 17:53:03 +00:00
|
|
|
jest.mock( '../tasks' );
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
describe( 'TaskDashboard and TaskList', () => {
|
2020-11-06 17:53:03 +00:00
|
|
|
afterEach( () => jest.clearAllMocks() );
|
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
const tasks = [
|
|
|
|
{
|
|
|
|
key: 'optional',
|
|
|
|
title: 'This task is optional',
|
|
|
|
container: null,
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
key: 'extension',
|
|
|
|
title: 'This task is an extension',
|
|
|
|
container: null,
|
|
|
|
completed: false,
|
|
|
|
visible: true,
|
|
|
|
time: '1 minute',
|
|
|
|
isDismissable: true,
|
|
|
|
type: 'extension',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
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',
|
|
|
|
},
|
|
|
|
];
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
it( 'renders the "Finish setup" and "Extensions setup" tasks lists', async () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
2020-11-06 17:53:03 +00:00
|
|
|
const { container } = render(
|
|
|
|
<TaskDashboard
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
2020-09-11 06:09:17 +00:00
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
// Wait for the setup task list to render.
|
2020-09-11 06:09:17 +00:00
|
|
|
expect( await findByText( container, 'Finish setup' ) ).toBeDefined();
|
|
|
|
|
2020-12-03 21:16:04 +00:00
|
|
|
// Wait for the extension task list to render.
|
|
|
|
expect(
|
|
|
|
await findByText( container, 'Extensions setup' )
|
|
|
|
).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'renders a dismiss button for tasks that are optional and incomplete', async () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
getAllTasks.mockReturnValue( tasks );
|
|
|
|
const { container } = render(
|
|
|
|
<TaskDashboard
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
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
|
|
|
|
|
|
|
it( 'sets homescreen layout default when dismissed', () => {
|
|
|
|
const updateOptions = jest.fn();
|
|
|
|
const { getByRole } = render(
|
2020-12-03 21:16:04 +00:00
|
|
|
<TaskList
|
2020-11-06 17:53:03 +00:00
|
|
|
dismissedTasks={ [] }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
2020-12-03 21:16:04 +00:00
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2020-11-06 17:53:03 +00:00
|
|
|
updateOptions={ updateOptions }
|
2020-12-03 21:16:04 +00:00
|
|
|
allTasks={ shorterTasksList }
|
|
|
|
specificTasks={ 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( {} );
|
|
|
|
const updateOptions = jest.fn();
|
|
|
|
act( () => {
|
|
|
|
render(
|
2020-12-03 21:16:04 +00:00
|
|
|
<TaskList
|
2020-11-06 17:53:03 +00:00
|
|
|
dismissedTasks={ [] }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
2020-12-03 21:16:04 +00:00
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
2020-11-06 17:53:03 +00:00
|
|
|
updateOptions={ updateOptions }
|
2020-12-03 21:16:04 +00:00
|
|
|
allTasks={ shorterTasksList }
|
|
|
|
specificTasks={ 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
|
|
|
|
|
|
|
it( 'sets extended tasks list as completed', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const updateOptions = jest.fn();
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isExtended={ true }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
|
|
|
updateOptions={ updateOptions }
|
|
|
|
allTasks={ shorterTasksList }
|
|
|
|
specificTasks={ shorterTasksList }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_extended_task_list_complete: 'yes',
|
|
|
|
} );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'Add untracked completed task', () => {
|
|
|
|
apiFetch.mockResolvedValue( {} );
|
|
|
|
const updateOptions = jest.fn();
|
|
|
|
act( () => {
|
|
|
|
render(
|
|
|
|
<TaskList
|
|
|
|
allTasks={ tasks }
|
|
|
|
dismissedTasks={ [] }
|
|
|
|
isTaskListComplete={ true }
|
|
|
|
profileItems={ {} }
|
|
|
|
query={ {} }
|
|
|
|
trackedCompletedTasks={ shorterTasksList }
|
|
|
|
updateOptions={ updateOptions }
|
|
|
|
specificTasks={ shorterTasksList }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} );
|
|
|
|
|
|
|
|
expect( updateOptions ).toHaveBeenCalledWith( {
|
|
|
|
woocommerce_task_list_tracked_completed_tasks: [ 'completed' ],
|
|
|
|
} );
|
|
|
|
} );
|
2020-09-11 06:09:17 +00:00
|
|
|
} );
|