Skip to content

Commit

Permalink
Add individual headings to the elements translations (#57472)
Browse files Browse the repository at this point in the history
Update tests to use custom, registered block
  • Loading branch information
ramonjd authored Jan 2, 2024
1 parent f364b68 commit 9e0747e
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ const translationMap = {
link: __( 'Link' ),
button: __( 'Button' ),
heading: __( 'Heading' ),
h1: __( 'H1' ),
h2: __( 'H2' ),
h3: __( 'H3' ),
h4: __( 'H4' ),
h5: __( 'H5' ),
h6: __( 'H6' ),
'settings.color': __( 'Color settings' ),
'settings.typography': __( 'Typography settings' ),
'styles.color': __( 'Colors' ),
Expand Down Expand Up @@ -54,10 +60,11 @@ function getTranslation( key ) {
}

if ( keyArray?.[ 0 ] === 'elements' ) {
const elementName = translationMap[ keyArray[ 1 ] ] || keyArray[ 1 ];
return sprintf(
// translators: %s: element name, e.g., heading button, link, caption.
__( '%s element' ),
translationMap[ keyArray[ 1 ] ]
elementName
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,31 @@
*/
import getGlobalStylesChanges from '../get-global-styles-changes';

jest.mock( '@wordpress/blocks', () => {
return {
...jest.requireActual( '@wordpress/blocks' ),
getBlockTypes: jest.fn( () => [
{
name: 'core/paragraph',
title: 'Test Paragraph',
},
] ),
};
} );
/**
* WordPress dependencies
*/
import {
registerBlockType,
unregisterBlockType,
getBlockTypes,
} from '@wordpress/blocks';

describe( 'getGlobalStylesChanges', () => {
beforeEach( () => {
registerBlockType( 'core/test-fiori-di-zucca', {
save: () => {},
category: 'text',
title: 'Test pumpkin flowers',
edit: () => {},
} );
} );

afterEach( () => {
getBlockTypes().forEach( ( block ) => {
unregisterBlockType( block.name );
} );
} );

const revision = {
id: 10,
styles: {
Expand All @@ -41,6 +53,11 @@ describe( 'getGlobalStylesChanges', () => {
letterSpacing: '37px',
},
},
h3: {
typography: {
lineHeight: '1.2',
},
},
caption: {
color: {
text: 'var(--wp--preset--color--pineapple)',
Expand All @@ -51,7 +68,7 @@ describe( 'getGlobalStylesChanges', () => {
text: 'var(--wp--preset--color--tomato)',
},
blocks: {
'core/paragraph': {
'core/test-fiori-di-zucca': {
color: {
text: '#000000',
},
Expand Down Expand Up @@ -96,6 +113,16 @@ describe( 'getGlobalStylesChanges', () => {
letterSpacing: '37px',
},
},
h3: {
typography: {
lineHeight: '2',
},
},
h6: {
typography: {
lineHeight: '1.2',
},
},
caption: {
typography: {
fontSize: '1.11rem',
Expand All @@ -118,7 +145,7 @@ describe( 'getGlobalStylesChanges', () => {
background: 'var(--wp--preset--color--pumpkin)',
},
blocks: {
'core/paragraph': {
'core/test-fiori-di-zucca': {
color: {
text: '#fff',
},
Expand All @@ -144,8 +171,10 @@ describe( 'getGlobalStylesChanges', () => {
expect( resultA ).toEqual( [
'Colors',
'Typography',
'Test Paragraph block',
'Test pumpkin flowers block',
'H3 element',
'Caption element',
'H6 element',
'Link element',
'Color settings',
] );
Expand All @@ -162,8 +191,8 @@ describe( 'getGlobalStylesChanges', () => {
expect( resultA ).toEqual( [
'Colors',
'Typography',
'Test Paragraph block',
'…and 3 more changes.',
'Test pumpkin flowers block',
'…and 5 more changes.',
] );
} );

Expand Down

1 comment on commit 9e0747e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected in 9e0747e.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/7384953376
📝 Reported issues:

Please sign in to comment.