Skip to content

Commit

Permalink
Using fixtures for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Sep 20, 2024
1 parent 9ff790a commit ed53658
Showing 1 changed file with 112 additions and 22 deletions.
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',
},
],
} );
} );
} );
} );

0 comments on commit ed53658

Please sign in to comment.