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

E2e/customer emails #44622

Merged
merged 4 commits into from Feb 15, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions plugins/woocommerce/changelog/e2e-customer-emails
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Adds e2e tests for user account email flows
@@ -0,0 +1,154 @@
const { test, expect } = require( '@playwright/test' );

const email = `test-${ Math.random() }@example.com`;
const username = `newcustomer-${ Math.random() }`;
const emailContent = '#wp-mail-logging-modal-content-body-content';
const emailContentJson = '#wp-mail-logging-modal-format-json';

test.describe( 'Shopper Account Email Receiving', () => {
test.use( { storageState: process.env.ADMINSTATE } );

test.beforeEach( async ( { page } ) => {
await page.goto(
`wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( email ) }`
);
// clear out the email logs before each test
while (
await page.locator( '#bulk-action-selector-top' ).isVisible()
) {
// In WP 6.3, label intercepts check action. Need to force.
await page
.getByLabel( 'Select All' )
.first()
.check( { force: true } );
await page
.locator( '#bulk-action-selector-top' )
.selectOption( 'delete' );
await page.locator( '#doaction' ).click();
}
} );

test.afterEach( async ( { page } ) => {
// delete created customer
await page.goto( 'wp-admin/users.php' );
await page.getByText( username ).last().hover();
await page.getByRole( 'link', { name: 'Delete' } ).last().click();
await page.getByRole( 'button', { name: 'Confirm Deletion' } ).click();
} );

test( 'should receive an email when creating an account', async ( { page } ) => {
// create a new customer
await page.goto( 'wp-admin/user-new.php' );

await page.getByLabel(' Username (required) ').fill( username );
await page.getByLabel(' Email (required) ').fill( email );
await page.getByLabel(' First Name ').fill( 'New' );
await page.getByLabel(' Last Name ').fill( 'Customer' );

await page.getByLabel( 'Send the new user an email' ).check();

await page.getByLabel( 'Role' ).selectOption( 'Customer' );

await page.getByRole( 'button', { name: 'Add New User' } ).click();

await page.waitForSelector( '.notice' );

// verify that the email was sent
await page.goto( `wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( email ) }` );

await expect( page.locator( 'td.column-receiver' ).first() ).toHaveText( email );
await expect( page.getByRole( 'cell', { name: '[WooCommerce Core E2E Test Suite] Login Details' } ) ).toBeVisible();

await page.getByRole( 'button', { name: 'View log' } ).first().click();
await page.locator( emailContentJson ).click();
await expect( page.locator( emailContent) ).toContainText( `Username: ${ username }` );
} );

test( 'should receive an email when password reset initiated from admin', async ( { page } ) => {
// create a new customer
await page.goto( 'wp-admin/user-new.php' );

await page.getByLabel(' Username (required) ').fill( username );
await page.getByLabel(' Email (required) ').fill( email );
await page.getByLabel(' First Name ').fill( 'New' );
await page.getByLabel(' Last Name ').fill( 'Customer' );

await page.getByLabel( 'Send the new user an email' ).uncheck();

await page.getByLabel( 'Role' ).selectOption( 'Customer' );

await page.getByRole( 'button', { name: 'Add New User' } ).click();

await page.waitForSelector( '.notice' );

// verify that no email was sent on account creation
await page.goto( `wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( email ) }` );
await expect( page.locator( 'td.column-receiver' ).first() ).not.toHaveText( email );

// initiate password reset from admin
await page.goto( 'wp-admin/users.php' );

await page.getByText( username ).last().hover();
await page.getByRole( 'link', { name: 'Send password reset' } ).last().click();

// verify that the email was sent
await page.goto( `wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( email ) }` );

await expect( page.locator( 'td.column-receiver' ).first() ).toHaveText( email );
await expect( page.getByRole( 'cell', { name: '[WooCommerce Core E2E Test Suite] Password Reset' } ) ).toBeVisible();

await page.getByRole( 'button', { name: 'View log' } ).first().click();
await page.locator( emailContentJson ).click();
await expect( page.locator( emailContent) ).toContainText( `Username: ${ username }` );
} );
} );

test.describe( 'Shopper Password Reset Email Receiving', () => {

test.use( { storageState: process.env.ADMINSTATE } );

test.beforeEach( async ( { page } ) => {
await page.goto(
`wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( 'customer@woocommercecoree2etestsuite.com' ) }`
);
// clear out the email logs before each test
while (
await page.locator( '#bulk-action-selector-top' ).isVisible()
) {
// In WP 6.3, label intercepts check action. Need to force.
await page
.getByLabel( 'Select All' )
.first()
.check( { force: true } );
await page
.locator( '#bulk-action-selector-top' )
.selectOption( 'delete' );
await page.locator( '#doaction' ).click();
}
} );

test.use( { cookies: [], origins: [] } );

test ( 'should receive an email when initiating a password reset', async ( { page } ) => {
await page.goto( 'my-account/lost-password/' );

await page.getByLabel( 'Username or email' ).fill( 'customer@woocommercecoree2etestsuite.com' );
await page.getByRole( 'button', { name: 'Reset password' } ).click();

await page.waitForSelector( '.woocommerce-message' );

// verify that the email was sent
await page.goto( 'wp-login.php' );
await page.getByLabel( 'Username or Email Address' ).fill( 'admin' );
await page.getByLabel( 'Password', { exact: true } ).fill( 'password' );
await page.getByRole( 'button', { name: 'Log In' } ).click();
await page.goto( `wp-admin/tools.php?page=wpml_plugin_log&s=${ encodeURIComponent( 'customer@woocommercecoree2etestsuite.com' ) }` );

await expect( page.locator( 'td.column-receiver' ).first() ).toHaveText( 'customer@woocommercecoree2etestsuite.com' );
await expect( page.getByRole( 'cell', { name: 'Password Reset Request for' } ).first() ).toBeVisible();

await page.getByRole( 'button', { name: 'View log' } ).first().click();
await page.locator( emailContentJson ).click();
await expect( page.locator( emailContent) ).toContainText( 'Username: customer' );
} );
} );