Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pinterest Block: Add an e2e test. #14096

Merged
merged 15 commits into from
Dec 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 );
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed this to use the element returned by waitForSelector(), as I'd originally modified waitForSelector() to accept an XPath selector, too (9f62cb1). That's since been reverted, I have no strong feelings either way about this change.

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';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reviewed all of the Core default themes, there was no consistent selector with the level of specificity of #main article.post: sometimes #main existed, sometimes it didn't. Sometimes it was a <div>, sometimes a <main>, sometimes it had role="main" defined. Sometimes it used <article> sometimes a <div>. However, they all use the .post class, given how long this class has been defined, I would expect it to continue into the future.

I don't think the lower specificity is a problem, since it's always loading a single post page: if there's no post, the .post class won't be used anywhere.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

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 }`;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gutenberg removed the aria-label property, and changed their equivalent selector in tests to an XPath selector. I found this to be unreliable, and felt fragile when applied to beta blocks, which have the "Beta" term in their displayed title. It's much more reliable to use the unique name that block defines.

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