Skip to content

Commit

Permalink
Add the critical tag to E2E tests that are part of critical flows (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoumpierre authored Feb 11, 2025
1 parent 36ae2f0 commit 6f99121
Show file tree
Hide file tree
Showing 33 changed files with 902 additions and 763 deletions.
4 changes: 4 additions & 0 deletions changelog/dev-10237-e2e-critical-flow-tag
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: dev

Add critical tag to tests that are part of the critical flows.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
// Run the tests if the two 'skip' environment variables are not set.
describeif( shouldRunSubscriptionsTests && shouldRunActionSchedulerTests )(
'Subscriptions > Renew a subscription via Action Scheduler',
{ tag: '@critical' },
() => {
const actionSchedulerHook =
'woocommerce_scheduled_subscription_payment';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ let subscriptionId = null;

describeif( shouldRunSubscriptionsTests )(
'Subscriptions > Renew a subscription as a merchant',
{ tag: '@critical' },
() => {
test.beforeAll( async ( { browser }, { project } ) => {
const restApi = new RestAPI( project.use.baseURL );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const navigateToSubscriptionDetails = async (

describeif( shouldRunSubscriptionsTests )(
'Shopper > Subscriptions > Manage Payment Methods',
{ tag: '@critical' },
() => {
let page: Page;
let subscriptionId: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,94 +67,98 @@ describeif( shouldRunSubscriptionsTests )(
}
} );

test( 'Shopper should be able to purchase a free trial', async ( {
browser,
} ) => {
const { shopperPage } = await getShopper( browser );
// Just to be sure, empty the cart
await emptyCart( shopperPage );
test(
'Shopper should be able to purchase a free trial',
{ tag: '@critical' },
async ( { browser } ) => {
const { shopperPage } = await getShopper( browser );
// Just to be sure, empty the cart
await emptyCart( shopperPage );

// Open the subscription product, and verify that the
// 14-day free trial is shown in the product description
await goToProductPageBySlug( shopperPage, productSlug );
await expect(
shopperPage
.locator( '.product' )
.getByText( '/ month with a 14-day free trial' )
).toBeVisible();

// Add it to the cart and verify that the cart page shows the free trial details
await shopperPage
.getByRole( 'button', { name: 'Sign up now' } )
.click();
await goToCart( shopperPage );
await expect(
shopperPage
.getByText( '/ month with a 14-day free trial' )
.first()
).toBeVisible();
// Open the subscription product, and verify that the
// 14-day free trial is shown in the product description
await goToProductPageBySlug( shopperPage, productSlug );
await expect(
shopperPage
.locator( '.product' )
.getByText( '/ month with a 14-day free trial' )
).toBeVisible();

// Also verify that the first renewal is 14 days from now
await expect(
shopperPage.getByText(
`First renewal: ${ renewalDateFormatted }`
)
).toBeVisible();
// Add it to the cart and verify that the cart page shows the free trial details
await shopperPage
.getByRole( 'button', { name: 'Sign up now' } )
.click();
await goToCart( shopperPage );
await expect(
shopperPage
.getByText( '/ month with a 14-day free trial' )
.first()
).toBeVisible();

// Verify that the order total is $0.00
await expect(
shopperPage
.getByRole( 'row', {
name: 'Total $0.00',
exact: true,
} )
.locator( 'td' )
).toBeVisible();
// Also verify that the first renewal is 14 days from now
await expect(
shopperPage.getByText(
`First renewal: ${ renewalDateFormatted }`
)
).toBeVisible();

// Proceed to the checkout page and verify that the 14-day free trial is shown in the product line item,
// and that the first renewal date is 14 days from now.
await setupCheckout( shopperPage, customerBilling );
await expect(
shopperPage
.locator( '#order_review' )
.getByText( '/ month with a 14-day free trial' )
).toBeVisible();
await expect(
shopperPage.getByText(
`First renewal: ${ renewalDateFormatted }`
)
).toBeVisible();
// Verify that the order total is $0.00
await expect(
shopperPage
.getByRole( 'row', {
name: 'Total $0.00',
exact: true,
} )
.locator( 'td' )
).toBeVisible();

// Pay using a 3DS card
const card = config.cards[ '3dsOTP' ];
await fillCardDetails( shopperPage, card );
await shopperPage
.getByRole( 'button', { name: 'Sign up now' } )
.click();
await shopperPage.frames()[ 0 ].waitForLoadState( 'load' );
await confirmCardAuthentication( shopperPage, true );
await shopperPage.frames()[ 0 ].waitForLoadState( 'networkidle' );
await shopperPage.waitForLoadState( 'networkidle' );
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();
// Proceed to the checkout page and verify that the 14-day free trial is shown in the product line item,
// and that the first renewal date is 14 days from now.
await setupCheckout( shopperPage, customerBilling );
await expect(
shopperPage
.locator( '#order_review' )
.getByText( '/ month with a 14-day free trial' )
).toBeVisible();
await expect(
shopperPage.getByText(
`First renewal: ${ renewalDateFormatted }`
)
).toBeVisible();

// Get the order ID so we can open it in the merchant view
orderId = (
await shopperPage.getByText( 'Order number:' ).innerText()
)
.replace( /[^0-9]/g, '' )
.trim();
subscriptionId = (
// Pay using a 3DS card
const card = config.cards[ '3dsOTP' ];
await fillCardDetails( shopperPage, card );
await shopperPage
.getByLabel( 'View subscription number' )
.textContent()
)
.trim()
.replace( '#', '' );
} );
.getByRole( 'button', { name: 'Sign up now' } )
.click();
await shopperPage.frames()[ 0 ].waitForLoadState( 'load' );
await confirmCardAuthentication( shopperPage, true );
await shopperPage
.frames()[ 0 ]
.waitForLoadState( 'networkidle' );
await shopperPage.waitForLoadState( 'networkidle' );
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();

// Get the order ID so we can open it in the merchant view
orderId = (
await shopperPage.getByText( 'Order number:' ).innerText()
)
.replace( /[^0-9]/g, '' )
.trim();
subscriptionId = (
await shopperPage
.getByLabel( 'View subscription number' )
.textContent()
)
.trim()
.replace( '#', '' );
}
);

test( 'Merchant should be able to create an order with "Setup Intent"', async () => {
await goToOrder( merchantPage, orderId );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,74 +50,80 @@ describeif( shouldRunSubscriptionsTests )(
}
} );

test( ' should be able to purchase multiple subscriptions', async () => {
// As a Shopper, purchase the subscription products.
await emptyCart( shopperPage );
await setupProductCheckout(
shopperPage,
[
[ config.products.subscription_no_signup_fee, 1 ],
[ config.products.subscription_signup_fee, 1 ],
],
configBillingAddress,
'USD'
);
await fillCardDetails( shopperPage, config.cards.basic );
await placeOrder( shopperPage );
await expect(
shopperPage.getByRole( 'heading', { name: 'Order received' } )
).toBeVisible();
test(
'should be able to purchase multiple subscriptions',
{ tag: '@critical' },
async () => {
// As a Shopper, purchase the subscription products.
await emptyCart( shopperPage );
await setupProductCheckout(
shopperPage,
[
[ config.products.subscription_no_signup_fee, 1 ],
[ config.products.subscription_signup_fee, 1 ],
],
configBillingAddress,
'USD'
);
await fillCardDetails( shopperPage, config.cards.basic );
await placeOrder( shopperPage );
await expect(
shopperPage.getByRole( 'heading', {
name: 'Order received',
} )
).toBeVisible();

const subscriptionId = (
await shopperPage
.getByLabel( 'View subscription number' )
.innerText()
)
.trim()
.replace( '#', '' );
const subscriptionId = (
await shopperPage
.getByLabel( 'View subscription number' )
.innerText()
)
.trim()
.replace( '#', '' );

await goToSubscriptions( shopperPage );
await goToSubscriptions( shopperPage );

const latestSubscriptionRow = shopperPage.getByRole( 'row', {
name: `subscription number ${ subscriptionId }`,
} );
const latestSubscriptionRow = shopperPage.getByRole( 'row', {
name: `subscription number ${ subscriptionId }`,
} );

await expect( latestSubscriptionRow ).toBeVisible();
await latestSubscriptionRow
.getByRole( 'link', {
name: 'View',
} )
.nth( 0 )
.click();
await expect( latestSubscriptionRow ).toBeVisible();
await latestSubscriptionRow
.getByRole( 'link', {
name: 'View',
} )
.nth( 0 )
.click();

await shopperPage.waitForLoadState( 'networkidle' );
await shopperPage.waitForLoadState( 'networkidle' );

// Ensure 'Subscription totals' section lists the subscription products with the correct price.
const subTotalsRows = shopperPage.locator(
'.order_details tr.order_item'
);
for ( let i = 0; i < ( await subTotalsRows.count() ); i++ ) {
const row = subTotalsRows.nth( i );
await expect( row.getByRole( 'cell' ).nth( 1 ) ).toContainText(
Object.keys( products )[ i ]
// Ensure 'Subscription totals' section lists the subscription products with the correct price.
const subTotalsRows = shopperPage.locator(
'.order_details tr.order_item'
);
for ( let i = 0; i < ( await subTotalsRows.count() ); i++ ) {
const row = subTotalsRows.nth( i );
await expect(
row.getByRole( 'cell' ).nth( 1 )
).toContainText( Object.keys( products )[ i ] );

await expect( row.getByRole( 'cell' ).nth( 2 ) ).toContainText(
'$9.99 / month'
);
}
await expect(
row.getByRole( 'cell' ).nth( 2 )
).toContainText( '$9.99 / month' );
}

await expect(
shopperPage
.getByRole( 'row', { name: 'total:' } )
.getByRole( 'cell' )
.nth( 1 )
).toContainText( '$19.98 USD / month' );
await expect(
shopperPage
.getByRole( 'row', { name: 'total:' } )
.getByRole( 'cell' )
.nth( 1 )
).toContainText( '$19.98 USD / month' );

// Confirm related order total matches payment
await expect(
shopperPage.getByText( '$21.97 USD for 2 items' )
).toBeVisible();
} );
// Confirm related order total matches payment
await expect(
shopperPage.getByText( '$21.97 USD for 2 items' )
).toBeVisible();
}
);
}
);
Loading

0 comments on commit 6f99121

Please sign in to comment.