2020-05-21 17:15:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
2020-10-22 22:13:14 +00:00
|
|
|
import { useUserPreferences } from '@woocommerce/data';
|
2020-08-13 02:05:22 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
2020-05-21 17:15:08 +00:00
|
|
|
import { Layout } from '../layout';
|
|
|
|
|
|
|
|
// Rendering <StatsOverview /> breaks tests.
|
2020-06-15 02:17:12 +00:00
|
|
|
jest.mock( 'homescreen/stats-overview', () =>
|
|
|
|
jest.fn().mockReturnValue( null )
|
|
|
|
);
|
2020-05-21 17:15:08 +00:00
|
|
|
|
|
|
|
// We aren't testing the <TaskList /> component here.
|
|
|
|
jest.mock( 'task-list', () => jest.fn().mockReturnValue( '[TaskList]' ) );
|
|
|
|
|
2020-06-05 16:28:25 +00:00
|
|
|
// We aren't testing the <InboxPanel /> component here.
|
2020-10-06 13:13:32 +00:00
|
|
|
jest.mock( 'inbox-panel', () => jest.fn().mockReturnValue( '[InboxPanel]' ) );
|
2020-06-11 11:55:53 +00:00
|
|
|
|
2020-10-22 22:13:14 +00:00
|
|
|
jest.mock( '@woocommerce/data', () => ( {
|
|
|
|
...jest.requireActual( '@woocommerce/data' ),
|
|
|
|
useUserPreferences: jest.fn().mockReturnValue( {} ),
|
|
|
|
} ) );
|
|
|
|
|
2020-06-15 02:17:12 +00:00
|
|
|
describe( 'Homescreen Layout', () => {
|
2020-05-21 17:15:08 +00:00
|
|
|
it( 'should show TaskList placeholder when loading', () => {
|
|
|
|
const { container } = render(
|
2020-08-17 00:30:46 +00:00
|
|
|
<Layout
|
|
|
|
requestingTaskList
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
2020-05-21 17:15:08 +00:00
|
|
|
);
|
|
|
|
|
2020-06-11 11:55:53 +00:00
|
|
|
const placeholder = container.querySelector(
|
|
|
|
'.woocommerce-task-card.is-loading'
|
|
|
|
);
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( placeholder ).not.toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show TaskList inline', async () => {
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-05-21 17:15:08 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're rendering the "full" home screen (with columns).
|
2020-06-11 11:55:53 +00:00
|
|
|
const columns = container.querySelector(
|
2020-06-15 02:17:12 +00:00
|
|
|
'.woocommerce-homescreen-column'
|
2020-06-11 11:55:53 +00:00
|
|
|
);
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( columns ).not.toBeNull();
|
|
|
|
|
|
|
|
// Expect that the <TaskList /> is there too.
|
2020-06-11 11:55:53 +00:00
|
|
|
const taskList = await screen.findByText( '[TaskList]' );
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( taskList ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should render TaskList alone when on task', async () => {
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {
|
|
|
|
task: 'products',
|
|
|
|
} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-05-21 17:15:08 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're NOT rendering the "full" home screen (with columns).
|
2020-06-11 11:55:53 +00:00
|
|
|
const columns = container.querySelector(
|
2020-06-15 02:17:12 +00:00
|
|
|
'.woocommerce-homescreen-column'
|
2020-06-11 11:55:53 +00:00
|
|
|
);
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( columns ).toBeNull();
|
|
|
|
|
|
|
|
// Expect that the <TaskList /> is there though.
|
2020-06-11 11:55:53 +00:00
|
|
|
const taskList = await screen.findByText( '[TaskList]' );
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( taskList ).toBeDefined();
|
|
|
|
} );
|
2020-05-27 16:08:39 +00:00
|
|
|
|
|
|
|
it( 'should not show TaskList when user has hidden', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden
|
|
|
|
query={ {} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-05-27 16:08:39 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-06-11 11:55:53 +00:00
|
|
|
const taskList = screen.queryByText( '[TaskList]' );
|
2020-05-27 16:08:39 +00:00
|
|
|
expect( taskList ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not show TaskList when it is complete', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListComplete
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-05-27 16:08:39 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-06-11 11:55:53 +00:00
|
|
|
const taskList = screen.queryByText( '[TaskList]' );
|
2020-05-27 16:08:39 +00:00
|
|
|
expect( taskList ).toBeNull();
|
|
|
|
} );
|
2020-06-11 11:55:53 +00:00
|
|
|
|
|
|
|
it( 'should show QuickLinks when user has hidden TaskList', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden
|
|
|
|
query={ {} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-06-11 11:55:53 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const quickLinks = screen.queryByText( '[QuickLinks]' );
|
|
|
|
expect( quickLinks ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show QuickLinks when TaskList is complete', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListComplete
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-06-11 11:55:53 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const quickLinks = screen.queryByText( '[QuickLinks]' );
|
|
|
|
expect( quickLinks ).toBeDefined();
|
|
|
|
} );
|
2020-10-22 22:13:14 +00:00
|
|
|
|
|
|
|
it( 'should default to two columns', () => {
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: '',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're rendering the two-column home screen.
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen two-columns'
|
|
|
|
)
|
|
|
|
).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'switches to single column layout based on user preference', () => {
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: 'single_column',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're rendering the two-column home screen.
|
|
|
|
const homescreen = container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen'
|
|
|
|
);
|
|
|
|
expect( homescreen ).toHaveLength( 1 );
|
|
|
|
|
|
|
|
expect( homescreen[ 0 ] ).not.toHaveClass( 'two-columns' );
|
|
|
|
} );
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|