Skip to content

Commit

Permalink
Test AmpNoloadingToggle
Browse files Browse the repository at this point in the history
  • Loading branch information
pierlon committed Dec 11, 2020
1 parent e68f9d5 commit b390973
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions assets/src/block-editor/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,10 @@ AmpLayoutControl.propTypes = {
*
* @return {ReactElement} Element.
*/
const AmpNoloadingToggle = ( props ) => {
export const AmpNoloadingToggle = ( props ) => {
const { attributes: { ampNoLoading }, setAttributes } = props;

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

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();
} );
} );

0 comments on commit b390973

Please sign in to comment.