Skip to content

Commit

Permalink
Fix tasklist completion message when no tasks are completed (#38092)
Browse files Browse the repository at this point in the history
* Fix task list progress title

* Add changelog
  • Loading branch information
chihsuan committed May 5, 2023
1 parent cabe966 commit 208ac81
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 1 deletion.
Expand Up @@ -55,7 +55,7 @@ export const DefaultProgressTitle: React.FC< DefaultProgressTitleProps > = ( {
)
: __( 'Welcome to your store', 'woocommerce' );
}
if ( completedCount > 0 && completedCount < 4 ) {
if ( completedCount <= 3 ) {
return __( "Let's get you started", 'woocommerce' ) + ' 🚀';
}
if ( completedCount > 3 && completedCount < 6 ) {
Expand Down
@@ -0,0 +1,110 @@
/**
* External dependencies
*/
import { render, screen } from '@testing-library/react';
import { useSelect } from '@wordpress/data';

/**
* Internal dependencies
*/
import { DefaultProgressTitle } from '../default-progress-title';

jest.mock( '@wordpress/data', () => ( {
...jest.requireActual( '@wordpress/data' ),
useSelect: jest.fn(),
} ) );

describe( 'default-progress-title', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [],
} ),
hasFinishedResolution: () => true,
} ) )
);

it( 'should render "Welcome to your store" when no tasks are completed and visited', () => {
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Welcome to your store' )
).toBeInTheDocument();
} );

it( 'should render "Welcome to your store" when all tasks are completed', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'Welcome to your store' )
).toBeInTheDocument();
} );

it( 'should render "Let\'s get you started" when has task visited and task completed count <= 3', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [ { isVisited: true, isComplete: false } ],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( "Let's get you started", { exact: false } )
).toBeInTheDocument();
} );

it( 'should render "You are on the right track" when has task visited and task completed count > 3', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: false },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'You are on the right track', { exact: false } )
).toBeInTheDocument();
} );

it( 'should render "You are almost there" when has task visited and task completed count > 5', () => {
( useSelect as jest.Mock ).mockImplementation( ( fn ) =>
fn( () => ( {
getTaskList: () => ( {
tasks: [
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: true },
{ isVisited: true, isComplete: false },
],
} ),
hasFinishedResolution: () => true,
} ) )
);
render( <DefaultProgressTitle taskListId="1" /> );
expect(
screen.getByText( 'You are almost there', { exact: false } )
).toBeInTheDocument();
} );
} );
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/fix-tasklist-completion-message
@@ -0,0 +1,4 @@
Significance: patch
Type: fix

Fix task list progress title when no tasks are completed

0 comments on commit 208ac81

Please sign in to comment.