-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert shopper purchasing multiple subscriptions E2E test to Playwri…
…ght (#10170)
- Loading branch information
Showing
3 changed files
with
135 additions
and
110 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
changelog/dev-10087-playwright-migration-shopper-subscriptions-purchase-multiple
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: dev | ||
|
||
Convert shopper purchase multiple subscriptions E2E tests to Playwright |
131 changes: 131 additions & 0 deletions
131
tests/e2e-pw/specs/shopper/shopper-subscriptions-purchase-multiple-subscriptions.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/** | ||
* External dependencies | ||
*/ | ||
import test, { Page, expect } from '@playwright/test'; | ||
|
||
/** | ||
* Internal dependencies | ||
*/ | ||
import { shouldRunSubscriptionsTests } from '../../utils/constants'; | ||
import { describeif, getMerchant, getShopper } from '../../utils/helpers'; | ||
import RestAPI from '../../utils/rest-api'; | ||
import { config } from '../../config/default'; | ||
import { | ||
emptyCart, | ||
fillCardDetails, | ||
placeOrder, | ||
setupProductCheckout, | ||
} from '../../utils/shopper'; | ||
import { | ||
goToShop, | ||
goToShopWithCurrency, | ||
goToSubscriptions, | ||
} from '../../utils/shopper-navigation'; | ||
import { | ||
activateMulticurrency, | ||
deactivateMulticurrency, | ||
restoreCurrencies, | ||
} from '../../utils/merchant'; | ||
|
||
const products = { | ||
'Subscription no signup fee product': 'subscription-no-signup-fee-product', | ||
'Subscription signup fee product': 'subscription-signup-fee-product', | ||
}; | ||
const configBillingAddress = config.addresses.customer.billing; | ||
let wasMulticurrencyEnabled = false; | ||
|
||
describeif( shouldRunSubscriptionsTests )( | ||
'Subscriptions > Purchase multiple subscriptions', | ||
() => { | ||
let merchantPage: Page, shopperPage: Page; | ||
test.beforeAll( async ( { browser }, { project } ) => { | ||
const restApi = new RestAPI( project.use.baseURL ); | ||
await restApi.deleteCustomerByEmailAddress( | ||
configBillingAddress.email | ||
); | ||
merchantPage = ( await getMerchant( browser ) ).merchantPage; | ||
shopperPage = ( await getShopper( browser ) ).shopperPage; | ||
wasMulticurrencyEnabled = await activateMulticurrency( | ||
merchantPage | ||
); | ||
await restoreCurrencies( merchantPage ); | ||
} ); | ||
|
||
test.afterAll( async () => { | ||
if ( ! wasMulticurrencyEnabled ) { | ||
await deactivateMulticurrency( merchantPage ); | ||
} | ||
} ); | ||
|
||
test( ' should be able to purchase multiple subscriptions', async () => { | ||
// As a Shopper, purchase the subscription products. | ||
await emptyCart( shopperPage ); | ||
await goToShopWithCurrency( shopperPage, 'USD' ); | ||
await goToShop( shopperPage, 2 ); | ||
await setupProductCheckout( | ||
shopperPage, | ||
Object.keys( products ).map( ( productName: string ) => [ | ||
productName, | ||
1, | ||
] ), | ||
configBillingAddress | ||
); | ||
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( '#', '' ); | ||
|
||
await goToSubscriptions( shopperPage ); | ||
|
||
const latestSubscriptionRow = shopperPage.getByRole( 'row', { | ||
name: `subscription number ${ subscriptionId }`, | ||
} ); | ||
|
||
await expect( latestSubscriptionRow ).toBeVisible(); | ||
await latestSubscriptionRow | ||
.getByRole( 'link', { | ||
name: 'View', | ||
} ) | ||
.nth( 0 ) | ||
.click(); | ||
|
||
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 ] | ||
); | ||
|
||
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' ); | ||
|
||
// Confirm related order total matches payment | ||
await expect( | ||
shopperPage.getByText( '$21.97 USD for 2 items' ) | ||
).toBeVisible(); | ||
} ); | ||
} | ||
); |
110 changes: 0 additions & 110 deletions
110
...specs/subscriptions/shopper/shopper-subscriptions-purchase-multiple-subscriptions.spec.js
This file was deleted.
Oops, something went wrong.