-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Chore cherry-pick 6.1.1 to v5 (#2827)
* Improves accessibility by removing region on payment method item and button loading state (#2816) * small a11y improvement * go back to disabled * make it visually hidden * fix mixin import (cherry picked from commit 18172bb) * Fixes LT postal code (#2822) * fix LT postal code also add AddressElement to storybook adds some test to validate * add changeset (cherry picked from commit 9d005c3) * change for v5
- Loading branch information
Showing
9 changed files
with
209 additions
and
9 deletions.
There are no files selected for viewing
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,5 @@ | ||
--- | ||
'@adyen/adyen-web': patch | ||
--- | ||
|
||
Fixes Lithuanian postal code to support 4-5 digits and LT prefix |
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,5 @@ | ||
--- | ||
'@adyen/adyen-web': patch | ||
--- | ||
|
||
Improves acessibility removing region on payment method item and button loading state |
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
140 changes: 140 additions & 0 deletions
140
packages/lib/src/components/internal/Address/validate.test.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,140 @@ | ||
import { validatePostalCode } from './validate'; | ||
import { ValidatorRules } from '../../../utils/Validator/types'; | ||
|
||
describe('validatePostalCode', () => { | ||
const validatorRules: ValidatorRules = { | ||
postalCode: { | ||
modes: ['blur'], | ||
validate: jest.fn(), | ||
errorMessage: '' | ||
} | ||
}; | ||
|
||
// LT | ||
it('should return true for a valid LT postal code without the LT prefix', () => { | ||
const result = validatePostalCode('12345', 'LT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid LT postal code without the LT prefix (4-digits)', () => { | ||
const result = validatePostalCode('1234', 'LT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid LT postal code with the LT prefix', () => { | ||
const result = validatePostalCode('LT-12345', 'LT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false for a valid LT postal code with the LT prefix but only 4 digits', () => { | ||
const result = validatePostalCode('LT-1235', 'LT', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false for an invalid LT postal code with fewer than 4 digits', () => { | ||
const result = validatePostalCode('123', 'LT', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
it('should return false for an invalid LT postal code with fewer than 6 digits', () => { | ||
const result = validatePostalCode('1234567', 'LT', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
// BR | ||
it('should return true for a valid BR postal code with hyphen', () => { | ||
const result = validatePostalCode('12345-678', 'BR', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid BR postal code without hyphen', () => { | ||
const result = validatePostalCode('12345678', 'BR', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid BR postal code', () => { | ||
const result = validatePostalCode('1234-5678', 'BR', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
// US and the ones using createPatternByDigits | ||
it('should return true for a valid US postal code with 5 digits', () => { | ||
const result = validatePostalCode('12345', 'US', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
// It fails because createPatternByDigits actually just check if there's at least X amount of digits | ||
// it('should return false for an invalid US postal code with more than 5 digits without a hyphen', () => { | ||
// const result = validatePostalCode('1234567', 'US', validatorRules); | ||
// expect(result).toBe(false); | ||
// }); | ||
|
||
// General | ||
it('should return null if the postal code is empty', () => { | ||
const result = validatePostalCode('', 'AT', validatorRules); | ||
expect(result).toBeNull(); | ||
}); | ||
|
||
it('should return true for a valid AT postal code', () => { | ||
const result = validatePostalCode('1234', 'AT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
// PT | ||
it('should return true for a valid PT postal code without hyphen', () => { | ||
const result = validatePostalCode('1234567', 'PT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid PT postal code with hyphen', () => { | ||
const result = validatePostalCode('1234-567', 'PT', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid PT postal code with incorrect format', () => { | ||
const result = validatePostalCode('123-4567', 'PT', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
// it('should return true for an PT postal code with just the part before the hyphen', () => { | ||
// const result = validatePostalCode('1234', 'PT', validatorRules); | ||
// expect(result).toBe(true); | ||
// }); | ||
|
||
// NL | ||
it('should return true for a valid NL postal code without NL prefix', () => { | ||
const result = validatePostalCode('1234AB', 'NL', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid NL postal code with space between digits and letters', () => { | ||
const result = validatePostalCode('1234 AB', 'NL', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return true for a valid NL postal code with NL prefix', () => { | ||
const result = validatePostalCode('NL-1234AB', 'NL', validatorRules); | ||
expect(result).toBe(true); | ||
}); | ||
|
||
it('should return false for an invalid NL postal code with missing letters', () => { | ||
const result = validatePostalCode('1234', 'NL', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
// Againt it seems like it's missing begining and end ^ $ symbols in the regex (same as US) | ||
// it('should return false for an invalid NL postal code with incorrect letter combination', () => { | ||
// const result = validatePostalCode('1234AA1', 'NL', validatorRules); | ||
// expect(result).toBe(false); | ||
// }); | ||
|
||
it('should return false for an invalid NL postal code with fewer digits', () => { | ||
const result = validatePostalCode('123AB', 'NL', validatorRules); | ||
expect(result).toBe(false); | ||
}); | ||
|
||
// it('should return false for an invalid NL postal code with too many digits', () => { | ||
// const result = validatePostalCode('12345AB', 'NL', validatorRules); | ||
// expect(result).toBe(false); | ||
// }); | ||
}); |
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
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
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
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
38 changes: 38 additions & 0 deletions
38
packages/lib/storybook/stories/internals/Address.stories.tsx
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,38 @@ | ||
import { Meta } from '@storybook/preact'; | ||
import Address from '../../../src/components/internal/Address'; | ||
import { getStoryContextCheckout } from '../../utils/get-story-context-checkout'; | ||
import { Container } from '../Container'; | ||
import AddressElement from '../../../src/components/Address/Address'; | ||
|
||
const meta: Meta = { | ||
title: 'Internals/Address', | ||
component: Address, | ||
argTypes: { | ||
size: { | ||
options: ['small', 'medium', 'large'], | ||
control: { type: 'radio' } | ||
} | ||
}, | ||
args: { | ||
size: 'large' | ||
} | ||
}; | ||
|
||
export const Default = { | ||
render: (args, context) => { | ||
const { componentConfiguration } = args; | ||
const checkout = getStoryContextCheckout(context); | ||
const address = new AddressElement(checkout, componentConfiguration); | ||
return <Container element={address} />; | ||
}, | ||
args: { | ||
countryCode: 'NL', | ||
amount: 2000, | ||
useSessions: false | ||
}, | ||
parameters: { | ||
controls: { exclude: ['useSessions', 'countryCode', 'shopperLocale', 'amount', 'showPayButton'] } | ||
} | ||
}; | ||
|
||
export default meta; |