2020-05-21 17:15:08 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
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-06-11 11:55:53 +00:00
|
|
|
jest.mock( 'header/activity-panel/panels/inbox', () =>
|
|
|
|
jest.fn().mockReturnValue( '[InboxPanel]' )
|
|
|
|
);
|
|
|
|
|
|
|
|
// We aren't testing the <QuickLinks /> component here.
|
|
|
|
jest.mock( 'quick-links', () => jest.fn().mockReturnValue( '[QuickLinks]' ) );
|
2020-06-05 16:28:25 +00:00
|
|
|
|
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-06-11 11:55:53 +00:00
|
|
|
<Layout requestingTaskList taskListHidden={ false } query={ {} } />
|
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={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// 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-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-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={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const quickLinks = screen.queryByText( '[QuickLinks]' );
|
|
|
|
expect( quickLinks ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should show QuickLinks when TaskList is complete', () => {
|
|
|
|
render(
|
|
|
|
<Layout
|
|
|
|
requestingTaskList={ false }
|
|
|
|
taskListComplete
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const quickLinks = screen.queryByText( '[QuickLinks]' );
|
|
|
|
expect( quickLinks ).toBeDefined();
|
|
|
|
} );
|
2020-05-21 17:15:08 +00:00
|
|
|
} );
|