woocommerce/plugins/woocommerce-admin/client/header/activity-panel/test/abbreviated-notifications-p...

116 lines
4.1 KiB
JavaScript
Raw Normal View History

Show task and activity notifications in the Inbox panel (https://github.com/woocommerce/woocommerce-admin/pull/7017) * Added abbreviated panels This commit adds abbreviated panels * Added notifications getter * Variables renamed * Added unread-indicators refactor * Open panel by default * Refactor unread-indicators * Renamed a few files and added event recording * Modified "critical alert" presentation * Removed useless control * Renamed const * Added control to InboxPanel component * Multiple critical alerts handling * Fixed styles * Moved Inbox panel styles # Conflicts: # packages/experimental/src/inbox-note/style.scss * Added tests * Inbox panel width reduced * Small refactor for unread notifications * Renamed abbreviated card component * Added changelog # Conflicts: # readme.txt # Conflicts: # readme.txt * Renamed inbox-panel and the cards config file * Renamed unread notifications variable * Fixed abbreviated card box-shadow * Small refactor to unread-indicators file * Refactored method getInitialState * Added scroll to task list # Conflicts: # client/task-list/task-list.js * Small CSS changes to titles * Fixed changelog # Conflicts: # readme.txt # Conflicts: # readme.txt * Added param to filter `woocommerce_admin_onboarding_task_list` * Removed extensibility from `getAbbreviatedNotifications` * Fixed chunk name * Removed `critical` prop from `AbbreviatedCard` comopnent * Moved AbbreviatedCard component to `packages` This commit moves the component `AbbreviatedCard` to `packages` # Conflicts: # docs/components/_sidebar.md # packages/components/CHANGELOG.md # packages/components/src/index.js # Conflicts: # packages/components/CHANGELOG.md * Removed `critical alerts` tag from abbreviated card This commit removes the tag `critical alerts` from the `Things to do next` abbreviated card * Removed filter `woocommerce_admin_abbreviated_card_list` * Fixed icon * Added defaut value to `hasUnreadNotifications` * Fix mapSelect error when the dismissed tasks option isn't populated. * Added AbbreviatedNotificationsPanel * Added tests * Renamed `getUnreadNotes` to `isNotesPanelVisible` * Removed abbreviated-card.js * Added singular/plural copy handling * Renamed method `getInitialState` to `getInitialOpenState` * Fixed Link prop * Revert "Fixed Link prop" This reverts commit 74e6a7fae030766eb5d6be098caa15478f2cb2c6. * Fixed Link prop * Added task list visibility check * Fixed scroll after redirect # Conflicts: # client/task-list/index.js * Added propType to `AbbreviatedCard` * Fixed `Add-task doc example * Removed default values from ActivityPanel * Fixed multiple calls to a filter Co-authored-by: Fernando Marichal <contacto@fernandomarichal.com> Co-authored-by: Jeff Stieler <jeff.m.stieler@gmail.com>
2021-06-09 13:56:45 +00:00
/**
* External dependencies
*/
import { render } from '@testing-library/react';
import { useSelect } from '@wordpress/data';
/**
* Internal dependencies
*/
import { AbbreviatedNotificationsPanel } from '../panels/inbox/abbreviated-notifications-panel';
jest.mock( '@wordpress/data', () => {
// Require the original module to not be mocked...
const originalModule = jest.requireActual( '@wordpress/data' );
return {
__esModule: true, // Use it when dealing with esModules
...originalModule,
useSelect: jest.fn().mockReturnValue( {} ),
};
} );
describe( 'Inbox', () => {
it( 'does not show any abbreviated notifications', () => {
const { queryByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 0 } />
);
expect( queryByText( 'Things to do next' ) ).toBeNull();
expect( queryByText( 'Orders to fulfill' ) ).toBeNull();
expect( queryByText( 'Reviews to moderate' ) ).toBeNull();
expect( queryByText( 'Inventory to review' ) ).toBeNull();
} );
it( 'does not show any abbreviated panel when the extended task list is hidden and the setup list is visible', () => {
useSelect.mockImplementation( () => ( {
stockNoticesCount: 4,
reviewsToModerateCount: 3,
ordersToProcessCount: 2,
isExtendedTaskListHidden: true,
} ) );
const { queryByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 1 } />
);
expect( queryByText( 'Things to do next' ) ).toBeNull();
expect( queryByText( 'Orders to fulfill' ) ).toBeNull();
expect( queryByText( 'Reviews to moderate' ) ).toBeNull();
expect( queryByText( 'Inventory to review' ) ).toBeNull();
} );
it( 'shows the `Things to do next` notification panel, with 1 thing to do', () => {
useSelect.mockImplementation( () => ( {
isExtendedTaskListHidden: false,
} ) );
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 1 } />
);
expect( getByText( 'Things to do next' ) ).toBeDefined();
expect( getByText( 'You have 1 new thing to do' ) ).toBeDefined();
} );
it( 'shows plural copy for the `Things to do next` notification panel', () => {
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 5 } />
);
expect( getByText( 'Things to do next' ) ).toBeDefined();
expect( getByText( 'You have 5 new things to do' ) ).toBeDefined();
} );
it( 'shows the `Orders to fulfill` notification panel, with 2 thing to do', () => {
useSelect.mockImplementation( () => ( {
ordersToProcessCount: 2,
isSetupTaskListHidden: true,
} ) );
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 0 } />
);
expect( getByText( 'Orders to fulfill' ) ).toBeDefined();
expect( getByText( 'You have 2 orders to fulfill' ) ).toBeDefined();
} );
it( 'shows the `Reviews to moderate` notification panel, with 3 thing to do', () => {
useSelect.mockImplementation( () => ( {
reviewsToModerateCount: 3,
isSetupTaskListHidden: true,
} ) );
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 0 } />
);
expect( getByText( 'Reviews to moderate' ) ).toBeDefined();
expect( getByText( 'You have 3 reviews to moderate' ) ).toBeDefined();
} );
it( 'shows the `Inventory to review` notification panel', () => {
useSelect.mockImplementation( () => ( {
stockNoticesCount: 4,
isSetupTaskListHidden: true,
} ) );
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 0 } />
);
expect( getByText( 'Inventory to review' ) ).toBeDefined();
expect(
getByText( 'You have inventory to review and update' )
).toBeDefined();
} );
it( 'shows all the abbreviated notification panels', () => {
useSelect.mockImplementation( () => ( {
stockNoticesCount: 4,
reviewsToModerateCount: 3,
ordersToProcessCount: 2,
isSetupTaskListHidden: true,
} ) );
const { getByText } = render(
<AbbreviatedNotificationsPanel thingsToDoNextCount={ 1 } />
);
expect( getByText( 'Things to do next' ) ).toBeDefined();
expect( getByText( 'Orders to fulfill' ) ).toBeDefined();
expect( getByText( 'Reviews to moderate' ) ).toBeDefined();
expect( getByText( 'Inventory to review' ) ).toBeDefined();
} );
} );