-
Notifications
You must be signed in to change notification settings - Fork 3.7k
feat: improve expiration date input format by auto-inserting slash after month #65079
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
MonilBhavsar
merged 20 commits into
Expensify:main
from
samranahm:64608/expiration-date-input-format
Jul 14, 2025
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
24b67f9
fix: auto-format expiration date input in AddPaymentCard form
samranahm 9b79287
use prevValue.length less than 2 to add slash
samranahm 85a24c9
remove didAutoCorrectFirstDigit check
samranahm d749d92
use first char 1 from value for month above 12 bellow 19
samranahm 45f6951
Merge branch 'Expensify:main' into 64608/expiration-date-input-format
samranahm c00b03e
fix code format with prettier
samranahm 30b2d76
Update translation in all locales
samranahm c74ecb1
fix: lint error
samranahm 3c6d33f
fix: prevent entering 00 as month by rejecting second 0
samranahm 5a3158c
fix: handle edge case where user pastes 001 or similar value, replace…
samranahm 11e69d2
fix: changed files ESLint
samranahm 8c250f2
update expiration date validation
samranahm 02fac7e
Fix expiration value formatting for 3-digit pasted input
samranahm c43d363
Add testID to Expiration date InputWrapper
samranahm a79f68d
add unit test for expiration date formatting
samranahm d2ec4e5
Fix typo in variable name previousValueRef
samranahm 0b30d95
Merge branch 'Expensify:main' into 64608/expiration-date-input-format
samranahm 8c8f4bb
fix code format and typo in variable name
samranahm fa33e0e
add comment to explain expiration date formatting
samranahm 01591fa
fix prettier
samranahm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,122 @@ | ||
| import {PortalProvider} from '@gorhom/portal'; | ||
| import {NavigationContainer} from '@react-navigation/native'; | ||
| import {createStackNavigator} from '@react-navigation/stack'; | ||
| import {fireEvent, render, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
| import OnyxProvider from '@components/OnyxProvider'; | ||
| import {CurrentReportIDContextProvider} from '@hooks/useCurrentReportID'; | ||
| import AddPaymentCard from '@pages/settings/Subscription/PaymentCard'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import SCREENS from '@src/SCREENS'; | ||
|
|
||
| jest.mock('@react-native-community/geolocation', () => ({ | ||
| setRNConfiguration: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@libs/ReportUtils', () => ({ | ||
| UnreadIndicatorUpdaterHelper: jest.fn(), | ||
| getReportIDFromLink: jest.fn(() => ''), | ||
| parseReportRouteParams: jest.fn(() => ({reportID: ''})), | ||
| })); | ||
|
|
||
| jest.mock('@pages/settings/Subscription/PaymentCard', () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return jest.requireActual('@pages/settings/Subscription/PaymentCard/index.tsx'); | ||
| }); | ||
|
|
||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| afterAll(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('Subscription/AddPaymentCard', () => { | ||
| const Stack = createStackNavigator(); | ||
|
|
||
| const renderAddPaymentCardPage = (initialRouteName: typeof SCREENS.SETTINGS.SUBSCRIPTION.ADD_PAYMENT_CARD) => { | ||
| return render( | ||
| <ComposeProviders components={[OnyxProvider, LocaleContextProvider, CurrentReportIDContextProvider]}> | ||
| <PortalProvider> | ||
| <NavigationContainer> | ||
| <Stack.Navigator initialRouteName={initialRouteName}> | ||
| <Stack.Screen | ||
| name={SCREENS.SETTINGS.SUBSCRIPTION.ADD_PAYMENT_CARD} | ||
| component={AddPaymentCard} | ||
| /> | ||
| </Stack.Navigator> | ||
| </NavigationContainer> | ||
| </PortalProvider> | ||
| </ComposeProviders>, | ||
| ); | ||
| }; | ||
|
|
||
| describe('AddPaymentCardPage Expiration Date Formatting', () => { | ||
| const runFormatTest = async (input: string, formattedAs: string) => { | ||
| renderAddPaymentCardPage(SCREENS.SETTINGS.SUBSCRIPTION.ADD_PAYMENT_CARD); | ||
| const expirationDateField = await screen.findByTestId('addPaymentCardPage.expiration'); | ||
| fireEvent.changeText(expirationDateField, input); | ||
| expect(expirationDateField.props.value).toBe(formattedAs); | ||
| }; | ||
|
|
||
| it('formats "0" as "0"', async () => { | ||
| await runFormatTest('0', '0'); | ||
| }); | ||
|
|
||
| it('formats "2" as "02/"', async () => { | ||
| await runFormatTest('2', '02/'); | ||
| }); | ||
|
|
||
| it('formats "11" as "11/"', async () => { | ||
| await runFormatTest('11', '11/'); | ||
| }); | ||
|
|
||
| it('formats "13" as "01/3"', async () => { | ||
| await runFormatTest('13', '01/3'); | ||
| }); | ||
|
|
||
| it('formats "20" as "02/0"', async () => { | ||
| await runFormatTest('20', '02/0'); | ||
| }); | ||
|
|
||
| it('formats "45" as "04/5"', async () => { | ||
| await runFormatTest('45', '04/5'); | ||
| }); | ||
|
|
||
| it('formats "98" as "09/8"', async () => { | ||
| await runFormatTest('98', '09/8'); | ||
| }); | ||
|
|
||
| it('formats "123" as "12/3"', async () => { | ||
| await runFormatTest('123', '12/3'); | ||
| }); | ||
|
|
||
| it('formats "567" as "05/67"', async () => { | ||
| await runFormatTest('567', '05/67'); | ||
| }); | ||
|
|
||
| it('formats "00" as "0"', async () => { | ||
| await runFormatTest('00', '0'); | ||
| }); | ||
|
|
||
| it('formats "11111" as "11/11"', async () => { | ||
| await runFormatTest('11111', '11/11'); | ||
| }); | ||
|
|
||
| it('formats "99/99" as "09/99"', async () => { | ||
| await runFormatTest('99/99', '09/99'); | ||
| }); | ||
|
|
||
| it('formats "0825" as "08/25"', async () => { | ||
| await runFormatTest('0825', '08/25'); | ||
| }); | ||
|
|
||
| it('formats "12255" as "12/25"', async () => { | ||
| await runFormatTest('12255', '12/25'); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.