Skip to content

Commit 0b5ebb7

Browse files
authored
Added tests for errorPanel.card.visible.spec.ts and refactor custom card models (#3057)
* test(errorPanel.card.visible.spec.ts): added test * test(e2e): use `pressSequentially` for `customCard.ts` and `customCardSeparateExpiryDate.ts` models * test(e2e): added tests for customCard.spec.ts
1 parent 2c6271f commit 0b5ebb7

10 files changed

+76
-99
lines changed

packages/e2e-playwright/fixtures/URL_MAP.ts

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const URL_MAP = {
1212
* Card
1313
*/
1414
card: '/iframe.html?args=&id=cards-card--default&viewMode=story',
15+
cardWithVisibleSrPanel: '/iframe.html?args=srConfig.showPanel:!true&globals=&id=cards-card--default&viewMode=story',
1516
cardWithSsn: '/iframe.html?globals=&id=cards-card--with-ssn&viewMode=story',
1617
cardWithAdvancedFlow: '/iframe.html?args=useSessions:!false&globals=&id=cards-card--default&viewMode=story',
1718
cardWithAvs: '/iframe.html?args=&globals=&id=cards-card--with-avs&viewMode=story',

packages/e2e-playwright/models/customCard.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class CustomCard extends Base {
9393
}
9494

9595
async typeCardNumber(cardNumber: string) {
96-
await this.cardNumberInput.type(cardNumber, { delay: USER_TYPE_DELAY });
96+
await this.cardNumberInput.pressSequentially(cardNumber, { delay: USER_TYPE_DELAY });
9797
}
9898

9999
async deleteCardNumber() {
@@ -105,11 +105,11 @@ class CustomCard extends Base {
105105
}
106106

107107
async typeExpiryDate(expiryDate: string) {
108-
await this.expiryDateInput.type(expiryDate, { delay: USER_TYPE_DELAY });
108+
await this.expiryDateInput.pressSequentially(expiryDate, { delay: USER_TYPE_DELAY });
109109
}
110110

111111
async typeCvc(cvc: string) {
112-
await this.cvcInput.type(cvc, { delay: USER_TYPE_DELAY });
112+
await this.cvcInput.pressSequentially(cvc, { delay: USER_TYPE_DELAY });
113113
}
114114
}
115115

packages/e2e-playwright/models/customCardSeparateExpiryDate.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,10 @@ class CustomCardSeparateExpiryDate extends CustomCard {
7272
}
7373

7474
async typeExpiryMonth(expiryMonth: string) {
75-
await this.expiryMonthInput.type(expiryMonth, { delay: USER_TYPE_DELAY });
75+
await this.expiryMonthInput.pressSequentially(expiryMonth, { delay: USER_TYPE_DELAY });
7676
}
7777
async typeExpiryYear(expiryYear: string) {
78-
await this.expiryYearInput.type(expiryYear, { delay: USER_TYPE_DELAY });
78+
await this.expiryYearInput.pressSequentially(expiryYear, { delay: USER_TYPE_DELAY });
7979
}
8080
}
8181

Original file line numberDiff line numberDiff line change
@@ -1,28 +1,55 @@
1-
import { test } from '@playwright/test';
1+
import { mergeTests, expect } from '@playwright/test';
2+
import { test as card } from '../../../fixtures/card.fixture';
3+
import { test as srPanel } from '../../../fixtures/srPanel.fixture';
4+
import { URL_MAP } from '../../../fixtures/URL_MAP';
5+
import { REGULAR_TEST_CARD } from '../../utils/constants';
26

3-
test('#1 Error panel is present at start, when there are no errors, but is empty', async () => {
4-
// Wait for field to appear in DOM
5-
// error panel exists but is empty
7+
const test = mergeTests(card, srPanel);
8+
9+
test('#1 Error panel is present at start, when there are no errors, but is empty', async ({ card, srPanel }) => {
10+
await card.goto(URL_MAP.cardWithVisibleSrPanel);
11+
expect(await srPanel.allMessages).toHaveLength(0);
612
});
713

8-
test('#2 Click pay with empty fields and error panel is populated', async () => {
9-
// Wait for field to appear in DOM
10-
// click pay, to validate & generate errors
11-
// Expect 3 elements, in order, with specific text
12-
// expect(cardPage.errorPanelEls.nth(0).withExactText(CARD_NUMBER_EMPTY).exists)
13-
// expect(cardPage.errorPanelEls.nth(1).withExactText(EXPIRY_DATE_EMPTY).exists)
14-
// expect(cardPage.errorPanelEls.nth(2).withExactText(CVC_EMPTY).exists)
15-
// no 4th element
16-
// Expect focus to be place on Card number field - since SRConfig for this card comp says it should be
14+
test('#2 Click pay with empty fields and error panel is populated', async ({ card, srPanel, page, browserName }) => {
15+
const expectedSRPanelTexts = ['Enter the card number-sr', 'Enter the expiry date-sr', 'Enter the security code-sr'];
16+
await card.goto(URL_MAP.cardWithVisibleSrPanel);
17+
await card.pay();
18+
// Wait for all sr panel messages
19+
await page.waitForFunction(
20+
expectedLength => [...document.querySelectorAll('.adyen-checkout-sr-panel__msg')].map(el => el.textContent).length === expectedLength,
21+
expectedSRPanelTexts.length
22+
);
23+
// check individual messages
24+
const srErrorMessages = await srPanel.allMessages;
25+
srErrorMessages.forEach((retrievedText, index) => {
26+
expect(retrievedText).toHaveText(expectedSRPanelTexts[index]);
27+
});
28+
if (browserName !== 'firefox') {
29+
await expect(card.cardNumberInput).toBeFocused();
30+
} else {
31+
console.log('Skipping focus check for Firefox');
32+
}
1733
});
1834

19-
test('#3 Fill out PAN & see that first error in error panel is date related', async () => {
20-
// Wait for field to appear in DOM
21-
// await cardPage.cardUtils.fillCardNumber(t, REGULAR_TEST_CARD);
22-
// click pay, to validate & generate errors
23-
// Expect 2 elements, in order, with specific text
24-
// expect(cardPage.errorPanelEls.nth(0).withExactText(EXPIRY_DATE_EMPTY).exists)
25-
// expect(cardPage.errorPanelEls.nth(1).withExactText(CVC_EMPTY).exists)
26-
// no 3rd element
27-
// Expect focus to be place on Expiry date field
35+
test('#3 Fill out PAN & see that first error in error panel is date related', async ({ card, srPanel, page, browserName }) => {
36+
const expectedSRPanelTexts = ['Enter the expiry date-sr', 'Enter the security code-sr'];
37+
await card.goto(URL_MAP.cardWithVisibleSrPanel);
38+
await card.fillCardNumber(REGULAR_TEST_CARD);
39+
await card.pay();
40+
// Wait for all sr panel messages
41+
await page.waitForFunction(
42+
expectedLength => [...document.querySelectorAll('.adyen-checkout-sr-panel__msg')].map(el => el.textContent).length === expectedLength,
43+
expectedSRPanelTexts.length
44+
);
45+
// check individual messages
46+
const srErrorMessages = await srPanel.allMessages;
47+
srErrorMessages.forEach((retrievedText, index) => {
48+
expect(retrievedText).toHaveText(expectedSRPanelTexts[index]);
49+
});
50+
if (browserName !== 'firefox') {
51+
await expect(card.expiryDateInput).toBeFocused();
52+
} else {
53+
console.log('Skipping focus check for Firefox');
54+
}
2855
});
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import { test, expect } from '../../../fixtures/customCard.fixture';
2-
import { PAYMENT_RESULT, REGULAR_TEST_CARD, TEST_CVC_VALUE, TEST_DATE_VALUE } from '../../utils/constants';
2+
import { PAYMENT_RESULT, REGULAR_TEST_CARD, TEST_CVC_VALUE, TEST_DATE_VALUE, TEST_MONTH_VALUE, TEST_YEAR_VALUE } from '../../utils/constants';
33

44
test.describe('Custom Card - Standard flow', () => {
5-
test('should fill in card fields and complete the payment', async ({ customCard }) => {
5+
test('should fill out the fields in the regular custom card and make a successful payment', async ({ customCard }) => {
66
await customCard.typeCardNumber(REGULAR_TEST_CARD);
77
await customCard.typeExpiryDate(TEST_DATE_VALUE);
88
await customCard.typeCvc(TEST_CVC_VALUE);
99
await customCard.pay();
1010
await expect(customCard.paymentResult).toContainText(PAYMENT_RESULT.authorised);
1111
});
12+
13+
test('should fill out the fields in the separate custom card and make a successful payment', async ({ customCardSeparateExpiryDate }) => {
14+
await customCardSeparateExpiryDate.typeCardNumber(REGULAR_TEST_CARD);
15+
await customCardSeparateExpiryDate.typeExpiryMonth(TEST_MONTH_VALUE);
16+
await customCardSeparateExpiryDate.typeExpiryYear(TEST_YEAR_VALUE);
17+
await customCardSeparateExpiryDate.typeCvc(TEST_CVC_VALUE);
18+
await customCardSeparateExpiryDate.pay();
19+
await expect(customCardSeparateExpiryDate.paymentResult).toContainText(PAYMENT_RESULT.authorised);
20+
});
1221
});

packages/e2e-playwright/tests/ui/customCard/expiryDate/customCard.regular.expiryDatePolicies.optional.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ test.describe('Test how Custom Card Component with regular date field handles hi
9595
await expect(cardErrors[ENCRYPTED_EXPIRY_DATE]).toBe(null);
9696
await expect(cardErrors[ENCRYPTED_SECURITY_CODE]).toBe(null);
9797
});
98-
// todo: flaky
99-
test.fixme('#4 date field in error DOES stop card becoming valid', async ({ page, customCard }) => {
98+
99+
test('#4 date field in error DOES stop card becoming valid', async ({ page, customCard }) => {
100100
await binLookupMock(page, optionalDateAndCvcMock);
101101

102102
// Card out of date

packages/e2e-playwright/tests/ui/customCard/expiryDate/customCard.separate.expiryDatePolicies.hidden.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ test.describe('Test how Custom Card Component with separate date field handles h
7777
let cardValid = await page.evaluate('window.customCardSeparate.isValid');
7878
await expect(cardValid).toEqual(true);
7979
});
80-
// todo: flaky
81-
test.fixme('#3 date field in error does not stop card becoming valid', async ({ page, customCardSeparateExpiryDate }) => {
80+
81+
test('#3 date field in error does not stop card becoming valid', async ({ page, customCardSeparateExpiryDate }) => {
8282
await binLookupMock(page, hiddenDateAndCvcMock);
8383

8484
// Card out of date

packages/e2e-playwright/tests/ui/customCard/expiryDate/customCard.separate.expiryDatePolicies.optional.spec.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ test.describe('Test how Custom Card Component with separate date fields handles
112112
let cardValid = await page.evaluate('window.customCardSeparate.isValid');
113113
await expect(cardValid).toEqual(true);
114114
});
115-
// todo: flaky.
116-
test.fixme('#4 date field in error DOES stop card becoming valid', async ({ page, customCardSeparateExpiryDate }) => {
115+
116+
test('#4 date field in error DOES stop card becoming valid', async ({ page, customCardSeparateExpiryDate }) => {
117117
await binLookupMock(page, optionalDateAndCvcMock);
118118

119119
// Card out of date

packages/e2e-playwright/tests/ui/customCard/general/general.spec.ts

-62
This file was deleted.

packages/lib/storybook/stories/components/Donation.stories.tsx

+4-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ const componentConfiguration: DonationConfiguration = {
1111
onCancel: () => alert('Donation canceled'),
1212
nonprofitName: 'Test Charity',
1313
nonprofitUrl: 'https://example.org',
14-
nonprofitDescription: 'Lorem ipsum...',
14+
nonprofitDescription:
15+
'Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.',
1516
donation: {
1617
type: 'fixedAmounts',
1718
currency: 'EUR',
@@ -20,7 +21,8 @@ const componentConfiguration: DonationConfiguration = {
2021
termsAndConditionsUrl: 'https://www.adyen.com',
2122
bannerUrl: '/banner.png',
2223
logoUrl: '/logo.png',
23-
commercialTxAmount: 1000
24+
commercialTxAmount: 1000,
25+
causeName: 'Earthquake Turkey & Syria'
2426
};
2527

2628
type DonationStory = StoryConfiguration<DonationConfiguration>;

0 commit comments

Comments
 (0)