From 7bf63fae05a1a9cd555b4c68c0bc3dca880883d7 Mon Sep 17 00:00:00 2001 From: Fernando Date: Wed, 27 Jan 2021 18:40:27 -0300 Subject: [PATCH] Hide Inventory and Reviews panels if store setup task list is visible (https://github.com/woocommerce/woocommerce-admin/pull/6182) * Fixed reviews and inventory panels visibility This commit fixes the reviews and inventory panels visibility when setup task list is enabled * Fixed tests * Fixed control and small refactor * Fixed useSelect * Fixed multiple useSelect Co-authored-by: Fernando Marichal --- .../client/homescreen/activity-panel/index.js | 15 ++++++----- .../homescreen/activity-panel/panels.js | 3 +++ .../homescreen/activity-panel/test/panels.js | 26 +++++++++++++++++++ .../client/homescreen/test/index.js | 13 +++++++--- 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js index 5a7944dc46a..83085129af8 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/index.js @@ -11,6 +11,7 @@ import { __experimentalText as Text, } from '@wordpress/components'; import { getSetting } from '@woocommerce/wc-admin-settings'; +import { OPTIONS_STORE_NAME } from '@woocommerce/data'; /** * Internal dependencies @@ -34,16 +35,18 @@ export const ActivityPanel = () => { const countLowStockProducts = getLowStockCount( select ); const countUnapprovedReviews = getUnapprovedReviews( select ); const publishedProductCount = getSetting( 'publishedProductCount', 0 ); - + const { getOption } = select( OPTIONS_STORE_NAME ); + const isTaskListHidden = getOption( 'woocommerce_task_list_hidden' ); return { countLowStockProducts, - countUnreadOrders, - manageStock, - orderStatuses, - totalOrderCount, - reviewsEnabled, countUnapprovedReviews, + countUnreadOrders, + isTaskListHidden, + manageStock, publishedProductCount, + reviewsEnabled, + totalOrderCount, + orderStatuses, }; } ); diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js index 76e635f56bd..f9a9ba2ab08 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/panels.js @@ -14,6 +14,7 @@ export function getAllPanels( { countLowStockProducts, countUnapprovedReviews, countUnreadOrders, + isTaskListHidden, manageStock, orderStatuses, publishedProductCount, @@ -37,6 +38,7 @@ export function getAllPanels( { }, totalOrderCount > 0 && publishedProductCount > 0 && + isTaskListHidden === 'yes' && manageStock === 'yes' && { className: 'woocommerce-homescreen-card', count: countLowStockProducts, @@ -51,6 +53,7 @@ export function getAllPanels( { title: __( 'Stock', 'woocommerce-admin' ), }, publishedProductCount > 0 && + isTaskListHidden === 'yes' && reviewsEnabled === 'yes' && { className: 'woocommerce-homescreen-card', id: 'reviews-panel', diff --git a/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js b/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js index 2989c68ff1c..d36052cb228 100644 --- a/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js +++ b/plugins/woocommerce-admin/client/homescreen/activity-panel/test/panels.js @@ -33,6 +33,30 @@ describe( 'ActivityPanel', () => { publishedProductCount: 0, manageStock: 'yes', reviewsEnabled: 'yes', + isTaskListHidden: 'yes', + } ); + + expect( panels ).toEqual( + expect.not.arrayContaining( [ + expect.objectContaining( { id: 'reviews-panel' } ), + ] ) + ); + expect( panels ).toEqual( + expect.not.arrayContaining( [ + expect.objectContaining( { id: 'stock-panel' } ), + ] ) + ); + } ); + + it( 'should exclude the reviews and stock panels when the setup task list is visible', () => { + const panels = getAllPanels( { + countUnreadOrders: 0, + orderStatuses: [], + totalOrderCount: 1, // Yes, I realize this isn't "possible". + publishedProductCount: 0, + manageStock: 'yes', + reviewsEnabled: 'yes', + isTaskListHidden: 'no', } ); expect( panels ).toEqual( @@ -68,6 +92,7 @@ describe( 'ActivityPanel', () => { totalOrderCount: 10, publishedProductCount: 2, manageStock: 'yes', + isTaskListHidden: 'yes', } ); expect( panels ).toEqual( @@ -81,6 +106,7 @@ describe( 'ActivityPanel', () => { const panels = getAllPanels( { publishedProductCount: 5, reviewsEnabled: 'yes', + isTaskListHidden: 'yes', } ); expect( panels ).toEqual( diff --git a/plugins/woocommerce-admin/client/homescreen/test/index.js b/plugins/woocommerce-admin/client/homescreen/test/index.js index 7e314fabf79..1e472e545e4 100644 --- a/plugins/woocommerce-admin/client/homescreen/test/index.js +++ b/plugins/woocommerce-admin/client/homescreen/test/index.js @@ -25,6 +25,11 @@ jest.mock( '@woocommerce/data', () => ( { useUserPreferences: jest.fn().mockReturnValue( {} ), } ) ); +// We aren't testing the component here. +jest.mock( '../activity-panel', () => ( { + ActivityPanel: jest.fn().mockReturnValue( '[ActivityPanel]' ), +} ) ); + describe( 'Homescreen Layout', () => { it( 'should show TaskList placeholder when loading', () => { const { container } = render( @@ -42,7 +47,7 @@ describe( 'Homescreen Layout', () => { expect( placeholder ).not.toBeNull(); } ); - it( 'should show TaskList inline', async () => { + it( 'should show TaskList inline', () => { const { container } = render( { expect( columns ).not.toBeNull(); // Expect that the is there too. - const taskList = await screen.findByText( '[TaskList]' ); + const taskList = screen.queryByText( '[TaskList]' ); expect( taskList ).toBeDefined(); } ); - it( 'should render TaskList alone when on task', async () => { + it( 'should render TaskList alone when on task', () => { const { container } = render( { expect( columns ).toBeNull(); // Expect that the is there though. - const taskList = await screen.findByText( '[TaskList]' ); + const taskList = screen.queryByText( '[TaskList]' ); expect( taskList ).toBeDefined(); } );