Skip to content

Commit

Permalink
Pinterest Block: Add an e2e test. (#14096)
Browse files Browse the repository at this point in the history
  • Loading branch information
pento authored Dec 2, 2019
1 parent b23a66d commit 9432874
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 13 deletions.
1 change: 1 addition & 0 deletions tests/e2e/bin/setup-e2e-travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ PHP
wp --allow-root config set WP_DEBUG true --raw --type=constant
wp --allow-root config set WP_DEBUG_LOG true --raw --type=constant
wp --allow-root config set WP_DEBUG_DISPLAY false --raw --type=constant
wp --allow-root config set JETPACK_BETA_BLOCKS true --raw --type=constant

# NOTE: Force classic connection flow
# https://github.com/Automattic/jetpack/pull/13288
Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/lib/blocks/mailchimp.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,17 @@ import ConnectionsPage from '../pages/wpcom/connections';

export default class MailchimpBlock {
constructor( block, page ) {
this.blockName = MailchimpBlock.name();
this.blockTitle = MailchimpBlock.title();
this.block = block;
this.page = page;
this.blockSelector = '#block-' + block.clientId;
}

static name() {
return 'mailchimp';
}

static title() {
return 'Mailchimp';
}

Expand Down
49 changes: 49 additions & 0 deletions tests/e2e/lib/blocks/pinterest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* Internal dependencies
*/
import { waitForSelector, waitAndClick, waitAndType } from '../page-helper';

export default class PinterestBlock {
constructor( block, page ) {
this.blockTitle = PinterestBlock.title();
this.block = block;
this.page = page;
this.blockSelector = '#block-' + block.clientId;
}

static name() {
return 'pinterest';
}

static title() {
return 'Pinterest';
}

static embedUrl() {
return 'https://www.pinterest.com/pin/180003316347175596/';
}

async addEmbed() {
const inputSelector = this.getSelector( '.components-placeholder__input' );
const descriptionSelector = this.getSelector( "button[type='submit']" );

await waitAndClick( this.page, inputSelector );
await waitAndType( this.page, inputSelector, PinterestBlock.embedUrl() );

await waitAndClick( this.page, descriptionSelector );
}

getSelector( selector ) {
return `${ this.blockSelector } ${ selector }`;
}

/**
* Checks whether block is rendered on frontend
* @param {Page} page Puppeteer page instance
*/
static async isRendered( page ) {
const containerSelector = `.entry-content a[data-pin-do='embedPin'][href='${ PinterestBlock.embedUrl() }']`;

await waitForSelector( page, containerSelector );
}
}
6 changes: 5 additions & 1 deletion tests/e2e/lib/blocks/simple-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import { waitAndType, waitAndClick, waitForSelector } from '../page-helper';

export default class SimplePaymentBlock {
constructor( block, page ) {
this.blockName = SimplePaymentBlock.name();
this.blockTitle = SimplePaymentBlock.title();
this.block = block;
this.page = page;
this.blockSelector = '#block-' + block.clientId;
}

static name() {
return 'simple-payments';
}

static title() {
return 'Simple Payments';
}

Expand Down
6 changes: 5 additions & 1 deletion tests/e2e/lib/blocks/word-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ import { clickBlockToolbarButton } from '@wordpress/e2e-test-utils';

export default class WordAdsBlock {
constructor( block, page ) {
this.blockName = WordAdsBlock.name();
this.blockTitle = WordAdsBlock.title();
this.block = block;
this.page = page;
this.blockSelector = '#block-' + block.clientId;
}

static name() {
return 'wordads';
}

static title() {
return 'Ad';
}

Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/lib/page-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export async function waitForSelector( page, selector, options = {} ) {
* @param {Object} options Custom options to modify function behavior.
*/
export async function waitAndClick( page, selector, options = { visible: true } ) {
await waitForSelector( page, selector, options );
return await page.click( selector, options );
const element = await waitForSelector( page, selector, options );
return await element.click( options );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/lib/pages/postFrontend.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { waitAndClick, waitForSelector } from '../page-helper';

export default class PostFrontendPage extends Page {
constructor( page ) {
const expectedSelector = '#main article.post';
const expectedSelector = '.post';
super( page, { expectedSelector } );
}

Expand Down
6 changes: 3 additions & 3 deletions tests/e2e/lib/pages/wp-admin/block-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ export default class BlockEditorPage extends Page {
super( page, { expectedSelector, url } );
}

async insertBlock( blockName ) {
await searchForBlock( blockName );
const blockIconSelector = `.editor-inserter__menu button[aria-label*='${ blockName }']`;
async insertBlock( blockName, blockTitle ) {
await searchForBlock( blockTitle );
const blockIconSelector = `.editor-block-list-item-jetpack-${ blockName }`;
const jetpackPanelSelector = '.components-panel__body .jetpack-logo';
await scrollIntoView( this.page, jetpackPanelSelector );
await waitAndClick( this.page, blockIconSelector );
Expand Down
3 changes: 2 additions & 1 deletion tests/e2e/lib/pages/wpcom/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export default class ConnectionsPage extends Page {
}

async connectMailchimp() {
const mailchimpConnectSelector = 'div.mailchimp .foldable-card__summary button:not([disabled])';
const mailchimpConnectSelector =
'div.mailchimp .foldable-card__summary-expanded button:not([disabled])';
const mcPopupPage = await clickAndWaitForNewPage( this.page, mailchimpConnectSelector );

// MC Login pop-up page. TODO: maybe extract to a new page
Expand Down
33 changes: 30 additions & 3 deletions tests/e2e/specs/pro-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { connectThroughWPAdminIfNeeded } from '../lib/flows/jetpack-connect';
import { resetWordpressInstall, getNgrokSiteUrl, activateModule } from '../lib/utils-helper';
import SimplePaymentBlock from '../lib/blocks/simple-payments';
import WordAdsBlock from '../lib/blocks/word-ads';
import PinterestBlock from '../lib/blocks/pinterest';

describe( 'Paid blocks', () => {
beforeAll( async () => {
Expand All @@ -27,7 +28,10 @@ describe( 'Paid blocks', () => {
describe( 'Mailchimp Block', () => {
it( 'Can publish a post with a Mailchimp Block', async () => {
const blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock( MailchimpBlock.name() );
const blockInfo = await blockEditor.insertBlock(
MailchimpBlock.name(),
MailchimpBlock.title()
);

const mcBlock = new MailchimpBlock( blockInfo, page );
await mcBlock.connect();
Expand All @@ -44,7 +48,10 @@ describe( 'Paid blocks', () => {
describe( 'Simple Payment', () => {
it( 'Can publish a post with a Simple Payments block', async () => {
const blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock( SimplePaymentBlock.name() );
const blockInfo = await blockEditor.insertBlock(
SimplePaymentBlock.name(),
SimplePaymentBlock.title()
);

const spBlock = new SimplePaymentBlock( blockInfo, page );
await spBlock.fillDetails();
Expand All @@ -61,7 +68,7 @@ describe( 'Paid blocks', () => {
describe( 'WordAds block', () => {
it( 'Can publish a post with a WordAds block', async () => {
const blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock( WordAdsBlock.name() );
const blockInfo = await blockEditor.insertBlock( WordAdsBlock.name(), WordAdsBlock.title() );

const adBlock = new WordAdsBlock( blockInfo, page );
await adBlock.switchFormat( 3 ); // switch to Wide Skyscraper ad format
Expand All @@ -74,4 +81,24 @@ describe( 'Paid blocks', () => {
await frontend.isRenderedBlockPresent( WordAdsBlock );
} );
} );

describe( 'Pinterest block', () => {
it( 'Can publish a post with a Pinterest block', async () => {
const blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock(
PinterestBlock.name(),
PinterestBlock.title()
);

const pinterestBlock = new PinterestBlock( blockInfo, page );
await pinterestBlock.addEmbed();

await blockEditor.focus();
await blockEditor.publishPost();
await blockEditor.viewPost();

const frontend = await PostFrontendPage.init( page );
await frontend.isRenderedBlockPresent( PinterestBlock );
} );
} );
} );

0 comments on commit 9432874

Please sign in to comment.