Skip to content

Commit

Permalink
chore: use i18n in unit tests - Payments 2 (#10351)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmccaskill-oddball authored Dec 11, 2024
1 parent 77fb2fb commit 2a454e2
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react'

import { fireEvent, screen } from '@testing-library/react-native'
import { t } from 'i18next'

import { directDepositKeys } from 'api/directDeposit'
import { DirectDepositData } from 'api/types'
Expand Down Expand Up @@ -73,13 +74,13 @@ context('DirectDepositScreen', () => {
.calledWith('/v0/payment-information/benefits')
.mockResolvedValue(mockData)
initializeTestInstance(mockData)
await waitFor(() => expect(screen.getByText('Account')).toBeTruthy())
await waitFor(() => expect(screen.getByText(t('directDeposit.account'))).toBeTruthy())
await waitFor(() => expect(screen.getByText('BoA')).toBeTruthy())
await waitFor(() => expect(screen.getByText('******1234')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Savings account')).toBeTruthy())
await waitFor(() => fireEvent.press(screen.getByTestId('account-boa-******1234-savings-account')))
await waitFor(() =>
expect(mockNavigationSpy).toBeCalledWith('EditDirectDeposit', { displayTitle: 'Edit account' }),
expect(mockNavigationSpy).toBeCalledWith('EditDirectDeposit', { displayTitle: t('directDeposit.edit.title') }),
)
})
})
Expand All @@ -90,7 +91,7 @@ context('DirectDepositScreen', () => {
.calledWith('/v0/payment-information/benefits')
.mockResolvedValue(noData)
initializeTestInstance()
await waitFor(() => expect(screen.getByText('Add your bank account information')).toBeTruthy())
await waitFor(() => expect(screen.getByText(t('directDeposit.addBankAccountInformation'))).toBeTruthy())
})
})

Expand All @@ -100,7 +101,9 @@ context('DirectDepositScreen', () => {
.calledWith('/v0/payment-information/benefits')
.mockRejectedValue({ networkError: true } as api.APIError)
initializeTestInstance()
await waitFor(() => expect(screen.getByRole('header', { name: "The app can't be loaded." })).toBeTruthy())
await waitFor(() =>
expect(screen.getByRole('header', { name: t('errors.networkConnection.header') })).toBeTruthy(),
)
})
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'

import { t } from 'i18next'

import { PaymentAccountData } from 'api/types'
import { DirectDepositErrors } from 'constants/errors'
import * as api from 'store/api'
Expand Down Expand Up @@ -43,9 +45,9 @@ context('EditDirectDepositScreen', () => {
describe('when user selects an account type', () => {
it('should update the value of the accountType', () => {
fireEvent.press(screen.getByTestId('accountType'))
fireEvent.press(screen.getByText('Checking'))
fireEvent.press(screen.getByText('Done'))
expect(screen.getByText('Checking')).toBeTruthy()
fireEvent.press(screen.getByText(t('accountType.checking')))
fireEvent.press(screen.getByText(t('done')))
expect(screen.getByText(t('accountType.checking'))).toBeTruthy()
})
})

Expand All @@ -60,26 +62,26 @@ context('EditDirectDepositScreen', () => {
fireEvent.changeText(screen.getByTestId('routingNumber'), '053100300')
fireEvent.changeText(screen.getByTestId('accountNumber'), '12345678901234567')
fireEvent.press(screen.getByTestId('accountType'))
fireEvent.press(screen.getByText('Checking'))
fireEvent.press(screen.getByText('Done'))
fireEvent.press(screen.getByText(t('accountType.checking')))
fireEvent.press(screen.getByText(t('done')))
fireEvent.press(screen.getByTestId('checkBox'))
fireEvent.press(screen.getByText('Save'))
fireEvent.press(screen.getByText(t('save')))
when(api.put as jest.Mock)
.calledWith(`/v0/payment-information/benefits`, bankData)
.mockResolvedValue('success')
expect(screen.getByText('Saving your direct deposit information...')).toBeTruthy()
expect(screen.getByText(t('directDeposit.savingInformation'))).toBeTruthy()
await waitFor(() => expect(api.put as jest.Mock).toBeCalledWith(`/v0/payment-information/benefits`, bankData))
})
})

