-
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.
Introduce ExperimentalBlockEditorProvider
This PR introduces `ExperimentalBlockEditorProvider` that prevents mixing experimental editor settings and the public `BlockEditorProvider` component. The actual filtering is handled in a private `__experimentalUpdateSettings` selector in the block-editor store. Experimental settings may still be set via a PHP plugin – limiting this vector would require a separate PR.
- Loading branch information
Showing
31 changed files
with
445 additions
and
143 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
98 changes: 98 additions & 0 deletions
98
packages/block-editor/src/components/provider/test/experimental-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,98 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import { render } from '@testing-library/react'; | ||
/** | ||
* WordPress dependencies | ||
*/ | ||
import { useRegistry } from '@wordpress/data'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { BlockEditorProvider, ExperimentalBlockEditorProvider } from '../'; | ||
import { store as blockEditorStore } from '../../../store'; | ||
|
||
const HasEditorSetting = ( props ) => { | ||
const registry = useRegistry(); | ||
if ( props.setRegistry ) { | ||
props.setRegistry( registry ); | ||
} | ||
return <p>Test.</p>; | ||
}; | ||
|
||
describe( 'BlockEditorProvider', () => { | ||
let registry; | ||
const setRegistry = ( reg ) => { | ||
registry = reg; | ||
}; | ||
beforeEach( () => { | ||
registry = undefined; | ||
} ); | ||
it( 'should strip experimental settings', async () => { | ||
render( | ||
<BlockEditorProvider | ||
settings={ { | ||
__unstableInserterMediaCategories: true, | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</BlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).not.toHaveProperty( | ||
'__unstableInserterMediaCategories' | ||
); | ||
} ); | ||
it( 'should preserve stable settings', async () => { | ||
render( | ||
<BlockEditorProvider | ||
settings={ { | ||
stableSetting: 'https://example.com', | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</BlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( 'stableSetting' ); | ||
} ); | ||
} ); | ||
|
||
describe( 'ExperimentalBlockEditorProvider', () => { | ||
let registry; | ||
const setRegistry = ( reg ) => { | ||
registry = reg; | ||
}; | ||
beforeEach( () => { | ||
registry = undefined; | ||
} ); | ||
it( 'should preserve experimental settings', async () => { | ||
render( | ||
<ExperimentalBlockEditorProvider | ||
settings={ { | ||
__unstableInserterMediaCategories: true, | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</ExperimentalBlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( | ||
'__unstableInserterMediaCategories' | ||
); | ||
} ); | ||
it( 'should preserve stable settings', async () => { | ||
render( | ||
<ExperimentalBlockEditorProvider | ||
settings={ { | ||
stableSetting: 'https://example.com', | ||
} } | ||
> | ||
<HasEditorSetting setRegistry={ setRegistry } /> | ||
</ExperimentalBlockEditorProvider> | ||
); | ||
const settings = registry.select( blockEditorStore ).getSettings(); | ||
expect( settings ).toHaveProperty( 'stableSetting' ); | ||
} ); | ||
} ); |
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
Oops, something went wrong.