2020-07-14 12:20:51 +00:00
|
|
|
/**
|
|
|
|
* External dependencies
|
|
|
|
*/
|
|
|
|
import { render, screen } from '@testing-library/react';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { ActivityPanel } from '../';
|
|
|
|
|
2020-10-22 22:13:14 +00:00
|
|
|
jest.mock( '@woocommerce/data', () => ( {
|
|
|
|
...jest.requireActual( '@woocommerce/data' ),
|
|
|
|
useUserPreferences: () => ( {
|
|
|
|
updateUserPreferences: () => {},
|
|
|
|
} ),
|
|
|
|
} ) );
|
|
|
|
|
2020-11-06 17:53:03 +00:00
|
|
|
// We aren't testing the <DisplayOptions /> component here.
|
|
|
|
jest.mock( '../display-options', () => ( {
|
|
|
|
DisplayOptions: jest.fn().mockReturnValue( '[DisplayOptions]' ),
|
|
|
|
} ) );
|
|
|
|
|
2020-12-18 13:17:07 +00:00
|
|
|
jest.mock( '../highlight-tooltip', () => ( {
|
|
|
|
HighlightTooltip: jest.fn().mockReturnValue( '[HighlightTooltip]' ),
|
|
|
|
} ) );
|
|
|
|
|
2020-07-14 12:20:51 +00:00
|
|
|
describe( 'Activity Panel', () => {
|
|
|
|
it( 'should render inbox tab on embedded pages', () => {
|
2020-07-28 02:32:58 +00:00
|
|
|
render( <ActivityPanel isEmbedded query={ {} } /> );
|
2020-07-14 12:20:51 +00:00
|
|
|
|
|
|
|
expect( screen.getByText( 'Inbox' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should render inbox tab if not on home screen', () => {
|
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/customers',
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
query={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( screen.getByText( 'Inbox' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render inbox tab on home screen', () => {
|
2020-07-28 02:32:58 +00:00
|
|
|
render( <ActivityPanel query={ {} } /> );
|
2020-07-14 12:20:51 +00:00
|
|
|
|
|
|
|
expect( screen.queryByText( 'Inbox' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
2020-11-10 13:36:04 +00:00
|
|
|
it( 'should not render help tab if not on home screen', () => {
|
2020-07-14 12:20:51 +00:00
|
|
|
render(
|
|
|
|
<ActivityPanel
|
2020-11-10 13:36:04 +00:00
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/customers',
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
query={ {} }
|
2020-07-14 12:20:51 +00:00
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-11-10 13:36:04 +00:00
|
|
|
expect( screen.queryByText( 'Help' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should render help tab if on home screen', () => {
|
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/',
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
query={ {} }
|
|
|
|
/>
|
|
|
|
);
|
2020-07-14 12:20:51 +00:00
|
|
|
|
|
|
|
expect( screen.getByText( 'Help' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
2020-11-10 13:36:04 +00:00
|
|
|
it( 'should render help tab before options load', async () => {
|
2020-07-14 12:20:51 +00:00
|
|
|
render(
|
|
|
|
<ActivityPanel
|
2020-11-10 13:36:04 +00:00
|
|
|
requestingTaskListOptions
|
2020-07-14 12:20:51 +00:00
|
|
|
query={ {
|
|
|
|
task: 'products',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
const tabs = await screen.findAllByRole( 'tab' );
|
|
|
|
|
|
|
|
// Expect that the only tab is "Help".
|
|
|
|
expect( tabs ).toHaveLength( 1 );
|
|
|
|
expect( screen.getByText( 'Help' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
2020-07-28 02:32:58 +00:00
|
|
|
it( 'should not render help tab when not on main route', () => {
|
2020-07-14 12:20:51 +00:00
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
2020-11-10 13:36:04 +00:00
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/customers',
|
|
|
|
},
|
|
|
|
} ) }
|
2020-07-14 12:20:51 +00:00
|
|
|
query={ {
|
|
|
|
task: 'products',
|
|
|
|
path: '/customers',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
// Expect that "Help" tab is absent.
|
|
|
|
expect( screen.queryByText( 'Help' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
2020-11-16 13:48:50 +00:00
|
|
|
it( 'should render display options if on home screen', () => {
|
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/',
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
query={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( screen.getByText( '[DisplayOptions]' ) ).toBeDefined();
|
|
|
|
} );
|
|
|
|
|
2020-09-24 21:23:27 +00:00
|
|
|
it( 'should only render the store setup link when TaskList is not complete', () => {
|
|
|
|
const { queryByText, rerender } = render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {
|
|
|
|
task: 'products',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( queryByText( 'Store Setup' ) ).toBeDefined();
|
|
|
|
|
|
|
|
rerender(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete
|
|
|
|
taskListHidden={ false }
|
|
|
|
query={ {
|
|
|
|
task: 'products',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( queryByText( 'Store Setup' ) ).toBeNull();
|
|
|
|
} );
|
2020-12-03 01:13:36 +00:00
|
|
|
|
|
|
|
it( 'should not render the store setup link when on the home screen and TaskList is not complete', () => {
|
|
|
|
const { queryByText } = render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
getHistory={ () => ( {
|
|
|
|
location: {
|
|
|
|
pathname: '/',
|
|
|
|
},
|
|
|
|
} ) }
|
|
|
|
query={ {
|
|
|
|
task: '',
|
|
|
|
} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( queryByText( 'Store Setup' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should render the store setup link when on embedded pages and TaskList is not complete', () => {
|
2020-12-18 13:17:07 +00:00
|
|
|
const { getByText } = render(
|
2020-12-03 01:13:36 +00:00
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
isEmbedded
|
|
|
|
query={ {} }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
2020-12-18 13:17:07 +00:00
|
|
|
expect( getByText( 'Store Setup' ) ).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
describe( 'help panel tooltip', () => {
|
|
|
|
it( 'should render highlight tooltip when task count is at-least 2, task is not completed, and tooltip not shown yet', () => {
|
|
|
|
const { getByText } = render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
userPreferencesData={ {
|
|
|
|
task_list_tracked_started_tasks: { payment: 2 },
|
|
|
|
} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
helpPanelHighlightShown="no"
|
|
|
|
isEmbedded
|
|
|
|
query={ { task: 'payment' } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( getByText( '[HighlightTooltip]' ) ).toBeInTheDocument();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render highlight tooltip when task is not visited more then once', () => {
|
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
userPreferencesData={ {
|
|
|
|
task_list_tracked_started_tasks: { payment: 1 },
|
|
|
|
} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
isEmbedded
|
|
|
|
query={ { task: 'payment' } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( screen.queryByText( '[HighlightTooltip]' ) ).toBeNull();
|
|
|
|
|
|
|
|
render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
userPreferencesData={ {
|
|
|
|
task_list_tracked_started_tasks: {},
|
|
|
|
} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
isEmbedded
|
|
|
|
query={ { task: 'payment' } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( screen.queryByText( '[HighlightTooltip]' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render highlight tooltip when task is visited twice, but completed already', () => {
|
|
|
|
const { queryByText } = render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
userPreferencesData={ {
|
|
|
|
task_list_tracked_started_tasks: { payment: 2 },
|
|
|
|
} }
|
|
|
|
trackedCompletedTasks={ [ 'payment' ] }
|
|
|
|
isEmbedded
|
|
|
|
query={ { task: 'payment' } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( queryByText( '[HighlightTooltip]' ) ).toBeNull();
|
|
|
|
} );
|
|
|
|
|
|
|
|
it( 'should not render highlight tooltip when task is visited twice, not completed, but already shown', () => {
|
|
|
|
const { queryByText } = render(
|
|
|
|
<ActivityPanel
|
|
|
|
requestingTaskListOptions={ false }
|
|
|
|
taskListComplete={ false }
|
|
|
|
taskListHidden={ false }
|
|
|
|
userPreferencesData={ {
|
|
|
|
task_list_tracked_started_tasks: { payment: 2 },
|
|
|
|
help_panel_highlight_shown: 'yes',
|
|
|
|
} }
|
|
|
|
trackedCompletedTasks={ [] }
|
|
|
|
isEmbedded
|
|
|
|
query={ { task: 'payment' } }
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
|
|
|
|
expect( queryByText( '[HighlightTooltip]' ) ).toBeNull();
|
|
|
|
} );
|
2020-12-03 01:13:36 +00:00
|
|
|
} );
|
2020-07-14 12:20:51 +00:00
|
|
|
} );
|