Skip to content

Commit

Permalink
E2E Tests: Add Classic and Userless connection tests (#19708)
Browse files Browse the repository at this point in the history
  • Loading branch information
brbrr authored Apr 30, 2021
1 parent df8f811 commit 8cbd439
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: other

Add userless and classic connection tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: added

Add Userless and Classic connection tests
28 changes: 22 additions & 6 deletions projects/plugins/jetpack/tests/e2e/lib/flows/jetpack-connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { execWpCommand } from '../utils-helper';
import { persistPlanData, syncPlanData } from '../plan-helper';
import logger from '../logger';
import InPlaceAuthorizeFrame from '../pages/wp-admin/in-place-authorize';
import RecommendationsPage from '../pages/wp-admin/recommendations';

const cookie = config.get( 'storeSandboxCookieValue' );
const cardCredentials = config.get( 'testCardCredentials' );
Expand Down Expand Up @@ -47,14 +48,15 @@ export async function connectThroughWPAdmin( { plan = 'complete', mockPlanData =
await syncJetpackPlanData( plan, mockPlanData );
}

async function doClassicConnection( mockPlanData ) {
export async function doClassicConnection( mockPlanData ) {
const jetpackPage = await JetpackPage.init( page );
await jetpackPage.forceVariation( 'original' );
await jetpackPage.connect();
// Go through Jetpack connect flow
await ( await AuthorizePage.init( page ) ).approve();
if ( mockPlanData ) {
return await ( await PickAPlanPage.init( page ) ).select( 'free' );
await ( await PickAPlanPage.init( page ) ).select( 'free' );
return await ( await Sidebar.init( page ) ).selectJetpack();
}
await ( await PickAPlanPage.init( page ) ).select( 'complete' );
await ( await CheckoutPage.init( page ) ).processPurchase( cardCredentials );
Expand All @@ -74,6 +76,20 @@ export async function doInPlaceConnection() {
await ( await Sidebar.init( page ) ).selectJetpack();
}

export async function doUserlessConnection() {
const jetpackPage = await JetpackPage.init( page );
await jetpackPage.forceVariation( 'in_place' );
await jetpackPage.connect();

await ( await InPlaceAuthorizeFrame.init( page ) ).continueWithout();
await ( await PickAPlanPage.init( page ) ).select( 'free' );
const isPageVisible = await (
await RecommendationsPage.visit( page )
).areSiteTypeQuestionsVisible();
expect( isPageVisible ).toBeTruthy();
await ( await Sidebar.init( page ) ).selectJetpack();
}

export async function syncJetpackPlanData( plan, mockPlanData = true ) {
logger.step( `Sync plan data. { plan: ${ plan }, mock: ${ mockPlanData } }` );
const planType = plan === 'free' ? 'jetpack_free' : 'jetpack_complete';
Expand Down Expand Up @@ -121,11 +137,11 @@ export async function loginToWpComIfNeeded( wpComUser, mockPlanData ) {
if ( ! mockPlanData ) {
await login.setSandboxModeForPayments( cookie );
}
if ( ! ( await login.isLoggedIn() ) ) {
await login.login( wpComUser );
} else {
logger.step( 'Already logged into Wordpress.com' );
if ( await login.isLoggedIn() ) {
return logger.step( 'Already logged into Wordpress.com' );
}

await login.login( wpComUser );
}

export async function isBlogTokenSet() {
Expand Down
8 changes: 8 additions & 0 deletions projects/plugins/jetpack/tests/e2e/lib/pages/page-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,14 @@ export default class PageActions {
return await this.reload();
}

async removeCookieByName( cookieName ) {
const ctx = this.page.context();
const allCookies = await ctx.cookies();
const cookiesWithoutWpcom = allCookies.filter( cookie => cookie.name !== cookieName );
await ctx.clearCookies();
await ctx.addCookies( cookiesWithoutWpcom );
}

// endregion

// region actions on page elements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ export default class InPlaceAuthorizeFrame extends WpPage {
return this.waitToDisappear();
}

async continueWithout() {
const continueSelector = '#jp-authenticate-no_user_test_mode a.jp-no-user-mode-button';
const iframe = await this.getFrame();
await iframe.click( continueSelector );
return this.waitToDisappear();
}

async waitToDisappear() {
return await this.waitForElementToBeHidden( this.selectors[ 0 ] );
}
Expand Down
1 change: 1 addition & 0 deletions projects/plugins/jetpack/tests/e2e/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"env-start": "./bin/env.sh start",
"env-reset": "./bin/env.sh reset",
"tunnel-on": "pm2 start bin/ecosystem.config.js && yarn pm2 logs --nostream --lines 4",
"tunnel-reset": "rm -rf config/tmp && yarn tunnel-on",
"tunnel-off": "pm2 delete bin/ecosystem.config.js && NODE_ENV=test node bin/tunnel.js off",
"pretest-e2e": "yarn clean",
"test-e2e": "NODE_CONFIG_DIR='./config' jest --config jest.config.js --runInBand --verbose --detectOpenHandles --json --outputFile=output/summary.json",
Expand Down
61 changes: 39 additions & 22 deletions projects/plugins/jetpack/tests/e2e/specs/connection.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { step } from '../lib/env/test-setup';
import { doInPlaceConnection } from '../lib/flows/jetpack-connect';
import { execMultipleWpCommands, execWpCommand } from '../lib/utils-helper';
import {
doInPlaceConnection,
doUserlessConnection,
loginToWpComIfNeeded,
loginToWpSite,
doClassicConnection,
} from '../lib/flows/jetpack-connect';
import { resetWordpressInstall } from '../lib/utils-helper';
import Sidebar from '../lib/pages/wp-admin/sidebar';
import JetpackPage from '../lib/pages/wp-admin/jetpack';
import path from 'path';
import config from 'config';
import DashboardPage from '../lib/pages/wp-admin/dashboard';

// Disable pre-connect for this test suite
Expand All @@ -15,32 +19,19 @@ process.env.SKIP_CONNECT = true;
* @group connection
*/
describe( 'Connection', () => {
beforeAll( async () => {
await execMultipleWpCommands(
'wp option delete e2e_jetpack_plan_data',
'wp option delete jetpack_active_plan',
'wp option delete jetpack_private_options',
'wp option delete jetpack_sync_error_idc'
);
await page.reload();
await page.reload();
} );

beforeEach( async () => {
await loginToWpComIfNeeded( 'defaultUser', true );
await loginToWpSite( true );
await DashboardPage.visit( page );
await ( await Sidebar.init( page ) ).selectJetpack();
} );

afterAll( async () => {
await execWpCommand(
`'wp option update jetpack_private_options --format=json < ${ path.resolve(
config.get( 'temp.jetpackPrivateOptions' )
) }'`
);
afterEach( async () => {
await resetWordpressInstall();
} );

it( 'In-place', async () => {
await step( 'Can start in-place connection', async () => {
await ( await Sidebar.init( page ) ).selectJetpack();
await doInPlaceConnection();
} );

Expand All @@ -49,4 +40,30 @@ describe( 'Connection', () => {
expect( await jetpackPage.isConnected() ).toBeTruthy();
} );
} );

it( 'User-less', async () => {
await step( 'Can clean up WPCOM cookie', async () => {
await ( await Sidebar.init( page ) ).removeCookieByName( 'wordpress_logged_in' );
} );

await step( 'Can start Userless connection', async () => {
await doUserlessConnection();
} );

await step( 'Can assert that site is connected', async () => {
const jetpackPage = await JetpackPage.init( page );
expect( await jetpackPage.isConnected() ).toBeTruthy();
} );
} );

it( 'Classic', async () => {
await step( 'Can start classic connection', async () => {
await doClassicConnection( true );
} );

await step( 'Can assert that site is connected', async () => {
const jetpackPage = await JetpackPage.init( page );
expect( await jetpackPage.isConnected() ).toBeTruthy();
} );
} );
} );

0 comments on commit 8cbd439

Please sign in to comment.