From 227a4993438a139b66909fe0b42e3d7381c87a53 Mon Sep 17 00:00:00 2001 From: Matt Sherman Date: Thu, 11 Jun 2020 07:55:53 -0400 Subject: [PATCH] Mock QuickLinks and add tests to ensure that QuickLinks is rendered when it should be. (https://github.com/woocommerce/woocommerce-admin/pull/4546) --- .../client/homepage/test/index.js | 61 +++++++++++++++---- 1 file changed, 48 insertions(+), 13 deletions(-) diff --git a/plugins/woocommerce-admin/client/homepage/test/index.js b/plugins/woocommerce-admin/client/homepage/test/index.js index 2ebff901dda..7bae62c7d71 100644 --- a/plugins/woocommerce-admin/client/homepage/test/index.js +++ b/plugins/woocommerce-admin/client/homepage/test/index.js @@ -11,19 +11,22 @@ jest.mock( 'homepage/stats-overview', () => jest.fn().mockReturnValue( null ) ); jest.mock( 'task-list', () => jest.fn().mockReturnValue( '[TaskList]' ) ); // We aren't testing the component here. -jest.mock( 'header/activity-panel/panels/inbox', () => jest.fn().mockReturnValue( '[InboxPanel]' ) ); +jest.mock( 'header/activity-panel/panels/inbox', () => + jest.fn().mockReturnValue( '[InboxPanel]' ) +); + +// We aren't testing the component here. +jest.mock( 'quick-links', () => jest.fn().mockReturnValue( '[QuickLinks]' ) ); describe( 'Homepage Layout', () => { it( 'should show TaskList placeholder when loading', () => { const { container } = render( - + ); - const placeholder = container.querySelector( '.woocommerce-task-card.is-loading' ); + const placeholder = container.querySelector( + '.woocommerce-task-card.is-loading' + ); expect( placeholder ).not.toBeNull(); } ); @@ -37,11 +40,13 @@ describe( 'Homepage Layout', () => { ); // Expect that we're rendering the "full" home screen (with columns). - const columns = container.querySelector( '.woocommerce-homepage-column' ); + const columns = container.querySelector( + '.woocommerce-homepage-column' + ); expect( columns ).not.toBeNull(); // Expect that the is there too. - const taskList = await screen.findByText( '[TaskList]' ) + const taskList = await screen.findByText( '[TaskList]' ); expect( taskList ).toBeDefined(); } ); @@ -57,11 +62,13 @@ describe( 'Homepage Layout', () => { ); // Expect that we're NOT rendering the "full" home screen (with columns). - const columns = container.querySelector( '.woocommerce-homepage-column' ); + const columns = container.querySelector( + '.woocommerce-homepage-column' + ); expect( columns ).toBeNull(); // Expect that the is there though. - const taskList = await screen.findByText( '[TaskList]' ) + const taskList = await screen.findByText( '[TaskList]' ); expect( taskList ).toBeDefined(); } ); @@ -75,7 +82,7 @@ describe( 'Homepage Layout', () => { /> ); - const taskList = screen.queryByText( '[TaskList]' ) + const taskList = screen.queryByText( '[TaskList]' ); expect( taskList ).toBeNull(); } ); @@ -89,7 +96,35 @@ describe( 'Homepage Layout', () => { /> ); - const taskList = screen.queryByText( '[TaskList]' ) + const taskList = screen.queryByText( '[TaskList]' ); expect( taskList ).toBeNull(); } ); + + it( 'should show QuickLinks when user has hidden TaskList', () => { + render( + + ); + + const quickLinks = screen.queryByText( '[QuickLinks]' ); + expect( quickLinks ).toBeDefined(); + } ); + + it( 'should show QuickLinks when TaskList is complete', () => { + render( + + ); + + const quickLinks = screen.queryByText( '[QuickLinks]' ); + expect( quickLinks ).toBeDefined(); + } ); } );