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';
|
|
|
|
|
2021-07-14 20:38:57 +00:00
|
|
|
jest.mock( '../stats-overview', () =>
|
2021-03-25 21:54:24 +00:00
|
|
|
jest.fn().mockReturnValue( <div>[StatsOverview]</div> )
|
2020-06-15 02:17:12 +00:00
|
|
|
);
|
2020-05-21 17:15:08 +00:00
|
|
|
|
2021-03-25 21:54:24 +00:00
|
|
|
jest.mock( '../../inbox-panel', () =>
|
|
|
|
jest.fn().mockReturnValue( <div>[InboxPanel]</div> )
|
|
|
|
);
|
2020-06-11 11:55:53 +00:00
|
|
|
|
2021-02-10 03:30:29 +00:00
|
|
|
jest.mock( '../../store-management-links', () => ( {
|
2021-03-25 21:54:24 +00:00
|
|
|
StoreManagementLinks: jest
|
|
|
|
.fn()
|
|
|
|
.mockReturnValue( <div>[StoreManagementLinks]</div> ),
|
|
|
|
} ) );
|
|
|
|
|
|
|
|
jest.mock( '../activity-panel', () => ( {
|
|
|
|
ActivityPanel: jest.fn().mockReturnValue( <div>[ActivityPanel]</div> ),
|
2021-02-10 03:30:29 +00:00
|
|
|
} ) );
|
|
|
|
|
2020-10-22 22:13:14 +00:00
|
|
|
jest.mock( '@woocommerce/data', () => ( {
|
|
|
|
...jest.requireActual( '@woocommerce/data' ),
|
|
|
|
useUserPreferences: jest.fn().mockReturnValue( {} ),
|
|
|
|
} ) );
|
|
|
|
|
2021-03-25 21:54:24 +00:00
|
|
|
jest.mock( '@wordpress/element', () => {
|
|
|
|
return {
|
|
|
|
...jest.requireActual( '@wordpress/element' ),
|
|
|
|
Suspense: ( { children } ) => <div>{ children }</div>,
|
|
|
|
// It's not easy to mock a React.lazy component, since we only use one in this component, this mocks lazy to return a mocked <TaskList>
|
|
|
|
lazy: () => () => <div>[TaskList]</div>,
|
|
|
|
};
|
|
|
|
} );
|
2021-01-27 21:40:27 +00:00
|
|
|
|
2020-06-15 02:17:12 +00:00
|
|
|
describe( 'Homescreen Layout', () => {
|
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-03-25 21:54:24 +00:00
|
|
|
taskListComplete
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
2024-05-22 22:05:01 +00:00
|
|
|
query={ { page: 'wc-admin' } }
|
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
|
|
|
);
|
2021-03-25 21:54:24 +00:00
|
|
|
expect( columns ).toBeInTheDocument();
|
2020-05-21 17:15:08 +00:00
|
|
|
|
|
|
|
// Expect that the <TaskList /> is there too.
|
2021-03-25 21:54:24 +00:00
|
|
|
const taskList = screen.getByText( '[TaskList]' );
|
|
|
|
expect( taskList ).toBeInTheDocument();
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|
|
|
|
|
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-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
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
|
|
|
);
|
2021-03-25 21:54:24 +00:00
|
|
|
expect( columns ).not.toBeInTheDocument();
|
2020-05-21 17:15:08 +00:00
|
|
|
|
|
|
|
// Expect that the <TaskList /> is there though.
|
2021-01-27 21:40:27 +00:00
|
|
|
const taskList = screen.queryByText( '[TaskList]' );
|
2021-03-25 21:54:24 +00:00
|
|
|
expect( taskList ).toBeInTheDocument();
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|
2020-05-27 16:08:39 +00:00
|
|
|
|
|
|
|
it( 'should not show TaskList when user has hidden', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ false }
|
2024-05-22 22:05:01 +00:00
|
|
|
query={ { page: 'wc-admin' } }
|
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]' );
|
2021-03-25 21:54:24 +00:00
|
|
|
expect( taskList ).not.toBeInTheDocument();
|
2020-06-11 11:55:53 +00:00
|
|
|
} );
|
|
|
|
|
2021-03-25 21:54:24 +00:00
|
|
|
it( 'should show StoreManagementLinks when TaskList is complete, even if the task list is not hidden', () => {
|
2020-06-11 11:55:53 +00:00
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
2021-03-25 21:54:24 +00:00
|
|
|
taskListComplete
|
2024-05-22 22:05:01 +00:00
|
|
|
query={ { page: 'wc-admin' } }
|
2020-08-17 00:30:46 +00:00
|
|
|
updateOptions={ () => {} }
|
2020-06-11 11:55:53 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2021-03-25 21:54:24 +00:00
|
|
|
const storeManagementLinks = screen.queryByText(
|
|
|
|
'[StoreManagementLinks]'
|
|
|
|
);
|
|
|
|
expect( storeManagementLinks ).toBeInTheDocument();
|
2020-06-11 11:55:53 +00:00
|
|
|
} );
|
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-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
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-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
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-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
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 }
|
2021-03-25 21:54:24 +00:00
|
|
|
taskListComplete
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
2024-05-22 22:05:01 +00:00
|
|
|
query={ { page: 'wc-admin' } }
|
2021-01-28 13:33:36 +00:00
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const columns = container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen-column'
|
|
|
|
);
|
|
|
|
expect( columns ).toHaveLength( 2 );
|
|
|
|
const firstColumn = columns[ 0 ];
|
|
|
|
const secondColumn = columns[ 1 ];
|
|
|
|
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).getByText( '[TaskList]' )
|
2021-01-28 13:33:36 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).getByText( '[InboxPanel]' )
|
2021-01-28 13:33:36 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).queryByText( '[TaskList]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-01-28 13:33:36 +00:00
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).queryByText( '[InboxPanel]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-01-28 13:33:36 +00:00
|
|
|
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).getByText( '[StatsOverview]' )
|
2021-01-28 13:33:36 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).queryByText( '[StatsOverview]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-01-28 13:33:36 +00:00
|
|
|
} );
|
2021-02-10 03:30:29 +00:00
|
|
|
|
|
|
|
it( 'should display the correct blocks in each column when task list is hidden', () => {
|
|
|
|
useUserPreferences.mockReturnValue( {
|
|
|
|
homepage_layout: 'two_columns',
|
|
|
|
} );
|
|
|
|
const { container } = render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
2021-03-25 21:54:24 +00:00
|
|
|
taskListComplete
|
2021-11-15 20:57:13 +00:00
|
|
|
hasTaskList={ true }
|
2021-02-10 03:30:29 +00:00
|
|
|
isTaskListHidden={ true }
|
2024-05-22 22:05:01 +00:00
|
|
|
query={ { page: 'wc-admin' } }
|
2021-02-10 03:30:29 +00:00
|
|
|
updateOptions={ () => {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const columns = container.getElementsByClassName(
|
|
|
|
'woocommerce-homescreen-column'
|
|
|
|
);
|
|
|
|
expect( columns ).toHaveLength( 2 );
|
|
|
|
const firstColumn = columns[ 0 ];
|
|
|
|
const secondColumn = columns[ 1 ];
|
|
|
|
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).getByText( '[TaskList]' )
|
2021-02-10 03:30:29 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).getByText( '[InboxPanel]' )
|
2021-02-10 03:30:29 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).queryByText( '[TaskList]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-02-10 03:30:29 +00:00
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).queryByText( '[InboxPanel]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-02-10 03:30:29 +00:00
|
|
|
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).getByText( '[StatsOverview]' )
|
2021-02-10 03:30:29 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( secondColumn ).getByText( '[StoreManagementLinks]' )
|
2021-02-10 03:30:29 +00:00
|
|
|
).toBeInTheDocument();
|
|
|
|
expect(
|
2021-03-25 21:54:24 +00:00
|
|
|
within( firstColumn ).queryByText( '[StatsOverview]' )
|
|
|
|
).not.toBeInTheDocument();
|
2021-02-10 03:30:29 +00:00
|
|
|
} );
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|