Skip to content

Commit

Permalink
test(avs.spec.ts): added address lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
longyulongyu committed Nov 14, 2024
1 parent 3ef11b1 commit 9f701f7
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 7 deletions.
16 changes: 16 additions & 0 deletions packages/e2e-playwright/models/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,17 @@ class Address {
return this.rootElement.getByRole('combobox', { name: /state/i });
}

get addressSearchInput() {
return this.rootElement.getByRole('combobox', { name: /address/i });
}

async fillInPostCode(postCode: string) {
await this.postalCodeInput.waitFor({ state: 'visible' });
await this.postalCodeInput.fill(postCode);
}

async selectState(options: { name?: RegExp | string }) {
await this.stateInput.waitFor({ state: 'visible' });
await this.stateInput.click();
await this.rootElement.getByRole('option', options).click();
}
Expand All @@ -76,8 +82,18 @@ class Address {
}

async fillInCity(city: string) {
await this.cityInput.waitFor({ state: 'visible' });
await this.cityInput.fill(city);
}

async searchAddressAndChooseTheFirst(query: string) {
await this.addressSearchInput.click();
await this.addressSearchInput.fill(query);
await this.rootElement
.getByRole('option', { name: new RegExp(query, 'i') })
.first()
.click();
}
}

export { Address };
2 changes: 1 addition & 1 deletion packages/e2e-playwright/models/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export abstract class Base {
await this.isComponentVisible();
}

async pay(options: { name?: RegExp | string } = { name: /^Pay/i }): Promise<void> {
async pay(options: { name?: RegExp | string } = { name: /pay/i }): Promise<void> {
if (this.payButton) {
await this.payButton.click();
} else {
Expand Down
4 changes: 0 additions & 4 deletions packages/e2e-playwright/models/card-avs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ class CardWithAvs extends Card {
super(page);
this.billingAddress = new Address(page);
}

async fillInPostCode(postCode: string) {
await this.billingAddress.fillInPostCode(postCode);
}
}

export { CardWithAvs };
17 changes: 15 additions & 2 deletions packages/e2e-playwright/tests/e2e/card/avs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { URL_MAP } from '../../../fixtures/URL_MAP';

const fullAvsWithoutPrefilledDataUrl = '/iframe.html?args=componentConfiguration.data:!undefined&globals=&id=cards-card--with-avs&viewMode=story';
const fullAvsWithPrefilledDataUrl = '/iframe.html?globals=&args=&id=cards-card--with-avs&viewMode=story';
const addressLookupUrl = '/iframe.html?id=cards-card--with-avs-address-lookup&viewMode=story';

type Fixture = {
cardWithAvs: CardWithAvs;
Expand All @@ -16,7 +17,19 @@ const test = base.extend<Fixture>({
}
});

test.describe('Card payments with address lookup', () => {});
test.describe('Card payments with address lookup', () => {
test('should make a successful card payment', async ({ cardWithAvs }) => {
await cardWithAvs.goto(addressLookupUrl);
await cardWithAvs.fillCardNumber(REGULAR_TEST_CARD);
await cardWithAvs.fillExpiryDate(TEST_DATE_VALUE);
await cardWithAvs.fillCvc(TEST_CVC_VALUE);

await cardWithAvs.billingAddress.searchAddressAndChooseTheFirst('1');
await cardWithAvs.pay();
await cardWithAvs.paymentResult.waitFor({ state: 'visible' });
await expect(cardWithAvs.paymentResult).toContainText(PAYMENT_RESULT.authorised);
});
});

test.describe('Card payments with partial avs', () => {
test.describe('When fill in a valid the post code', () => {
Expand All @@ -25,7 +38,7 @@ test.describe('Card payments with partial avs', () => {
await cardWithAvs.fillCardNumber(REGULAR_TEST_CARD);
await cardWithAvs.fillExpiryDate(TEST_DATE_VALUE);
await cardWithAvs.fillCvc(TEST_CVC_VALUE);
await cardWithAvs.fillInPostCode(TEST_POSTCODE);
await cardWithAvs.billingAddress.fillInPostCode(TEST_POSTCODE);
await cardWithAvs.pay();
await cardWithAvs.paymentResult.waitFor({ state: 'visible' });
await expect(cardWithAvs.paymentResult).toContainText(PAYMENT_RESULT.authorised);
Expand Down

0 comments on commit 9f701f7

Please sign in to comment.