2020-05-21 17:15:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
2021-01-28 13:33:36 +00:00
|
|
|
import { render, screen, within } 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', () =>
|
2021-01-28 13:33:36 +00:00
|
|
|
jest.fn().mockReturnValue( '[StatsOverview]' )
|
2020-06-15 02:17:12 +00:00
|
|
|
);
|
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( {} ),
|
|
|
|
} ) );
|
|
|
|
|
2021-01-27 21:40:27 +00:00
|
|
|
// We aren't testing the <ActivityPanel /> component here.
|
|
|
|
jest.mock( '../activity-panel', () => ( {
|
|
|
|
ActivityPanel: jest.fn().mockReturnValue( '[ActivityPanel]' ),
|
|
|
|
} ) );
|
|
|
|
|
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
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-08-17 00:30:46 +00:00
|
|
|
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();
|
|
|
|
} );
|
|
|
|
|
2021-01-27 21:40:27 +00:00
|
|
|
it( 'should show TaskList inline', () => {
|
2020-05-21 17:15:08 +00:00
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-05-21 17:15:08 +00:00
|
|
|
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.
|
2021-01-28 13:33:36 +00:00
|
|
|
const taskList = screen.queryByText( /\[TaskList\]/ );
|
2020-05-21 17:15:08 +00:00
|
|
|
expect( taskList ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
2021-01-27 21:40:27 +00:00
|
|
|
it( 'should render TaskList alone when on task', () => {
|
2020-05-21 17:15:08 +00:00
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-05-21 17:15:08 +00:00
|
|
|
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.
|
2021-01-27 21:40:27 +00:00
|
|
|
const taskList = screen.queryByText( '[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 }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden
|
2020-05-27 16:08:39 +00:00
|
|
|
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 }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden
|
2020-06-11 11:55:53 +00:00
|
|
|
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 }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-06-11 11:55:53 +00:00
|
|
|
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
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
it( 'should default to layout option value', () => {
|
2020-10-22 22:13:14 +00:00
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: '',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
2020-11-06 17:53:03 +00:00
|
|
|
defaultHomescreenLayout="two_columns"
|
2020-10-22 22:13:14 +00:00
|
|
|
requestingTaskList={ false }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-10-22 22:13:14 +00:00
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're rendering the two-column home screen.
|
2020-11-06 17:53:03 +00:00
|
|
|
// The user doesn't have a preference set, but the component received a prop
|
|
|
|
// defaulting to the two column view.
|
2020-10-22 22:13:14 +00:00
|
|
|
expect(
|
|
|
|
container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen two-columns'
|
|
|
|
)
|
|
|
|
).toHaveLength( 1 );
|
|
|
|
} );
|
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
it( 'should falback to single column layout', () => {
|
2020-10-22 22:13:14 +00:00
|
|
|
useUserPreferences.mockReturnValue( {
|
2020-11-06 17:53:03 +00:00
|
|
|
homepage_layout: '',
|
2020-10-22 22:13:14 +00:00
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-10-22 22:13:14 +00:00
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
// Expect that we're rendering the single column home screen.
|
|
|
|
// If a default layout prop isn't specified, the default falls back to single column view.
|
2020-10-22 22:13:14 +00:00
|
|
|
const homescreen = container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen'
|
|
|
|
);
|
|
|
|
expect( homescreen ).toHaveLength( 1 );
|
|
|
|
|
|
|
|
expect( homescreen[ 0 ] ).not.toHaveClass( 'two-columns' );
|
|
|
|
} );
|
2020-11-06 17:53:03 +00:00
|
|
|
|
|
|
|
it( 'switches to two column layout based on user preference', () => {
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-01-27 18:40:02 +00:00
|
|
|
bothTaskListsHidden={ false }
|
2020-11-06 17:53:03 +00:00
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that we're rendering the two-column home screen.
|
|
|
|
expect(
|
|
|
|
container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen two-columns'
|
|
|
|
)
|
|
|
|
).toHaveLength( 1 );
|
|
|
|
} );
|
2021-01-28 13:33:36 +00:00
|
|
|
|
|
|
|
it( 'should display the correct blocks in each column', () => {
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
bothTaskListsHidden={ false }
|
|
|
|
query={ {} }
|
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const columns = container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen-column'
|
|
|
|
);
|
|
|
|
expect( columns ).toHaveLength( 2 );
|
|
|
|
const firstColumn = columns[ 0 ];
|
|
|
|
const secondColumn = columns[ 1 ];
|
|
|
|
|
|
|
|
expect(
|
|
|
|
within( firstColumn ).getByText( /\[TaskList\]/ )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
within( firstColumn ).getByText( /\[InboxPanel\]/ )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
within( secondColumn ).queryByText( /\[TaskList\]/ )
|
|
|
|
).toBeNull();
|
|
|
|
expect(
|
|
|
|
within( secondColumn ).queryByText( /\[InboxPanel\]/ )
|
|
|
|
).toBeNull();
|
|
|
|
|
|
|
|
expect(
|
|
|
|
within( secondColumn ).getByText( /\[StatsOverview\]/ )
|
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
|
|
|
within( firstColumn ).queryByText( /\[StatsOverview\]/ )
|
|
|
|
).toBeNull();
|
|
|
|
} );
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|