Skip to content

Commit

Permalink
Improve Features block stability through transforms testing (#1189)
Browse files Browse the repository at this point in the history
* add features block transform tests

* remove extra imports
  • Loading branch information
AnthonyLedesma authored and jrtashjian committed Dec 11, 2019
1 parent 79840ce commit 9acc7b2
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/blocks/features/test/transforms.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* External dependencies
*/
import { registerBlockType } from '@wordpress/blocks';

/**
* Internal dependencies.
*/
import * as helpers from '../../../../.dev/tests/jest/helpers';
import { name, settings } from '../index';

describe( 'coblocks/features transforms', () => {
beforeAll( () => {
// Register the block.
registerBlockType( name, { category: 'common', ...settings } );
} );

it( 'should transform when :feature prefix is seen', () => {
const block = helpers.performPrefixTransformation( name, ':feature', ':feature' );
expect( block.isValid ).toBe( true );
expect( block.name ).toBe( name );
expect( block.attributes.columns ).toBe( 1 ); // should be single column.
} );

// Should allow transform when prefixed with 1-3 colons.
for ( let i = 1; i <= 3; i++ ) {
const prefix = Array( i + 1 ).join( ':' ) + 'features';
it( `should transform when ${ prefix } prefix is seen`, () => {
const block = helpers.performPrefixTransformation( name, prefix, prefix );
expect( block.isValid ).toBe( true );
expect( block.name ).toBe( name );
expect( block.attributes.columns ).toBe( Math.max( i, 2 ) ); // should be 2 minimum columns or 3 max.
} );
}
} );

0 comments on commit 9acc7b2

Please sign in to comment.