From 8cbd439a7241a1a671106b126b675f5425ea56f1 Mon Sep 17 00:00:00 2001 From: Yaroslav Kukharuk Date: Fri, 30 Apr 2021 16:23:46 +0300 Subject: [PATCH] E2E Tests: Add Classic and Userless connection tests (#19708) --- ...-e2e-userless-and-classic-connection-tests | 4 ++ ...-e2e-userless-and-classic-connection-tests | 4 ++ .../tests/e2e/lib/flows/jetpack-connect.js | 28 +++++++-- .../tests/e2e/lib/pages/page-actions.js | 8 +++ .../lib/pages/wp-admin/in-place-authorize.js | 7 +++ .../plugins/jetpack/tests/e2e/package.json | 1 + .../tests/e2e/specs/connection.test.js | 61 ++++++++++++------- 7 files changed, 85 insertions(+), 28 deletions(-) create mode 100644 projects/plugins/jetpack/changelog/add-e2e-userless-and-classic-connection-tests create mode 100644 projects/plugins/jetpack/tests/e2e/changelog/add-e2e-userless-and-classic-connection-tests diff --git a/projects/plugins/jetpack/changelog/add-e2e-userless-and-classic-connection-tests b/projects/plugins/jetpack/changelog/add-e2e-userless-and-classic-connection-tests new file mode 100644 index 0000000000000..43658583ce995 --- /dev/null +++ b/projects/plugins/jetpack/changelog/add-e2e-userless-and-classic-connection-tests @@ -0,0 +1,4 @@ +Significance: patch +Type: other + +Add userless and classic connection tests diff --git a/projects/plugins/jetpack/tests/e2e/changelog/add-e2e-userless-and-classic-connection-tests b/projects/plugins/jetpack/tests/e2e/changelog/add-e2e-userless-and-classic-connection-tests new file mode 100644 index 0000000000000..910268d8f9ea6 --- /dev/null +++ b/projects/plugins/jetpack/tests/e2e/changelog/add-e2e-userless-and-classic-connection-tests @@ -0,0 +1,4 @@ +Significance: patch +Type: added + +Add Userless and Classic connection tests diff --git a/projects/plugins/jetpack/tests/e2e/lib/flows/jetpack-connect.js b/projects/plugins/jetpack/tests/e2e/lib/flows/jetpack-connect.js index b9d0aea1c9e80..e02c3d384d3bd 100644 --- a/projects/plugins/jetpack/tests/e2e/lib/flows/jetpack-connect.js +++ b/projects/plugins/jetpack/tests/e2e/lib/flows/jetpack-connect.js @@ -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' ); @@ -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 ); @@ -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'; @@ -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() { diff --git a/projects/plugins/jetpack/tests/e2e/lib/pages/page-actions.js b/projects/plugins/jetpack/tests/e2e/lib/pages/page-actions.js index 032c16023386a..16f927190aed5 100644 --- a/projects/plugins/jetpack/tests/e2e/lib/pages/page-actions.js +++ b/projects/plugins/jetpack/tests/e2e/lib/pages/page-actions.js @@ -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 diff --git a/projects/plugins/jetpack/tests/e2e/lib/pages/wp-admin/in-place-authorize.js b/projects/plugins/jetpack/tests/e2e/lib/pages/wp-admin/in-place-authorize.js index 197c76294d6ea..0b2f7eb523e53 100644 --- a/projects/plugins/jetpack/tests/e2e/lib/pages/wp-admin/in-place-authorize.js +++ b/projects/plugins/jetpack/tests/e2e/lib/pages/wp-admin/in-place-authorize.js @@ -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 ] ); } diff --git a/projects/plugins/jetpack/tests/e2e/package.json b/projects/plugins/jetpack/tests/e2e/package.json index f10780cc0e349..3b163f29edbec 100644 --- a/projects/plugins/jetpack/tests/e2e/package.json +++ b/projects/plugins/jetpack/tests/e2e/package.json @@ -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", diff --git a/projects/plugins/jetpack/tests/e2e/specs/connection.test.js b/projects/plugins/jetpack/tests/e2e/specs/connection.test.js index f9d169bd530cc..a94f339b9dcfd 100644 --- a/projects/plugins/jetpack/tests/e2e/specs/connection.test.js +++ b/projects/plugins/jetpack/tests/e2e/specs/connection.test.js @@ -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 @@ -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(); } ); @@ -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(); + } ); + } ); } );