Skip to content

Commit

Permalink
Add default category
Browse files Browse the repository at this point in the history
Using fixtures for tests.

Using fixtures for tests.
  • Loading branch information
ramonjd committed Sep 20, 2024
1 parent 5709016 commit 021275c
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 36 deletions.
1 change: 1 addition & 0 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function StyleBook( {
</div>
) : (
<StyleBookBody
category={ tabs[ 0 ].name }
examples={ examples }
isSelected={ isSelected }
onClick={ onClick }
Expand Down
134 changes: 112 additions & 22 deletions packages/edit-site/src/components/style-book/test/utils.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,131 @@
/**
* Internal dependencies
*/
import { getCategoryExamples, getExamples } from '../utils';
import { getCategoryExamples } from '../utils';
import { STYLE_BOOK_CATEGORIES } from '../constants';

/**
* WordPress dependencies
*/
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
import { registerCoreBlocks } from '@wordpress/block-library';
// Fixtures
const exampleThemeBlocks = [
{
name: 'core/post-content',
title: 'Post Content',
category: 'theme',
},
{
name: 'core/post-terms',
title: 'Post Terms',
category: 'theme',
},
{
name: 'core/home-link',
title: 'Home Link',
category: 'design',
},
{
name: 'custom/colors',
title: 'Colors',
category: 'colors',
},
{
name: 'core/site-logo',
title: 'Site Logo',
category: 'theme',
},
{
name: 'core/site-title',
title: 'Site Title',
category: 'theme',
},
{
name: 'core/site-tagline',
title: 'Site Tagline',
category: 'theme',
},
{
name: 'core/group',
title: 'Group',
category: 'design',
},
{
name: 'core/comments-pagination-numbers',
title: 'Comments Page Numbers',
category: 'theme',
},
{
name: 'core/post-featured-image',
title: 'Featured Image',
category: 'theme',
},
];

describe( 'utils', () => {
beforeAll( () => {
// Register all core blocks
registerCoreBlocks();
} );

afterAll( () => {
// Clean up registered blocks
getBlockTypes().forEach( ( block ) => {
unregisterBlockType( block.name );
} );
} );

describe( 'getCategoryExamples', () => {
it( 'returns category key value pairs', () => {
it( 'returns theme subcategories examples', () => {
const themeCategory = STYLE_BOOK_CATEGORIES.find(
( category ) => category.name === 'theme'
);
const themeCategoryExamples = getCategoryExamples(
themeCategory,
getExamples()
exampleThemeBlocks
);

expect( themeCategoryExamples.name ).toEqual( 'theme' );
expect( themeCategoryExamples.subcategories ).toHaveLength(
themeCategory.subcategories.length

const siteIdentity = themeCategoryExamples.subcategories.find(
( subcategory ) => subcategory.name === 'site-identity'
);
expect( siteIdentity ).toEqual( {
title: 'Site Identity',
name: 'site-identity',
examples: [
{
name: 'core/site-logo',
title: 'Site Logo',
category: 'theme',
},
{
name: 'core/site-title',
title: 'Site Title',
category: 'theme',
},
{
name: 'core/site-tagline',
title: 'Site Tagline',
category: 'theme',
},
],
} );

const design = themeCategoryExamples.subcategories.find(
( subcategory ) => subcategory.name === 'design'
);
expect( design ).toEqual( {
title: 'Design',
name: 'design',
examples: [
{
name: 'core/group',
title: 'Group',
category: 'design',
},
],
} );

const posts = themeCategoryExamples.subcategories.find(
( subcategory ) => subcategory.name === 'posts'
);

expect( posts ).toEqual( {
title: 'Posts',
name: 'posts',
examples: [
{
name: 'core/post-terms',
title: 'Post Terms',
category: 'theme',
},
],
} );
} );
} );
} );
15 changes: 1 addition & 14 deletions packages/edit-site/src/components/style-book/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,6 @@ export function getCategoryExamples( categoryDefinition, examples ) {
return {
title: categoryDefinition.title,
name: categoryDefinition.name,
examples: examples.filter( ( example ) => {
return (
! blocksToExclude.includes( example.name ) &&
( example.category === categoryDefinition.name ||
blocksToInclude.includes( example.name ) )
);
} ),
examples: categoryExamples,
};
}

/*
*/

0 comments on commit 021275c

Please sign in to comment.