Add category title tests (https://github.com/woocommerce/woocommerce-admin/pull/6445)
This commit is contained in:
parent
09d6bd9164
commit
2acbc0c1e8
|
@ -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>
|
||||
|
|
|
@ -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();
|
||||
} );
|
||||
} );
|
Loading…
Reference in New Issue