Skip to content

Commit

Permalink
Updated tests to test the renamedFeatures object.
Browse files Browse the repository at this point in the history
  • Loading branch information
ramonjd committed Mar 10, 2022
1 parent da8e838 commit 106619c
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions packages/block-editor/src/hooks/test/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ describe( 'addSaveProps', () => {
title: 'block title',
supports: {
spacing: { padding: true },
color: { gradients: true, text: true },
typography: {
fontSize: true,
__experimentalTextTransform: true,
Expand All @@ -134,15 +135,22 @@ describe( 'addSaveProps', () => {
},
};

const applySkipSerialization = ( skipSerialization ) => {
const applySkipSerialization = ( features ) => {
const updatedSettings = { ...blockSettings };
updatedSettings.supports.typography.__experimentalSkipSerialization = skipSerialization;

Object.keys( features ).forEach( ( key ) => {
updatedSettings.supports[ key ].__experimentalSkipSerialization =
features[ key ];
} );
return updatedSettings;
};

const attributes = {
style: {
color: {
text: '#d92828',
gradient:
'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,13,13) 46%,rgb(155,81,224) 100%)',
},
spacing: { padding: '10px' },
typography: {
fontSize: '1rem',
Expand All @@ -156,6 +164,9 @@ describe( 'addSaveProps', () => {
const extraProps = addSaveProps( {}, blockSettings, attributes );

expect( extraProps.style ).toEqual( {
background:
'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,13,13) 46%,rgb(155,81,224) 100%)',
color: '#d92828',
padding: '10px',
fontSize: '1rem',
textDecoration: 'underline',
Expand All @@ -164,20 +175,28 @@ describe( 'addSaveProps', () => {
} );

it( 'should skip serialization of entire feature set if flag is true', () => {
const settings = applySkipSerialization( true );
const settings = applySkipSerialization( {
typography: true,
} );
const extraProps = addSaveProps( {}, settings, attributes );

expect( extraProps.style ).toEqual( { padding: '10px' } );
expect( extraProps.style ).toEqual( {
background:
'linear-gradient(135deg,rgb(6,147,227) 0%,rgb(223,13,13) 46%,rgb(155,81,224) 100%)',
color: '#d92828',
padding: '10px',
} );
} );

it( 'should skip serialization of individual features if flag is an array', () => {
const settings = applySkipSerialization( [
'textDecoration',
'textTransform',
] );
const settings = applySkipSerialization( {
color: [ 'gradient' ],
typography: [ 'textDecoration', 'textTransform' ],
} );
const extraProps = addSaveProps( {}, settings, attributes );

expect( extraProps.style ).toEqual( {
color: '#d92828',
padding: '10px',
fontSize: '1rem',
} );
Expand Down

0 comments on commit 106619c

Please sign in to comment.