From 1270436bb4b3c218c365dda7049d9bd1c6f3b3e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Grzegorz=20=28Greg=29=20Zi=C3=B3=C5=82kowski?= Date: Fri, 21 Feb 2020 06:05:05 +0100 Subject: [PATCH] E2E tests: Block variations (#20286) * E2E tests: Block variations * E2E tests: Implement test for block variations --- .../e2e-tests/plugins/block-variations.php | 28 ++++++ .../plugins/block-variations/index.js | 69 +++++++++++++ .../specs/editor/plugins/block-variations.js | 96 +++++++++++++++++++ 3 files changed, 193 insertions(+) create mode 100644 packages/e2e-tests/plugins/block-variations.php create mode 100644 packages/e2e-tests/plugins/block-variations/index.js create mode 100644 packages/e2e-tests/specs/editor/plugins/block-variations.js diff --git a/packages/e2e-tests/plugins/block-variations.php b/packages/e2e-tests/plugins/block-variations.php new file mode 100644 index 00000000000000..25280868088843 --- /dev/null +++ b/packages/e2e-tests/plugins/block-variations.php @@ -0,0 +1,28 @@ + { + beforeAll( async () => { + await activatePlugin( 'gutenberg-test-block-variations' ); + } ); + + beforeEach( async () => { + await createNewPost(); + } ); + + afterAll( async () => { + await deactivatePlugin( 'gutenberg-test-block-variations' ); + } ); + + const expectInserterItem = async ( + blockName, + blockTitle, + variationName = null + ) => { + const inserterItemSelector = [ + '.editor-block-list-item', + blockName.replace( 'core/', '' ), + variationName, + ] + .filter( Boolean ) + .join( '-' ); + const inserterItem = await page.$( inserterItemSelector ); + expect( inserterItem ).toBeDefined(); + expect( + await inserterItem.$x( `//span[text()="${ blockTitle }"]` ) + ).toHaveLength( 1 ); + }; + + test( 'Search for the overriden default Quote block', async () => { + await searchForBlock( 'Quote' ); + + expect( await page.$( '.editor-block-list-item-quote' ) ).toBeNull(); + expectInserterItem( 'quote', 'Large Quote', 'large' ); + } ); + + test( 'Insert the overriden default Quote block variation', async () => { + await insertBlock( 'Large Quote' ); + + expect( + await page.$( + '.wp-block[data-type="core/quote"] blockquote.is-style-large' + ) + ).toBeDefined(); + } ); + + test( 'Search for the Paragraph block with 2 additioanl variations', async () => { + await searchForBlock( 'Paragraph' ); + + expectInserterItem( 'core/paragraph', 'Paragraph' ); + expectInserterItem( 'core/paragraph', 'Success Message', 'success' ); + expectInserterItem( 'core/paragraph', 'Warning Message', 'warning' ); + } ); + + test( 'Insert the Success Message block variation', async () => { + await insertBlock( 'Success Message' ); + + const successMessageBlock = await page.$( + '.wp-block[data-type="core/paragraph"]' + ); + expect( successMessageBlock ).toBeDefined(); + expect( + await successMessageBlock.$eval( + 'p.has-vivid-green-cyan-background-color', + ( node ) => node.innerText + ) + ).toBe( 'This is a success message!' ); + } ); + test( 'Pick the additional variation in the inserted Columns block', async () => { + await insertBlock( 'Columns' ); + + const fourColumnsVariation = await page.waitForSelector( + '.wp-block[data-type="core/columns"] .block-editor-block-variation-picker__variation[aria-label="Four columns"]' + ); + await fourColumnsVariation.click(); + expect( + await page.$$( + '.wp-block[data-type="core/columns"] .wp-block[data-type="core/column"]' + ) + ).toHaveLength( 4 ); + } ); +} );