Skip to content
This repository has been archived by the owner on Feb 23, 2024. It is now read-only.

Add E2E to the the Order Confirmation Block #10863

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
101 changes: 101 additions & 0 deletions tests/e2e/tests/checkout/checkout.page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
import { Page } from '@playwright/test';
import { expect } from '@woocommerce/e2e-playwright-utils';

/**
* Internal dependencies
*/
import {
FREE_SHIPPING_NAME,
SIMPLE_PHYSICAL_PRODUCT_NAME,
SIMPLE_VIRTUAL_PRODUCT_NAME,
} from './constants';

export class CheckoutPage {
private BLOCK_NAME = 'woocommerce/checkout';
public page: Page;
Expand Down Expand Up @@ -245,4 +254,96 @@ export class CheckoutPage {
this.page.locator( '.wc-block-order-confirmation-billing-wrapper' )
).toBeVisible();
}

async verifyOrderConfirmationDetails(
currentPage: Page,
toBeVisible = true
) {
const statusSection = currentPage.locator(
'[data-block-name="woocommerce/order-confirmation-status"]'
);
const summarySection = currentPage.locator(
'[data-block-name="woocommerce/order-confirmation-summary"]'
);
const totalsSection = currentPage.locator(
'[data-block-name="woocommerce/order-confirmation-totals"]'
);
const shippingAddressSection = currentPage.locator(
'[data-block-name="woocommerce/order-confirmation-shipping-address"]'
);
const billingAddressSection = currentPage.locator(
'[data-block-name="woocommerce/order-confirmation-billing-address"]'
);

if ( toBeVisible ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this take care of the partial view for guests? If it doesn't and its not needed, just add a note to the method that it only handles the full logged in view.

const {
firstname,
lastname,
addressfirstline,
addresssecondline,
city,
postcode,
email,
phone,
} = this.testData;

await expect( statusSection ).toBeVisible();
await expect( summarySection ).toBeVisible();
await expect( totalsSection ).toBeVisible();
await expect( shippingAddressSection ).toBeVisible();
await expect( billingAddressSection ).toBeVisible();

// Confirm order data are visible and correct
await expect(
currentPage.getByText(
'Thank you. Your order has been received.'
)
).toBeVisible();
await expect( currentPage.getByText( email ) ).toBeVisible();
await expect(
currentPage.getByText( FREE_SHIPPING_NAME )
).toBeVisible();
await expect(
currentPage.getByText( SIMPLE_PHYSICAL_PRODUCT_NAME )
).toBeVisible();
await expect(
currentPage.getByText( SIMPLE_VIRTUAL_PRODUCT_NAME )
).toBeVisible();
await expect(
currentPage
.getByText(
`${ firstname } ${ lastname }${ addressfirstline }${ addresssecondline }${ city }, NY ${ postcode }${ phone }`
)
.first()
).toBeVisible();
await expect(
currentPage
.getByText(
`${ firstname } ${ lastname }${ addressfirstline }${ addresssecondline }${ city }, NY ${ postcode }${ phone }`
)
.nth( 1 )
).toBeVisible();
} else {
await expect( statusSection ).toBeVisible();
await expect( summarySection ).toBeHidden();
await expect( totalsSection ).toBeHidden();
await expect( shippingAddressSection ).toBeHidden();
await expect( billingAddressSection ).toBeHidden();
}
}

getOrderId() {
// Get the current URL
const url = this.page.url();
const urlObject = new URL( url );

// Extract orderId from the pathname
const pathnameSegments = urlObject.pathname.split( '/' );
const orderId =
pathnameSegments[
pathnameSegments.indexOf( 'order-received' ) + 1
];

return orderId;
}
}
Loading