Skip to content

Commit 03572cb

Browse files
authored
Fixes regression and allows Enter key to validate/submit (#2837)
* Fixes regression and allows Enter key to validate/submit * Expanding e2e tests * Removing CardInput default props that are actually only Card level props * No longer any need to exclude onEnterKeyPressed from Card default props * Adding conditional chaining operator now that onBinLookup is not defined by default
1 parent e6153e8 commit 03572cb

File tree

8 files changed

+53
-16
lines changed

8 files changed

+53
-16
lines changed

.changeset/cool-comics-own.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@adyen/adyen-web': patch
3+
---
4+
5+
Fixes regression and allows Enter key to validate/submit

packages/e2e-playwright/tests/card/card.spec.ts

+35
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
import { test, expect } from '../../pages/cards/card.fixture';
22
import { REGULAR_TEST_CARD, TEST_CVC_VALUE, TEST_DATE_VALUE } from '../utils/constants';
33
import LANG from '../../../server/translations/en-US.json';
4+
import { pressEnter } from '../utils/keyboard';
45

56
const PAN_ERROR_NOT_VALID = LANG['cc.num.902'];
67
const PAN_ERROR_EMPTY = LANG['cc.num.900'];
78
const PAN_ERROR_NOT_COMPLETE = LANG['cc.num.901'];
89

10+
const EXPIRY_DATE_ERROR_EMPTY = LANG['cc.dat.910'];
11+
const CVC_ERROR_EMPTY = LANG['cc.cvc.920'];
12+
913
test.describe('Card - Standard flow', () => {
1014
test('#1 Should fill in card fields and complete the payment', async ({ cardPage }) => {
1115
const { card, page } = cardPage;
@@ -49,4 +53,35 @@ test.describe('Card - Standard flow', () => {
4953
await expect(card.cardNumberErrorElement).toBeVisible();
5054
await expect(card.cardNumberErrorElement).toHaveText(PAN_ERROR_NOT_COMPLETE);
5155
});
56+
57+
test('#5 Filling PAN then pressing Enter will trigger validation ', async ({ cardPage }) => {
58+
const { card, page } = cardPage;
59+
60+
await card.isComponentVisible();
61+
await card.typeCardNumber(REGULAR_TEST_CARD);
62+
63+
await pressEnter(page);
64+
65+
await page.waitForTimeout(500); // wait for UI to show errors
66+
67+
await expect(card.expiryDateErrorElement).toBeVisible();
68+
await expect(card.expiryDateErrorElement).toHaveText(EXPIRY_DATE_ERROR_EMPTY);
69+
70+
await expect(card.cvcErrorElement).toBeVisible();
71+
await expect(card.cvcErrorElement).toHaveText(CVC_ERROR_EMPTY);
72+
});
73+
74+
test('#6 Filling in card fields then pressing Enter will trigger submission ', async ({ cardPage }) => {
75+
const { card, page } = cardPage;
76+
77+
await card.isComponentVisible();
78+
79+
await card.typeCardNumber(REGULAR_TEST_CARD);
80+
await card.typeCvc(TEST_CVC_VALUE);
81+
await card.typeExpiryDate(TEST_DATE_VALUE);
82+
83+
await pressEnter(page);
84+
85+
await expect(page.locator('#result-message')).toHaveText('Authorised');
86+
});
5287
});

packages/e2e-playwright/tests/card/installments/card.installments.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ test.describe('Cards (Installments)', () => {
7272
await card.installmentsDropdown.click();
7373
await pressKeyboardToNextItem(page);
7474
await pressKeyboardToNextItem(page);
75-
// await pressKeyboardToSelectItem(page);
75+
// await pressEnter(page);
7676

7777
const listItem = await card.selectListItem('2');
7878
await listItem.click();

packages/e2e-playwright/tests/issuerList/issuer-list.spec.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { test, expect } from '../../pages/issuerList/issuer-list.fixture';
2-
import { pressKeyboardToNextItem, pressKeyboardToSelectItem } from '../utils/keyboard';
2+
import { pressKeyboardToNextItem, pressEnter } from '../utils/keyboard';
33

44
test.describe('Issuer List', () => {
55
test('it should be able to filter and select using the keyboard', async ({ issuerListPage }) => {
@@ -15,15 +15,15 @@ test.describe('Issuer List', () => {
1515

1616
// select one of the filtered option
1717
await pressKeyboardToNextItem(page); // Arrow down
18-
await pressKeyboardToSelectItem(page); // Enter key
18+
await pressEnter(page); // Enter key
1919

2020
await expect(issuerList.submitButton).toHaveText('Continue to Idea Cloud');
2121

2222
// 1st press opens the dropdown
2323
await pressKeyboardToNextItem(page);
2424
// 2nd selects next item
2525
await pressKeyboardToNextItem(page);
26-
await pressKeyboardToSelectItem(page);
26+
await pressEnter(page);
2727

2828
await expect(issuerList.submitButton).toHaveText('Continue to mRaty');
2929
});
@@ -33,7 +33,7 @@ test.describe('Issuer List', () => {
3333

3434
await issuerList.clickOnSelector();
3535
await issuerList.typeOnSelectorField('Nest');
36-
await pressKeyboardToSelectItem(page);
36+
await pressEnter(page);
3737

3838
await expect(issuerList.submitButton).toHaveText('Continue to Nest Bank');
3939
});
@@ -44,7 +44,7 @@ test.describe('Issuer List', () => {
4444
// Open the drop down and select an item
4545
await issuerList.clickOnSelector();
4646
await pressKeyboardToNextItem(page); // Arrow down
47-
await pressKeyboardToSelectItem(page); // Enter key
47+
await pressEnter(page); // Enter key
4848

4949
let issuerListData = await page.evaluate('window.dotpay.data');
5050

packages/e2e-playwright/tests/utils/keyboard.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ export const pressKeyboardToPreviousItem = async page => {
88
await page.keyboard.press('ArrowUp', { delay: KEYBOARD_DELAY });
99
};
1010

11-
export const pressKeyboardToSelectItem = async page => {
11+
export const pressEnter = async page => {
1212
await page.keyboard.press('Enter', { delay: KEYBOARD_DELAY });
1313
};

packages/lib/src/components/Card/Card.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export class CardElement extends UIElement<CardConfiguration> {
198198
// Handler for regular card comp doesn't need this 'raw' data or to know about 'resets'
199199
if (!obj.isReset) {
200200
const nuObj = reject('supportedBrandsRaw').from(obj);
201-
this.props.onBinLookup(nuObj);
201+
this.props.onBinLookup?.(nuObj);
202202
}
203203
}
204204

packages/lib/src/components/Card/components/CardInput/defaultProps.ts

+1-5
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,5 @@ export default {
5050
onBinValue: (): any => {},
5151
onBlur: (): any => {},
5252
onFocus: (): any => {},
53-
onChange: (): any => {},
54-
55-
// Strictly speaking a Card level props, but needed here for analytics.configData
56-
onBinLookup: () => {},
57-
onEnterKeyPressed: () => {}
53+
onChange: (): any => {}
5854
};

packages/lib/src/core/Analytics/utils.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -183,15 +183,16 @@ export const getCardConfigData = (cardProps: CardConfiguration): CardConfigData
183183
/** callbacks */
184184
// We need to detect if the merchant themselves has defined these, not if we've set them as a default
185185
hasOnAllValid: onAllValid !== CardInputDefaultProps.onAllValid,
186-
hasOnBinLookup: onBinLookup !== CardInputDefaultProps.onBinLookup,
187186
hasOnBinValue: onBinValue !== CardInputDefaultProps.onBinValue,
188187
hasOnBlur: onBlur !== CardInputDefaultProps.onBlur,
189188
hasOnBrand: onBrand !== CardInputDefaultProps.onBrand,
190189
hasOnConfigSuccess: onConfigSuccess !== CardInputDefaultProps.onConfigSuccess,
191-
hasOnEnterKeyPressed: onEnterKeyPressed !== CardInputDefaultProps.onEnterKeyPressed,
192190
hasOnFieldValid: onFieldValid !== CardInputDefaultProps.onFieldValid,
193191
hasOnFocus: onFocus !== CardInputDefaultProps.onFocus,
194-
hasOnLoad: onLoad !== CardInputDefaultProps.onLoad
192+
hasOnLoad: onLoad !== CardInputDefaultProps.onLoad,
193+
// Card level props
194+
hasOnBinLookup: !!onBinLookup,
195+
hasOnEnterKeyPressed: !!onEnterKeyPressed
195196
};
196197

197198
return configData;

0 commit comments

Comments
 (0)