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.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||||
test.use( { storageState: process.env.ADMINSTATE } );
|
test.use( { storageState: process.env.ADMINSTATE } );
|
||||||
|
|
||||||
let orderId, orderToCancel;
|
let orderId, secondOrderId, orderToCancel, customerId;
|
||||||
|
|
||||||
test.beforeAll( async ( { baseURL } ) => {
|
test.beforeAll( async ( { baseURL } ) => {
|
||||||
const api = new wcApi( {
|
const api = new wcApi( {
|
||||||
|
@ -21,6 +21,13 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||||
.then( ( response ) => {
|
.then( ( response ) => {
|
||||||
orderId = response.data.id;
|
orderId = response.data.id;
|
||||||
} );
|
} );
|
||||||
|
await api
|
||||||
|
.post( 'orders', {
|
||||||
|
status: 'processing',
|
||||||
|
} )
|
||||||
|
.then( ( response ) => {
|
||||||
|
secondOrderId = response.data.id;
|
||||||
|
} );
|
||||||
await api
|
await api
|
||||||
.post( 'orders', {
|
.post( 'orders', {
|
||||||
status: 'processing',
|
status: 'processing',
|
||||||
|
@ -28,6 +35,40 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||||
.then( ( response ) => {
|
.then( ( response ) => {
|
||||||
orderToCancel = response.data.id;
|
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 } ) => {
|
test.afterAll( async ( { baseURL } ) => {
|
||||||
|
@ -38,7 +79,9 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||||
version: 'wc/v3',
|
version: 'wc/v3',
|
||||||
} );
|
} );
|
||||||
await api.delete( `orders/${ orderId }`, { force: true } );
|
await api.delete( `orders/${ orderId }`, { force: true } );
|
||||||
|
await api.delete( `orders/${ secondOrderId }`, { force: true } );
|
||||||
await api.delete( `orders/${ orderToCancel }`, { force: true } );
|
await api.delete( `orders/${ orderToCancel }`, { force: true } );
|
||||||
|
await api.delete( `customers/${ customerId }`, { force: true } );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'can view single order', async ( { page } ) => {
|
test( 'can view single order', async ( { page } ) => {
|
||||||
|
@ -210,77 +253,115 @@ test.describe( 'Edit order', { tag: [ '@services', '@hpos' ] }, () => {
|
||||||
).toBeHidden();
|
).toBeHidden();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
test( 'can load billing details', async ( { page, baseURL } ) => {
|
test( 'can load billing and shipping details', async ( { page } ) => {
|
||||||
let customerId;
|
// 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 }`
|
||||||
|
);
|
||||||
|
|
||||||
const api = new wcApi( {
|
// Assign customer
|
||||||
url: baseURL,
|
await page.locator( '#select2-customer_user-container' ).click();
|
||||||
consumerKey: process.env.CONSUMER_KEY,
|
await page
|
||||||
consumerSecret: process.env.CONSUMER_SECRET,
|
.getByRole( 'combobox' )
|
||||||
version: 'wc/v3',
|
.nth( 4 )
|
||||||
|
.pressSequentially( 'big.archie' );
|
||||||
|
await page.waitForSelector( 'li.select2-results__option' );
|
||||||
|
await page.locator( 'li.select2-results__option' ).click();
|
||||||
} );
|
} );
|
||||||
|
|
||||||
await api
|
await test.step( 'Load the billing and shipping addresses', async () => {
|
||||||
.post( 'customers', {
|
// Click the load billing address button
|
||||||
email: 'archie123@email.addr',
|
await page
|
||||||
first_name: 'Archie',
|
.getByRole( 'link', { name: 'Load billing address' } )
|
||||||
last_name: 'Greenback',
|
.click();
|
||||||
username: 'big.archie',
|
await expect(
|
||||||
billing: {
|
page.locator( '[id="_billing_first_name"]' )
|
||||||
first_name: 'Archibald',
|
).toHaveValue( '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;
|
|
||||||
} );
|
|
||||||
|
|
||||||
// Open our test order and select the customer we just created.
|
// Click the load shipping address button
|
||||||
await page.goto(
|
await page
|
||||||
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ orderId }`
|
.getByRole( 'link', { name: 'Load shipping address' } )
|
||||||
);
|
.click();
|
||||||
|
await expect(
|
||||||
|
page.locator( '[id="_shipping_first_name"]' )
|
||||||
|
).toHaveValue( 'Shipping First' );
|
||||||
|
} );
|
||||||
|
|
||||||
// Simulate the ajax `woocommerce_get_customer_details` call normally done inside meta-boxes-order.js.
|
await test.step( 'Save the order and confirm addresses saved', async () => {
|
||||||
const response = await page.evaluate( async ( custId ) => {
|
// Save the order
|
||||||
const simulateCustomerDetailsCall = new Promise( ( resolve ) => {
|
await page.locator( 'button.save_order' ).click();
|
||||||
// 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 );
|
|
||||||
},
|
|
||||||
} );
|
|
||||||
} );
|
|
||||||
|
|
||||||
return await simulateCustomerDetailsCall;
|
// Verify both addresses are saved
|
||||||
}, customerId );
|
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();
|
||||||
|
} );
|
||||||
|
} );
|
||||||
|
|
||||||
// Response should contain billing address info, but should not contain user meta data.
|
test( 'can copy billing address to shipping address', async ( {
|
||||||
expect( 'billing' in response ).toBeTruthy();
|
page,
|
||||||
expect( response.billing.first_name ).toContain( 'Archibald' );
|
} ) => {
|
||||||
expect( response.meta_data ).toBeUndefined();
|
// click ok on the dialog that pops up
|
||||||
|
page.on( 'dialog', ( dialog ) => dialog.accept() );
|
||||||
|
|
||||||
// Clean-up.
|
await test.step( 'Open our second test order and select the customer we just created.', async () => {
|
||||||
await api.delete( `customers/${ customerId }`, { force: true } );
|
// Open our second test order
|
||||||
|
await page.goto(
|
||||||
|
`/wp-admin/admin.php?page=wc-orders&action=edit&id=${ secondOrderId }`
|
||||||
|
);
|
||||||
|
|
||||||
|
// 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();
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
|
@ -410,7 +491,7 @@ test.describe(
|
||||||
await revertGrantAccessAfterPaymentSetting( api );
|
await revertGrantAccessAfterPaymentSetting( api );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
// these tests aren't completely independent. Needs some refactoring.
|
// these tests aren't completely independent. Needs some refactoring.
|
||||||
|
|
||||||
test( 'can add downloadable product permissions to order without product', async ( {
|
test( 'can add downloadable product permissions to order without product', async ( {
|
||||||
page,
|
page,
|
||||||
|
|
Loading…
Reference in New Issue