Skip to content

Commit

Permalink
Make tests resilient against transforms added by plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgefilipecosta committed Mar 28, 2019
1 parent 2e6199d commit c173dfe
Showing 1 changed file with 44 additions and 34 deletions.
78 changes: 44 additions & 34 deletions packages/e2e-tests/specs/block-transforms.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
flatMap,
map,
mapValues,
noop,
pickBy,
some,
} from 'lodash';
Expand Down Expand Up @@ -136,53 +137,62 @@ describe( 'Block transforms', () => {
}
} );

it( 'should contain the expected transforms', async () => {
const transforms = mapValues(
pickBy(
transformStructure,
( { availableTransforms } ) => availableTransforms,
),
( { availableTransforms, originalBlock } ) => {
return { originalBlock, availableTransforms };
}
);
expect(
transforms
).toEqual( EXPECTED_TRANSFORMS );
} );

describe( 'correctly transform', () => {
beforeAll( async () => {
await createNewPost();
} );

beforeEach( async () => {
await setPostContent( '' );
await page.click( '.editor-post-title .editor-post-title__block' );
if ( ! process.env.POPULAR_PLUGINS ) {
it( 'should contain the expected transforms', async () => {
const transforms = mapValues(
pickBy(
transformStructure,
( { availableTransforms } ) => availableTransforms,
),
( { availableTransforms, originalBlock } ) => {
return { originalBlock, availableTransforms };
}
);
expect(
transforms
).toEqual( EXPECTED_TRANSFORMS );
} );
}

describe( 'correctly transform', () => {
const testTable = flatMap(
EXPECTED_TRANSFORMS,
( { originalBlock, availableTransforms }, fixture ) => (
map(
availableTransforms,
( distinationBlock ) => ( [
( destinationBlock ) => ( [
originalBlock,
fixture,
distinationBlock,
destinationBlock,
] )
)
)
);

it.each( testTable )(
'block %s in fixture %s into the %s block',
async ( originalBlock, fixture, distinationBlock ) => {
const { content } = transformStructure[ fixture ];
expect(
await getTransformResult( content, distinationBlock )
).toMatchSnapshot();
}
);
if ( ! process.env.POPULAR_PLUGINS ) {
beforeAll( async () => {
await createNewPost();
} );

beforeEach( async () => {
await setPostContent( '' );
await page.click( '.editor-post-title .editor-post-title__block' );
} );

it.each( testTable )(
'block %s in fixture %s into the %s block',
async ( originalBlock, fixture, destinationBlock ) => {
const { content } = transformStructure[ fixture ];
expect(
await getTransformResult( content, destinationBlock )
).toMatchSnapshot();
}
);
} else {
it.skip.each( testTable )(
'block %s in fixture %s into the %s block',
noop
);
}
} );
} );

0 comments on commit c173dfe

Please sign in to comment.