describe('when content is invalid', () => {
it('should display an AlertBox and field errors', () => {
fireEvent.press(screen.getByRole('button', { name: 'Save' }))
expect(screen.getByText('Check your direct deposit information')).toBeTruthy()
expect(screen.getByText('Enter a 9-digit routing number')).toBeTruthy()
expect(screen.getByText('Enter an account number')).toBeTruthy()
expect(screen.getByText('Select an account type')).toBeTruthy()
expect(screen.getByText('Select checkbox to confirm information')).toBeTruthy()
fireEvent.press(screen.getByRole('button', { name: t('save') }))
expect(screen.getByText(t('editDirectDeposit.pleaseCheckDDInfo'))).toBeTruthy()
expect(screen.getByText(t('editDirectDeposit.routingNumberFieldError'))).toBeTruthy()
expect(screen.getByText(t('editDirectDeposit.accountNumberFieldError'))).toBeTruthy()
expect(screen.getByText(t('editDirectDeposit.accountTypeFieldError'))).toBeTruthy()
expect(screen.getByText(t('editDirectDeposit.checkBoxFieldError'))).toBeTruthy()
})
})

Expand All @@ -95,10 +97,10 @@ context('EditDirectDepositScreen', () => {
fireEvent.changeText(screen.getByTestId('routingNumber'), '053100300')
fireEvent.changeText(screen.getByTestId('accountNumber'), '12345678901234567')
fireEvent.press(screen.getByTestId('accountType'))
fireEvent.press(screen.getByText('Checking'))
fireEvent.press(screen.getByText('Done'))
fireEvent.press(screen.getByText(t('accountType.checking')))
fireEvent.press(screen.getByText(t('done')))
fireEvent.press(screen.getByTestId('checkBox'))
fireEvent.press(screen.getByText('Save'))
fireEvent.press(screen.getByText(t('save')))
when(api.put as jest.Mock)
.calledWith(`/v0/payment-information/benefits`, bankData)
.mockRejectedValue({
Expand All @@ -116,13 +118,7 @@ context('EditDirectDepositScreen', () => {
],
},
})
await waitFor(() =>
expect(
screen.getByText(
"We couldn't find a bank linked to this routing number. Please check your bank's 9-digit routing number and enter again.",
),
).toBeTruthy(),
)
await waitFor(() => expect(screen.getByText(t('editDirectDeposit.errorInvalidRoutingNumber'))).toBeTruthy())
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { Linking } from 'react-native'

import { fireEvent, screen } from '@testing-library/react-native'
import { t } from 'i18next'

import { context, mockNavProps, render } from 'testUtils'

Expand All @@ -13,24 +14,18 @@ context('HowToUpdateDirectDepositScreen', () => {
})

it('initializes correctly', () => {
expect(screen.getByLabelText('Direct deposit')).toBeTruthy()
expect(screen.getByLabelText(t('directDeposit.title'))).toBeTruthy()
expect(
screen.getByRole('heading', {
name: 'You’ll need to sign in with a verified ID.me or Login.gov account to update your direct deposit information',
name: t('howToUpdateDirectDeposit.alert.title'),
}),
).toBeTruthy()
expect(screen.getByText('We require this to protect bank account information and prevent fraud.')).toBeTruthy()
expect(
screen.getByText(
'If you have one, please sign out and sign back in using your verified ID.me or Login.gov account.',
),
).toBeTruthy()
expect(screen.getByRole('header', { name: 'Call us to update your direct deposit information' })).toBeTruthy()
expect(
screen.getByText('You can call us. We’re here Monday through Friday, 8:00 a.m. to 9:00 p.m. ET.'),
).toBeTruthy()
expect(screen.getByText(t('howToUpdateDirectDeposit.alert.body.1'))).toBeTruthy()
expect(screen.getByText(t('howToUpdateDirectDeposit.alert.body.2'))).toBeTruthy()
expect(screen.getByRole('header', { name: t('howToUpdateDirectDeposit.card.title') })).toBeTruthy()
expect(screen.getByText(t('howToUpdateDirectDeposit.card.callUs'))).toBeTruthy()
expect(screen.getByRole('link', { name: '800-827-1000' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'TTY: 711' })).toBeTruthy()
expect(screen.getByRole('link', { name: t('contactVA.tty.displayText') })).toBeTruthy()
fireEvent.press(screen.getByRole('link', { name: '800-827-1000' }))
expect(Linking.openURL).toBeCalled()
})
Expand Down

0 comments on commit 2a454e2

Please sign in to comment.