-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Global Styles: Fix block-level global styles color panels (#34293)
Check if block color support have been explicitly opted out BackgroundColor and color are opt-out block supports: they're enabled if there's support for any color unless the block opts-out from them explicitly. Global styles UI panels were't respecting this opt out process, which is why we add logic to validate whether or not a block has turned off background color and color supports.
- Loading branch information
Showing
3 changed files
with
153 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
packages/edit-site/src/components/editor/test/global-styles-provider.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { dispatch } from '@wordpress/data'; | ||
|
||
/** | ||
* External dependencies | ||
*/ | ||
import { mount } from 'enzyme'; | ||
import { act } from 'react-dom/test-utils'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import GlobalStylesProvider, { | ||
useGlobalStylesContext, | ||
} from '../global-styles-provider'; | ||
|
||
const settings = { | ||
styles: [ | ||
{ | ||
css: 'body {\n\tmargin: 0;\n\tpadding: 0;\n}', | ||
baseURL: 'http://localhost:4759/ponyfill.css', | ||
}, | ||
], | ||
__experimentalGlobalStylesBaseStyles: {}, | ||
}; | ||
|
||
const generateCoverBlockType = ( colorSupports ) => { | ||
return { | ||
name: 'core/cover', | ||
supports: { | ||
color: colorSupports, | ||
}, | ||
}; | ||
}; | ||
|
||
const FakeCmp = () => { | ||
const globalStylesContext = useGlobalStylesContext(); | ||
const coverBlockSupports = | ||
globalStylesContext.blocks[ 'core/cover' ].supports; | ||
|
||
return <div supports={ coverBlockSupports }></div>; | ||
}; | ||
|
||
const generateWrapper = () => { | ||
return mount( | ||
<GlobalStylesProvider | ||
baseStyles={ settings.__experimentalGlobalStylesBaseStyles } | ||
> | ||
<FakeCmp /> | ||
</GlobalStylesProvider> | ||
); | ||
}; | ||
|
||
describe( 'global styles provider', () => { | ||
beforeAll( () => { | ||
dispatch( 'core/edit-site' ).updateSettings( settings ); | ||
} ); | ||
|
||
describe( 'when a block enables color support', () => { | ||
describe( 'and disables background color support', () => { | ||
it( 'still enables text color support', () => { | ||
act( () => { | ||
dispatch( 'core/blocks' ).addBlockTypes( | ||
generateCoverBlockType( { | ||
link: true, | ||
background: false, | ||
} ) | ||
); | ||
} ); | ||
|
||
const wrapper = generateWrapper(); | ||
const actual = wrapper | ||
.findWhere( ( ele ) => Boolean( ele.prop( 'supports' ) ) ) | ||
.prop( 'supports' ); | ||
expect( actual ).not.toContain( 'backgroundColor' ); | ||
expect( actual ).toContain( 'color' ); | ||
|
||
act( () => { | ||
dispatch( 'core/blocks' ).removeBlockTypes( 'core/cover' ); | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'and both text color and background color support are disabled', () => { | ||
it( 'disables text color and background color support', () => { | ||
act( () => { | ||
dispatch( 'core/blocks' ).addBlockTypes( | ||
generateCoverBlockType( { | ||
text: false, | ||
background: false, | ||
} ) | ||
); | ||
} ); | ||
|
||
const wrapper = generateWrapper(); | ||
const actual = wrapper | ||
.findWhere( ( ele ) => Boolean( ele.prop( 'supports' ) ) ) | ||
.prop( 'supports' ); | ||
expect( actual ).not.toContain( 'backgroundColor' ); | ||
expect( actual ).not.toContain( 'color' ); | ||
|
||
act( () => { | ||
dispatch( 'core/blocks' ).removeBlockTypes( 'core/cover' ); | ||
} ); | ||
} ); | ||
} ); | ||
|
||
describe( 'and text color and background color supports are omitted', () => { | ||
it( 'still enables both text color and background color supports', () => { | ||
act( () => { | ||
dispatch( 'core/blocks' ).addBlockTypes( | ||
generateCoverBlockType( { link: true } ) | ||
); | ||
} ); | ||
|
||
const wrapper = generateWrapper(); | ||
const actual = wrapper | ||
.findWhere( ( ele ) => Boolean( ele.prop( 'supports' ) ) ) | ||
.prop( 'supports' ); | ||
expect( actual ).toContain( 'backgroundColor' ); | ||
expect( actual ).toContain( 'color' ); | ||
|
||
act( () => { | ||
dispatch( 'core/blocks' ).removeBlockTypes( 'core/cover' ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); | ||
} ); |