E2e Tests Order Copying Billing Shipping Address (#50131)
* Update order edit tests with shipping address tests Update order edit tests with shipping address tests * Add changelog * Refactor new tests --------- Co-authored-by: Jon Lane <jon.lane@automattic.com>
This commit is contained in:
parent
d409d6db99
commit
be79bcca84
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: dev
|
||||
|
||||
|
|
@ -5,7 +5,7 @@ const uuid = require( 'uuid' );
|
|||
test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||
test.use( { storageState: process.env.ADMINSTATE } );
|
||||
|
||||
let orderId, orderToCancel;
|
||||
let orderId, secondOrderId, orderToCancel, customerId;
|
||||
|
||||
test.beforeAll( async ( { baseURL } ) => {
|
||||
const api = new wcApi( {
|
||||
|
@ -21,6 +21,13 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
|||
.then( ( response ) => {
|
||||
orderId = response.data.id;
|
||||
} );
|
||||
await api
|
||||
.post( 'orders', {
|
||||
status: 'processing',
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
secondOrderId = response.data.id;
|
||||
} );
|
||||
await api
|
||||
.post( 'orders', {
|
||||
status: 'processing',
|
||||
|
@ -28,6 +35,40 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
|||
.then( ( response ) => {
|
||||
orderToCancel = response.data.id;
|
||||
} );
|
||||
await api
|
||||
.post( 'customers', {
|
||||
email: 'archie123@email.addr',
|
||||
first_name: 'Archie',
|
||||
last_name: 'Greenback',
|
||||
username: 'big.archie',
|
||||
billing: {
|
||||
first_name: 'Archibald',
|
||||
last_name: 'Greenback',
|
||||
company: 'Automattic',
|
||||
country: 'US',
|
||||
address_1: 'Billing Address 1',
|
||||
address_2: 'Billing Address 2',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94107',
|
||||
phone: '123456789',
|
||||
email: 'archie123@email.addr',
|
||||
},
|
||||
shipping: {
|
||||
first_name: 'Shipping First',
|
||||
last_name: 'Shipping Last',
|
||||
company: 'Automattic',
|
||||
country: 'US',
|
||||
address_1: 'Shipping Address 1',
|
||||
address_2: 'Shipping Address 2',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94107',
|
||||
},
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
customerId = response.data.id;
|
||||
} );
|
||||
} );
|
||||
|
||||
test.afterAll( async ( { baseURL } ) => {
|
||||
|
@ -38,7 +79,9 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
|||
version: 'wc/v3',
|
||||
} );
|
||||
await api.delete( `orders/${ orderId }`, { force: true } );
|
||||
await api.delete( `orders/${ secondOrderId }`, { force: true } );
|
||||
await api.delete( `orders/${ orderToCancel }`, { force: true } );
|
||||
await api.delete( `customers/${ customerId }`, { force: true } );
|
||||
} );
|
||||
|
||||
test( 'can view single order', async ( { page } ) => {
|
||||
|
@ -210,77 +253,115 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
|||
).toBeHidden();
|
||||
} );
|
||||
|
||||
test( 'can load billing details', async ( { page, baseURL } ) => {
|
||||
let customerId;
|
||||
|
||||
const api = new wcApi( {
|
||||
url: baseURL,
|
||||
consumerKey: process.env.CONSUMER_KEY,
|
||||
consumerSecret: process.env.CONSUMER_SECRET,
|
||||
version: 'wc/v3',
|
||||
} );
|
||||
|
||||
await api
|
||||
.post( 'customers', {
|
||||
email: 'archie123@email.addr',
|
||||
first_name: 'Archie',
|
||||
last_name: 'Greenback',
|
||||
username: 'big.archie',
|
||||
billing: {
|
||||
first_name: 'Archibald',
|
||||
last_name: 'Greenback',
|
||||
company: 'Automattic',
|
||||
country: 'US',
|
||||
address_1: 'address1',
|
||||
address_2: 'address2',
|
||||
city: 'San Francisco',
|
||||
state: 'CA',
|
||||
postcode: '94107',
|
||||
phone: '123456789',
|
||||
email: 'archie123@email.addr',
|
||||
},
|
||||
} )
|
||||
.then( ( response ) => {
|
||||
customerId = response.data.id;
|
||||
} );
|
||||
|
||||
test( 'can load billing and shipping details', async ( { page } ) => {
|
||||
// Open our test order and select the customer we just created.
|
||||
await test.step( 'Open our test order and select the customer we just created.', async () => {
|
||||
await page.goto(
|
||||
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ orderId }`
|
||||
);
|
||||
|
||||
// Simulate the ajax `woocommerce_get_customer_details` call normally done inside meta-boxes-order.js.
|
||||
const response = await page.evaluate( async ( custId ) => {
|
||||
const simulateCustomerDetailsCall = new Promise( ( resolve ) => {
|
||||
// eslint-disable-next-line no-undef
|
||||
jQuery.ajax( {
|
||||
// eslint-disable-next-line no-undef
|
||||
url: woocommerce_admin_meta_boxes.ajax_url,
|
||||
data: {
|
||||
user_id: custId,
|
||||
action: 'woocommerce_get_customer_details',
|
||||
security:
|
||||
// eslint-disable-next-line no-undef
|
||||
woocommerce_admin_meta_boxes.get_customer_details_nonce,
|
||||
},
|
||||
type: 'POST',
|
||||
// eslint-disable-next-line no-shadow
|
||||
success( resp ) {
|
||||
resolve( resp );
|
||||
},
|
||||
// Assign customer
|
||||
await page.locator( '#select2-customer_user-container' ).click();
|
||||
await page
|
||||
.getByRole( 'combobox' )
|
||||
.nth( 4 )
|
||||
.pressSequentially( 'big.archie' );
|
||||
await page.waitForSelector( 'li.select2-results__option' );
|
||||
await page.locator( 'li.select2-results__option' ).click();
|
||||
} );
|
||||
|
||||
await test.step( 'Load the billing and shipping addresses', async () => {
|
||||
// Click the load billing address button
|
||||
await page
|
||||
.getByRole( 'link', { name: 'Load billing address' } )
|
||||
.click();
|
||||
await expect(
|
||||
page.locator( '[id="_billing_first_name"]' )
|
||||
).toHaveValue( 'Archibald' );
|
||||
|
||||
// Click the load shipping address button
|
||||
await page
|
||||
.getByRole( 'link', { name: 'Load shipping address' } )
|
||||
.click();
|
||||
await expect(
|
||||
page.locator( '[id="_shipping_first_name"]' )
|
||||
).toHaveValue( 'Shipping First' );
|
||||
} );
|
||||
|
||||
await test.step( 'Save the order and confirm addresses saved', async () => {
|
||||
// Save the order
|
||||
await page.locator( 'button.save_order' ).click();
|
||||
|
||||
// Verify both addresses are saved
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Billing Edit Load billing address Archibald GreenbackAutomatticBilling Address'
|
||||
)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Shipping Edit Load shipping address Copy billing address Shipping First'
|
||||
)
|
||||
).toBeVisible();
|
||||
} );
|
||||
} );
|
||||
|
||||
return await simulateCustomerDetailsCall;
|
||||
}, customerId );
|
||||
test( 'can copy billing address to shipping address', async ( {
|
||||
page,
|
||||
} ) => {
|
||||
// click ok on the dialog that pops up
|
||||
page.on( 'dialog', ( dialog ) => dialog.accept() );
|
||||
|
||||
// Response should contain billing address info, but should not contain user meta data.
|
||||
expect( 'billing' in response ).toBeTruthy();
|
||||
expect( response.billing.first_name ).toContain( 'Archibald' );
|
||||
expect( response.meta_data ).toBeUndefined();
|
||||
await test.step( 'Open our second test order and select the customer we just created.', async () => {
|
||||
// Open our second test order
|
||||
await page.goto(
|
||||
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ secondOrderId }`
|
||||
);
|
||||
|
||||
// Clean-up.
|
||||
await api.delete( `customers/${ customerId }`, { force: true } );
|
||||
// Assign customer
|
||||
await page.locator( '#select2-customer_user-container' ).click();
|
||||
await page
|
||||
.getByRole( 'combobox' )
|
||||
.nth( 4 )
|
||||
.pressSequentially( 'big.archie' );
|
||||
await page.waitForSelector( 'li.select2-results__option' );
|
||||
await page.locator( 'li.select2-results__option' ).click();
|
||||
} );
|
||||
|
||||
await test.step( 'Load the billing address and then copy it to the shipping address', async () => {
|
||||
// Click the load billing address button
|
||||
await page
|
||||
.getByRole( 'link', { name: 'Load billing address' } )
|
||||
.click();
|
||||
await expect(
|
||||
page.locator( '[id="_billing_first_name"]' )
|
||||
).toHaveValue( 'Archibald' );
|
||||
|
||||
// Click the copy billing address to shipping address button
|
||||
await page
|
||||
.getByRole( 'link', { name: 'Copy billing address' } )
|
||||
.click();
|
||||
await expect(
|
||||
page.locator( '[id="_shipping_first_name"]' )
|
||||
).toHaveValue( 'Archibald' );
|
||||
} );
|
||||
|
||||
await test.step( 'Save the order and confirm addresses saved', async () => {
|
||||
// Save the order
|
||||
await page.locator( 'button.save_order' ).click();
|
||||
|
||||
// Verify both addresses are saved
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Billing Edit Load billing address Archibald GreenbackAutomatticBilling Address'
|
||||
)
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
page.getByText(
|
||||
'Shipping Edit Load shipping address Copy billing address Archibald'
|
||||
)
|
||||
).toBeVisible();
|
||||
} );
|
||||
} );
|
||||
} );
|
||||
|
||||
|
|
Loading…
Reference in New Issue