Fix product task text shown before accordion is expanded on stack layout

This commit is contained in:
Chi-Hsuan Huang 2022-05-12 09:56:53 +08:00
parent a287963fa4
commit 5453737747
6 changed files with 64 additions and 37 deletions

View File

@ -22,7 +22,7 @@
color: #007cba;
padding: 0;
height: fit-content;
margin-top: 25px;
margin-top: 21px;
justify-content: center;
svg {

View File

@ -116,6 +116,7 @@ export const Products = () => {
<Stack
items={ visibleProductTypes }
onClickLoadSampleProduct={ loadSampleProduct }
showOtherOptions={ isExpanded }
/>
) : (
<CardLayout items={ visibleProductTypes } />

View File

@ -67,6 +67,7 @@
.woocommerce-stack__other-options {
display: block;
margin-top: 20px;
margin-bottom: 4px;
color: $gray-700;
line-height: 16px;
}

View File

@ -18,15 +18,18 @@ type StackProps = {
onClick: () => void;
} )[];
onClickLoadSampleProduct: () => void;
showOtherOptions?: boolean;
};
const Stack: React.FC< StackProps > = ( {
items,
onClickLoadSampleProduct,
showOtherOptions = true,
} ) => {
return (
<div className="woocommerce-products-stack">
<List items={ items } />
{ showOtherOptions && (
<Text className="woocommerce-stack__other-options">
{ interpolateComponents( {
mixedString: __(
@ -49,7 +52,6 @@ const Stack: React.FC< StackProps > = ( {
</Link>
),
LspLink: (
// TODO: Update this to the load sample product.
<Link
href=""
type="wc-admin"
@ -64,6 +66,7 @@ const Stack: React.FC< StackProps > = ( {
},
} ) }
</Text>
) }
</div>
);
};

View File

@ -93,6 +93,10 @@ describe( 'Products', () => {
const fetchMock = jest.spyOn( global, 'fetch' );
const { queryByText, getByRole } = render( <Products /> );
userEvent.click(
getByRole( 'button', { name: 'View more product types' } )
);
expect( queryByText( 'Load Sample Products' ) ).toBeInTheDocument();
userEvent.click(

View File

@ -27,6 +27,24 @@ describe( 'Stack', () => {
expect( queryAllByRole( 'link' ) ).toHaveLength( 2 );
} );
it( 'should not render other product options', () => {
const { queryByText } = render(
<Stack
showOtherOptions={ false }
onClickLoadSampleProduct={ () => {} }
items={ [
{
...productTypes[ 0 ],
onClick: () => {},
},
] }
/>
);
expect( queryByText( 'Start Blank' ) ).not.toBeInTheDocument();
expect( queryByText( 'Load Sample Products' ) ).not.toBeInTheDocument();
} );
it( 'should call onClickLoadSampleProduct when the "Load Sample Products" link is clicked', async () => {
const onClickLoadSampleProduct = jest.fn();
const { getByRole } = render(