Skip to content

Commit

Permalink
Global styles: add background to global styles changes output (#60229)
Browse files Browse the repository at this point in the history
* Adding "background" top-level styles to the possible change list values. Updates tests.


Co-authored-by: ramonjd <ramonopoly@git.wordpress.org>
Co-authored-by: andrewserong <andrewserong@git.wordpress.org>
  • Loading branch information
3 people committed Mar 27, 2024
1 parent e30a12b commit 689d529
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const translationMap = {
'settings.typography': __( 'Typography' ),
'styles.color': __( 'Colors' ),
'styles.spacing': __( 'Spacing' ),
'styles.background': __( 'Background' ),
'styles.typography': __( 'Typography' ),
};
const getBlockNames = memoize( () =>
Expand Down Expand Up @@ -126,6 +127,7 @@ export function getGlobalStylesChangelist( next, previous ) {
const changedValueTree = deepCompare(
{
styles: {
background: next?.styles?.background,
color: next?.styles?.color,
typography: next?.styles?.typography,
spacing: next?.styles?.spacing,
Expand All @@ -136,6 +138,7 @@ export function getGlobalStylesChangelist( next, previous ) {
},
{
styles: {
background: previous?.styles?.background,
color: previous?.styles?.color,
typography: previous?.styles?.typography,
spacing: previous?.styles?.spacing,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ import {
describe( 'getGlobalStylesChanges and utils', () => {
const next = {
styles: {
background: {
backgroundImage: {
url: 'https://example.com/image.jpg',
source: 'file',
},
backgroundSize: 'contain',
backgroundPosition: '30% 30%',
backgroundRepeat: 'no-repeat',
},
typography: {
fontSize: 'var(--wp--preset--font-size--potato)',
fontStyle: 'normal',
Expand Down Expand Up @@ -84,6 +93,15 @@ describe( 'getGlobalStylesChanges and utils', () => {
};
const previous = {
styles: {
background: {
backgroundImage: {
url: 'https://example.com/image_new.jpg',
source: 'file',
},
backgroundSize: 'contain',
backgroundPosition: '40% 77%',
backgroundRepeat: 'repeat',
},
typography: {
fontSize: 'var(--wp--preset--font-size--fungus)',
fontStyle: 'normal',
Expand Down Expand Up @@ -195,7 +213,7 @@ describe( 'getGlobalStylesChanges and utils', () => {
it( 'returns a list of changes', () => {
const result = getGlobalStylesChanges( next, previous );
expect( result ).toEqual( [
'Colors, Typography styles.',
'Background, Colors, Typography styles.',
'Test pumpkin flowers block.',
'H3, Caption, H6, Link elements.',
'Color, Typography settings.',
Expand All @@ -204,10 +222,10 @@ describe( 'getGlobalStylesChanges and utils', () => {

it( 'returns a list of truncated changes', () => {
const resultA = getGlobalStylesChanges( next, previous, {
maxResults: 3,
maxResults: 4,
} );
expect( resultA ).toEqual( [
'Colors, Typography styles.',
'Background, Colors, Typography styles.',
'Test pumpkin flowers block.',
] );
} );
Expand Down Expand Up @@ -254,6 +272,7 @@ describe( 'getGlobalStylesChanges and utils', () => {
const resultA = getGlobalStylesChangelist( next, previous );

expect( resultA ).toEqual( [
[ 'styles', 'Background' ],
[ 'styles', 'Colors' ],
[ 'styles', 'Typography' ],
[ 'blocks', 'Test pumpkin flowers' ],
Expand Down

0 comments on commit 689d529

Please sign in to comment.