|
| 1 | +/** |
| 2 | + * External dependencies |
| 3 | + */ |
| 4 | +import test, { expect } from '@playwright/test'; |
| 5 | + |
| 6 | +/** |
| 7 | + * Internal dependencies |
| 8 | + */ |
| 9 | +import { config } from '../../config/default'; |
| 10 | +import { |
| 11 | + goToCart, |
| 12 | + goToCheckout, |
| 13 | + goToShop, |
| 14 | +} from '../../utils/shopper-navigation'; |
| 15 | +import { useShopper } from '../../utils/helpers'; |
| 16 | +import { |
| 17 | + addToCartFromShopPage, |
| 18 | + emptyCart, |
| 19 | + fillBillingAddress, |
| 20 | + fillCardDetails, |
| 21 | + placeOrder, |
| 22 | + setupCheckout, |
| 23 | +} from '../../utils/shopper'; |
| 24 | + |
| 25 | +const productName = config.products.simple.name; |
| 26 | + |
| 27 | +test.describe( |
| 28 | + 'Checkout with free coupon & after modifying cart on Checkout page', |
| 29 | + () => { |
| 30 | + // All tests will use the shopper only. |
| 31 | + useShopper(); |
| 32 | + |
| 33 | + test.beforeEach( async ( { page } ) => { |
| 34 | + await goToShop( page ); |
| 35 | + await addToCartFromShopPage( page, productName ); |
| 36 | + await goToCart( page ); |
| 37 | + await page.getByPlaceholder( 'Coupon code' ).fill( 'free' ); |
| 38 | + await page.getByRole( 'button', { name: 'Apply coupon' } ).click(); |
| 39 | + } ); |
| 40 | + |
| 41 | + test.afterEach( async ( { page } ) => { |
| 42 | + await emptyCart( page ); |
| 43 | + } ); |
| 44 | + |
| 45 | + test( 'Checkout with a free coupon', async ( { page } ) => { |
| 46 | + await goToCheckout( page ); |
| 47 | + await fillBillingAddress( page, config.addresses.customer.billing ); |
| 48 | + await placeOrder( page ); |
| 49 | + await page.waitForURL( /\/order-received\//, { |
| 50 | + waitUntil: 'load', |
| 51 | + } ); |
| 52 | + await expect( |
| 53 | + page.getByRole( 'heading', { |
| 54 | + name: 'Order received', |
| 55 | + } ) |
| 56 | + ).toBeVisible(); |
| 57 | + } ); |
| 58 | + |
| 59 | + test( 'Remove free coupon, then checkout', async ( { page } ) => { |
| 60 | + await goToCheckout( page ); |
| 61 | + await page.getByRole( 'link', { name: '[Remove]' } ).click(); |
| 62 | + await setupCheckout( page, config.addresses.customer.billing ); |
| 63 | + await fillCardDetails( page, config.cards.basic ); |
| 64 | + await placeOrder( page ); |
| 65 | + await page.waitForURL( /\/order-received\//, { |
| 66 | + waitUntil: 'load', |
| 67 | + } ); |
| 68 | + await expect( |
| 69 | + page.getByRole( 'heading', { |
| 70 | + name: 'Order received', |
| 71 | + } ) |
| 72 | + ).toBeVisible(); |
| 73 | + } ); |
| 74 | + } |
| 75 | +); |
0 commit comments