This commit is contained in:
Joshua T Flowers 2021-03-04 10:32:46 -05:00 committed by GitHub
parent 09d6bd9164
commit 2acbc0c1e8
2 changed files with 81 additions and 2 deletions

View File

@ -6,11 +6,11 @@ import { FavoriteButton } from '../favorite-button';
import { FavoritesTooltip } from '../favorites-tooltip';
export const CategoryTitle = ( { category } ) => {
const { id, title } = category;
const { id, menuId, title } = category;
const className = 'woocommerce-navigation-category-title';
if ( [ 'plugins', 'favorites' ].includes( category.menuId ) ) {
if ( [ 'plugins', 'favorites' ].includes( menuId ) ) {
return (
<span className={ className }>
<span className={ `${ className }__text` }>{ title }</span>

View File

@ -0,0 +1,79 @@
/**
* External dependencies
*/
import { render } from '@testing-library/react';
/**
* Internal dependencies
*/
import CategoryTitle from '../';
describe( 'CategoryTitle', () => {
test( 'should render the category title without the option to favorite for the primary menu', () => {
const { container, queryByText } = render(
<CategoryTitle
category={ {
id: 'my-category',
menuId: 'primary',
title: 'Category Title',
} }
/>
);
expect(
container.querySelector( '.woocommerce-navigation-favorite-button' )
).toBeNull();
expect( queryByText( 'Category Title' ) ).not.toBeNull();
} );
test( 'should render the category title without the option to favorite for any other menus', () => {
const { container, queryByText } = render(
<CategoryTitle
category={ {
id: 'my-category',
menuId: 'new-menu',
title: 'Category Title',
} }
/>
);
expect(
container.querySelector( '.woocommerce-navigation-favorite-button' )
).toBeNull();
expect( queryByText( 'Category Title' ) ).not.toBeNull();
} );
test( 'should render the category title and favorite button for plugins', () => {
const { container, queryByText } = render(
<CategoryTitle
category={ {
id: 'my-category',
menuId: 'plugins',
title: 'Category Title',
} }
/>
);
expect(
container.querySelector( '.woocommerce-navigation-favorite-button' )
).not.toBeNull();
expect( queryByText( 'Category Title' ) ).not.toBeNull();
} );
test( 'should render the category title and unfavorite button for favorites', () => {
const { container, queryByText } = render(
<CategoryTitle
category={ {
id: 'my-category',
menuId: 'favorites',
title: 'Category Title',
} }
/>
);
expect(
container.querySelector( '.woocommerce-navigation-favorite-button' )
).not.toBeNull();
expect( queryByText( 'Category Title' ) ).not.toBeNull();
} );
} );