|
1 | 1 | /**
|
2 | 2 | * Internal dependencies
|
3 | 3 | */
|
4 |
| -import { getCategoryExamples, getExamples } from '../utils'; |
| 4 | +import { getCategoryExamples } from '../utils'; |
5 | 5 | import { STYLE_BOOK_CATEGORIES } from '../constants';
|
6 | 6 |
|
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 | +]; |
12 | 60 |
|
13 | 61 | 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 |
| - |
26 | 62 | describe( 'getCategoryExamples', () => {
|
27 |
| - it( 'returns category key value pairs', () => { |
| 63 | + it( 'returns theme subcategories examples', () => { |
28 | 64 | const themeCategory = STYLE_BOOK_CATEGORIES.find(
|
29 | 65 | ( category ) => category.name === 'theme'
|
30 | 66 | );
|
31 | 67 | const themeCategoryExamples = getCategoryExamples(
|
32 | 68 | themeCategory,
|
33 |
| - getExamples() |
| 69 | + exampleThemeBlocks |
34 | 70 | );
|
| 71 | + |
35 | 72 | 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' |
38 | 101 | );
|
| 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 | + } ); |
39 | 129 | } );
|
40 | 130 | } );
|
41 | 131 | } );
|
0 commit comments