Skip to content

Commit 021275c

Browse files
committed
Add default category
Using fixtures for tests. Using fixtures for tests.
1 parent 5709016 commit 021275c

File tree

3 files changed

+114
-36
lines changed

3 files changed

+114
-36
lines changed

packages/edit-site/src/components/style-book/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ function StyleBook( {
149149
</div>
150150
) : (
151151
<StyleBookBody
152+
category={ tabs[ 0 ].name }
152153
examples={ examples }
153154
isSelected={ isSelected }
154155
onClick={ onClick }
Lines changed: 112 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,131 @@
11
/**
22
* Internal dependencies
33
*/
4-
import { getCategoryExamples, getExamples } from '../utils';
4+
import { getCategoryExamples } from '../utils';
55
import { STYLE_BOOK_CATEGORIES } from '../constants';
66

7-
/**
8-
* WordPress dependencies
9-
*/
10-
import { getBlockTypes, unregisterBlockType } from '@wordpress/blocks';
11-
import { registerCoreBlocks } from '@wordpress/block-library';
7+
// Fixtures
8+
const exampleThemeBlocks = [
9+
{
10+
name: 'core/post-content',
11+
title: 'Post Content',
12+
category: 'theme',
13+
},
14+
{
15+
name: 'core/post-terms',
16+
title: 'Post Terms',
17+
category: 'theme',
18+
},
19+
{
20+
name: 'core/home-link',
21+
title: 'Home Link',
22+
category: 'design',
23+
},
24+
{
25+
name: 'custom/colors',
26+
title: 'Colors',
27+
category: 'colors',
28+
},
29+
{
30+
name: 'core/site-logo',
31+
title: 'Site Logo',
32+
category: 'theme',
33+
},
34+
{
35+
name: 'core/site-title',
36+
title: 'Site Title',
37+
category: 'theme',
38+
},
39+
{
40+
name: 'core/site-tagline',
41+
title: 'Site Tagline',
42+
category: 'theme',
43+
},
44+
{
45+
name: 'core/group',
46+
title: 'Group',
47+
category: 'design',
48+
},
49+
{
50+
name: 'core/comments-pagination-numbers',
51+
title: 'Comments Page Numbers',
52+
category: 'theme',
53+
},
54+
{
55+
name: 'core/post-featured-image',
56+
title: 'Featured Image',
57+
category: 'theme',
58+
},
59+
];
1260

1361
describe( 'utils', () => {
14-
beforeAll( () => {
15-
// Register all core blocks
16-
registerCoreBlocks();
17-
} );
18-
19-
afterAll( () => {
20-
// Clean up registered blocks
21-
getBlockTypes().forEach( ( block ) => {
22-
unregisterBlockType( block.name );
23-
} );
24-
} );
25-
2662
describe( 'getCategoryExamples', () => {
27-
it( 'returns category key value pairs', () => {
63+
it( 'returns theme subcategories examples', () => {
2864
const themeCategory = STYLE_BOOK_CATEGORIES.find(
2965
( category ) => category.name === 'theme'
3066
);
3167
const themeCategoryExamples = getCategoryExamples(
3268
themeCategory,
33-
getExamples()
69+
exampleThemeBlocks
3470
);
71+
3572
expect( themeCategoryExamples.name ).toEqual( 'theme' );
36-
expect( themeCategoryExamples.subcategories ).toHaveLength(
37-
themeCategory.subcategories.length
73+
74+
const siteIdentity = themeCategoryExamples.subcategories.find(
75+
( subcategory ) => subcategory.name === 'site-identity'
76+
);
77+
expect( siteIdentity ).toEqual( {
78+
title: 'Site Identity',
79+
name: 'site-identity',
80+
examples: [
81+
{
82+
name: 'core/site-logo',
83+
title: 'Site Logo',
84+
category: 'theme',
85+
},
86+
{
87+
name: 'core/site-title',
88+
title: 'Site Title',
89+
category: 'theme',
90+
},
91+
{
92+
name: 'core/site-tagline',
93+
title: 'Site Tagline',
94+
category: 'theme',
95+
},
96+
],
97+
} );
98+
99+
const design = themeCategoryExamples.subcategories.find(
100+
( subcategory ) => subcategory.name === 'design'
38101
);
102+
expect( design ).toEqual( {
103+
title: 'Design',
104+
name: 'design',
105+
examples: [
106+
{
107+
name: 'core/group',
108+
title: 'Group',
109+
category: 'design',
110+
},
111+
],
112+
} );
113+
114+
const posts = themeCategoryExamples.subcategories.find(
115+
( subcategory ) => subcategory.name === 'posts'
116+
);
117+
118+
expect( posts ).toEqual( {
119+
title: 'Posts',
120+
name: 'posts',
121+
examples: [
122+
{
123+
name: 'core/post-terms',
124+
title: 'Post Terms',
125+
category: 'theme',
126+
},
127+
],
128+
} );
39129
} );
40130
} );
41131
} );

packages/edit-site/src/components/style-book/utils.js

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -100,19 +100,6 @@ export function getCategoryExamples( categoryDefinition, examples ) {
100100
return {
101101
title: categoryDefinition.title,
102102
name: categoryDefinition.name,
103-
examples: examples.filter( ( example ) => {
104-
return (
105-
! blocksToExclude.includes( example.name ) &&
106-
( example.category === categoryDefinition.name ||
107-
blocksToInclude.includes( example.name ) )
108-
);
109-
} ),
103+
examples: categoryExamples,
110104
};
111105
}
112-
113-
/*
114-
115-
116-
117-
118-
*/

0 commit comments

Comments
 (0)