Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide AMP Noloading toggle if block does not have specified setting #5574

Merged
merged 5 commits into from
Dec 13, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion assets/src/block-editor/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -411,13 +411,19 @@ AmpLayoutControl.propTypes = {
/**
* Get AMP Noloading toggle control.
*
* @deprecated As of v2.1. Blocks with the `ampNoLoading` attribute will still be able to use the control.
*
* @param {Object} props Props.
*
* @return {ReactElement} Element.
*/
const AmpNoloadingToggle = ( props ) => {
export const AmpNoloadingToggle = ( props ) => {
const { attributes: { ampNoLoading }, setAttributes } = props;

if ( undefined === ampNoLoading ) {
return null;
}

const label = __( 'AMP Noloading', 'amp' );

return (
Expand Down
46 changes: 46 additions & 0 deletions assets/src/block-editor/helpers/test/AmpNoloadingToggle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* External dependencies
*/
import { act } from 'react-dom/test-utils';

/**
* WordPress dependencies
*/
import { render } from '@wordpress/element';

/**
* Internal dependencies
*/
import { AmpNoloadingToggle } from '../';

let container;

describe( 'AmpNoloadingToggle', () => {
beforeEach( () => {
container = document.createElement( 'div' );
document.body.appendChild( container );
} );

afterEach( () => {
document.body.removeChild( container );
container = null;
} );

it( 'should not render if ampNoLoading is undefined', function() {
act( () => {
render( <AmpNoloadingToggle setAttributes={ () => {} } attributes={ {} } />, container );
} );

const selectControl = container.querySelector( 'input' );
expect( selectControl ).toBeNull();
} );

it( 'should render if ampNoLoading is defined', function() {
act( () => {
render( <AmpNoloadingToggle setAttributes={ () => {} } attributes={ { ampNoLoading: true } } />, container );
} );

const selectControl = container.querySelector( 'input' );
expect( selectControl ).not.toBeNull();
} );
} );