Skip to content

Commit

Permalink
Fixes for free-blocks and pro-blocks tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
adimoldovan committed Nov 16, 2020
1 parent a562672 commit 3230cd4
Show file tree
Hide file tree
Showing 15 changed files with 76 additions and 77 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ yarn-error.log
phpcs.xml
/modules/**/*.min.css.map
e2e_tunnels.txt
plan-data.json
plan-data.txt
jetpack_private_options.txt

Expand Down
6 changes: 2 additions & 4 deletions tests/e2e/lib/blocks/eventbrite.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import { waitForSelector } from '../page-helper';

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

Expand All @@ -28,7 +27,6 @@ export default class EventbriteBlock {
const inputSelector = this.getSelector( '.components-placeholder__input' );
const descriptionSelector = this.getSelector( "button[type='submit']" );

await page.click( inputSelector );
await page.type( inputSelector, this.embedUrl() );
await page.click( descriptionSelector );
await waitForSelector( this.page, '.wp-block-jetpack-eventbrite .components-sandbox' );
Expand Down
40 changes: 26 additions & 14 deletions tests/e2e/lib/blocks/mailchimp.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
/**
* Internal dependencies
*/
import { clickAndWaitForNewPage, waitForSelector } from '../page-helper';
import { waitForSelector } from '../page-helper';
import LoginPage from '../pages/wpcom/login';
import ConnectionsPage from '../pages/wpcom/connections';
import logger from '../logger';
import { getNgrokSiteUrl } from '../utils-helper';

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

static name() {
Expand All @@ -33,14 +33,25 @@ export default class MailchimpBlock {
*/
async connect( isLoggedIn = true ) {
const setupFormSelector = this.getSelector( "a[href*='calypso-marketing-connections']" );
const formSelector = await waitForSelector( this.page, setupFormSelector );
const hrefProperty = await formSelector.getProperty( 'href' );
const connectionsUrl = await hrefProperty.jsonValue();
const loginTab = await clickAndWaitForNewPage( this.page, setupFormSelector );
global.page = loginTab;
// const formSelector = await waitForSelector(this.page, setupFormSelector);
// const hrefProperty = await formSelector.getProperty('href');
// const connectionsUrl = await hrefProperty.jsonValue();

// hrefProperty.jsonValue() is not pointing to the right site and next steps will fail
const connectionsUrl = `https://wordpress.com/marketing/connections/${ getNgrokSiteUrl().replace(
'https://',
''
) }`;

await this.page.click( setupFormSelector );
const wpComTab = await page.waitForEvent( 'popup' );
await wpComTab.bringToFront();
await wpComTab.goto( connectionsUrl );

global.page = wpComTab;

if ( ! isLoggedIn ) {
await ( await LoginPage.init( loginTab ) ).login( 'defaultUser' );
await ( await LoginPage.init( wpComTab ) ).login( 'defaultUser' );
}

// Hacky way to force-sync Publicize activation. The first attempt is always get redirected to stats page.
Expand All @@ -52,25 +63,26 @@ export default class MailchimpBlock {
while ( ! loaded ) {
try {
count++;
await ConnectionsPage.init( loginTab );
await ConnectionsPage.init( wpComTab );
loaded = true;
} catch ( e ) {
logger.info(
'ConnectionsPage is not available yet. Attempt: ' + count,
' URL: ' + connectionsUrl
);
await loginTab.goto( connectionsUrl, { timeout: 120000 } );
await wpComTab.goto( connectionsUrl, { timeout: 120000 } );
if ( count > 9 ) {
throw new Error( 'ConnectionsPage is not available is not available after 10th attempt' );
}
}
}

await loginTab.reload( { waitFor: 'networkidle' } );
await wpComTab.reload( { waitFor: 'networkidle' } );

await ( await ConnectionsPage.init( loginTab ) ).selectMailchimpList();
await ( await ConnectionsPage.init( wpComTab ) ).selectMailchimpList();

global.page = this.page;

const reCheckSelector = this.getSelector( 'button.is-link' );
await page.click( reCheckSelector );
}
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/lib/blocks/pinterest.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import { waitForSelector } from '../page-helper';

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

Expand All @@ -27,8 +26,6 @@ export default class PinterestBlock {
async addEmbed() {
const inputSelector = this.getSelector( '.components-placeholder__input' );
const descriptionSelector = this.getSelector( "button[type='submit']" );

await page.click( inputSelector );
await page.type( inputSelector, this.embedUrl() );
await page.click( descriptionSelector );
await waitForSelector( this.page, '.wp-block-jetpack-pinterest .components-sandbox' );
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/lib/blocks/simple-payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@
import { waitForSelector } from '../page-helper';

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

static name() {
Expand Down
5 changes: 2 additions & 3 deletions tests/e2e/lib/blocks/word-ads.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ import { waitForSelector } from '../page-helper';
import { clickBlockToolbarButton } from '@wordpress/e2e-test-utils';

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

static name() {
Expand Down
19 changes: 8 additions & 11 deletions tests/e2e/lib/pages/wp-admin/block-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import Page from '../page';
/**
* WordPress dependencies
*/
import { getAllBlocks, searchForBlock } from '@wordpress/e2e-test-utils';
import { scrollIntoView, waitForSelector } from '../../page-helper';
import { searchForBlock } from '@wordpress/e2e-test-utils';
import { waitForSelector } from '../../page-helper';
import { getNgrokSiteUrl } from '../../utils-helper';

export default class BlockEditorPage extends Page {
Expand Down Expand Up @@ -36,17 +36,14 @@ export default class BlockEditorPage extends Page {

async insertBlock( blockName, blockTitle ) {
await searchForBlock( blockTitle );
const blockIconSelector = `.editor-block-list-item-jetpack-${ blockName }`;
await scrollIntoView( this.page, blockIconSelector );

await page.click( blockIconSelector );
const blockInfo = await this.getInsertedBlock();
return blockInfo;
await page.click( `.editor-block-list-item-jetpack-${ blockName }` );
return await this.getInsertedBlock( blockName );
}

async getInsertedBlock() {
const blocks = await getAllBlocks();
return blocks[ blocks.length - 1 ];
async getInsertedBlock( blockName ) {
return ( await page.waitForSelector( `div[data-type='jetpack/${ blockName }']` ) ).getAttribute(
'data-block'
);
}

async publishPost() {
Expand Down
7 changes: 2 additions & 5 deletions tests/e2e/lib/pages/wpcom/connections.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,8 @@ export default class ConnectionsPage extends Page {
}

// WPCOM Connections page
await this.page.waitForSelector( mcOptionXpathSelector );

const optionHandle = ( await this.page.$$( `xpath=${ mcOptionXpathSelector }` ) )[ 0 ];
const optionValue = await ( await optionHandle.getProperty( 'value' ) ).jsonValue();
await this.page.select( marketingSelectSelector, optionValue );
await this.page.waitForSelector( mcOptionXpathSelector, { state: 'attached' } );
await page.selectOption( marketingSelectSelector, { label: mailchimpList } );

await this.page.waitForSelector( successNoticeSelector );
await this.page.close();
Expand Down
4 changes: 2 additions & 2 deletions tests/e2e/lib/plan-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ export async function persistPlanData( planType = 'jetpack_complete' ) {
const siteId = await getSiteId();
const planData = getPlanData( siteId, siteUrl, planType );

fs.writeFileSync( 'plan-data.txt', JSON.stringify( planData ) );
fs.writeFileSync( 'plan-data.json', JSON.stringify( planData ) );

const cmd = `wp option update ${ planDataOption } < plan-data.txt`;
const cmd = `wp option update ${ planDataOption } < plan-data.json`;
await execWpCommand( cmd );
}

Expand Down
13 changes: 8 additions & 5 deletions tests/e2e/lib/setup-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -247,21 +247,24 @@ catchBeforeAll( async () => {
await setupBrowser();

// Handles not saved changed dialog in block editor
// await enablePageDialogAccept();
observeConsoleLogging();

page.on( 'dialog', async dialog => {
await dialog.accept();
} );

const url = await tunnelManager.create( process.env.SKIP_CONNECT );
global.tunnelUrl = url;
await maybePreConnect();
} );

beforeEach( async () => {
await setupBrowser();
} );

afterAll( async () => {
if ( captureVideo ) {
await video.stop();
}
await tunnelManager.close();
} );

afterEach( async () => {
await setupBrowser();
} );
2 changes: 0 additions & 2 deletions tests/e2e/lib/tunnel-manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ export default class TunnelManager {
* @param {boolean} oneOff If the tunnel should be reused.
*/
async create( oneOff = false ) {
logger.info( '>> Creating a tunnel' );

const tunnelConfig = this.getConfig( oneOff );

await this.newTunnel( tunnelConfig );
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/lib/utils-helper.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { execSync, exec } from 'child_process';
import { exec, execSync } from 'child_process';
import config from 'config';
import logger from './logger';

Expand Down
8 changes: 4 additions & 4 deletions tests/e2e/specs/free-blocks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ describe( 'Free blocks', () => {

await step( 'Can visit the block editor and add a Pinterest block', async () => {
blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock(
const blockId = await blockEditor.insertBlock(
PinterestBlock.name(),
PinterestBlock.title()
);

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

Expand All @@ -46,12 +46,12 @@ describe( 'Free blocks', () => {

await step( 'Can visit the block editor and add a Eventbrite block', async () => {
blockEditor = await BlockEditorPage.visit( page );
const blockInfo = await blockEditor.insertBlock(
const blockId = await blockEditor.insertBlock(
EventbriteBlock.name(),
EventbriteBlock.title()
);

const eventbriteBlock = new EventbriteBlock( blockInfo, page, eventId );
const eventbriteBlock = new EventbriteBlock( blockId, page, eventId );
await eventbriteBlock.addEmbed();
} );

Expand Down
16 changes: 7 additions & 9 deletions tests/e2e/specs/plugin-updater.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import { catchBeforeAll, step } from '../lib/setup-env';
import { connectThroughWPAdminIfNeeded } from '../lib/flows/jetpack-connect';
import {
execWpCommand,
prepareUpdaterTest,
getNgrokSiteUrl,
prepareUpdaterTest,
resetWordpressInstall,
execMultipleWpCommands,
} from '../lib/utils-helper';
import Sidebar from '../lib/pages/wp-admin/sidebar';
import PluginsPage from '../lib/pages/wp-admin/plugins';
Expand All @@ -20,13 +19,12 @@ describe( 'Jetpack updater', () => {
catchBeforeAll( async () => {
await prepareUpdaterTest();
const url = getNgrokSiteUrl();

await execMultipleWpCommands(
'wp plugin deactivate jetpack-dev',
'wp option delete jetpack_sync_error_idc',
'wp plugin install --activate jetpack',
'wp plugin activate e2e-plugin-updater',
'wp option set e2e_jetpack_upgrader_update_version 8.8-alpha',
await execWpCommand( 'wp plugin deactivate jetpack-dev' );
await execWpCommand( 'wp option delete jetpack_sync_error_idc' );
await execWpCommand( 'wp plugin install --activate jetpack' );
await execWpCommand( 'wp plugin activate e2e-plugin-updater' );
await execWpCommand( 'wp option set e2e_jetpack_upgrader_update_version 8.8-alpha' );
await execWpCommand(
`wp option set e2e_jetpack_upgrader_plugin_url ${ url }/wp-content/uploads/jetpack.zip`
);
} );
Expand Down
Loading

0 comments on commit 3230cd4

Please sign in to comment.