From 2a454e22ef808fe3b73255f3842c7a84597175c7 Mon Sep 17 00:00:00 2001 From: Kim McCaskill <187308860+kimmccaskill-oddball@users.noreply.github.com> Date: Wed, 11 Dec 2024 09:37:46 -0700 Subject: [PATCH] chore: use i18n in unit tests - Payments 2 (#10351) --- .../DirectDepositScreen.test.tsx | 11 +++-- .../EditDirectDepositScreen.test.tsx | 42 +++++++++---------- .../HowToUpdateDirectDepositScreen.test.tsx | 21 ++++------ 3 files changed, 34 insertions(+), 40 deletions(-) diff --git a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/DirectDepositScreen.test.tsx b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/DirectDepositScreen.test.tsx index a1301a6e0b5..2bbc012fa19 100644 --- a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/DirectDepositScreen.test.tsx +++ b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/DirectDepositScreen.test.tsx @@ -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' @@ -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') }), ) }) }) @@ -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()) }) }) @@ -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(), + ) }) }) }) diff --git a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/EditDirectDepositScreen/EditDirectDepositScreen.test.tsx b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/EditDirectDepositScreen/EditDirectDepositScreen.test.tsx index 338690bbe4e..fde013e6111 100644 --- a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/EditDirectDepositScreen/EditDirectDepositScreen.test.tsx +++ b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/EditDirectDepositScreen/EditDirectDepositScreen.test.tsx @@ -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' @@ -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() }) }) @@ -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() }) }) @@ -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({ @@ -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()) }) }) }) diff --git a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/HowToUpdateDirectDepositScreen/HowToUpdateDirectDepositScreen.test.tsx b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/HowToUpdateDirectDepositScreen/HowToUpdateDirectDepositScreen.test.tsx index efd91c6069d..ab63573837c 100644 --- a/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/HowToUpdateDirectDepositScreen/HowToUpdateDirectDepositScreen.test.tsx +++ b/VAMobile/src/screens/PaymentsScreen/DirectDepositScreen/HowToUpdateDirectDepositScreen/HowToUpdateDirectDepositScreen.test.tsx @@ -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' @@ -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() })