From 09aedbd16c3c9ebeb8a947731e793b438097b02d Mon Sep 17 00:00:00 2001 From: Matthew Guest - Work Date: Fri, 22 Nov 2024 10:45:52 -0800 Subject: [PATCH] chore: Updated ContactInformationScreen tests with i18n --- .../EditEmailScreen/EditEmailScreen.test.tsx | 17 +++++++++-------- .../EditPhoneNumberScreen.test.tsx | 11 ++++++----- .../HowWillYouScreen/HowWillYouScreen.test.tsx | 15 ++++----------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditEmailScreen/EditEmailScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditEmailScreen/EditEmailScreen.test.tsx index 0892d7580fa..a0dc3140a82 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditEmailScreen/EditEmailScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditEmailScreen/EditEmailScreen.test.tsx @@ -1,6 +1,7 @@ import React from 'react' import { fireEvent, screen, waitFor } from '@testing-library/react-native' +import { t } from 'i18next' import { contactInformationKeys } from 'api/contactInformation/queryKeys' import { put } from 'store/api' @@ -51,7 +52,7 @@ describe('EditEmailScreen', () => { describe('when the email is saved', () => { it('navigates back to the previous screen', async () => { fireEvent.changeText(screen.getByTestId('emailAddressEditTestID'), 'my@email.com') - fireEvent.press(screen.getByRole('button', { name: 'Save' })) + fireEvent.press(screen.getByRole('button', { name: t('save') })) await waitFor(() => expect(onBackSpy).toHaveBeenCalled()) }) }) @@ -59,17 +60,17 @@ describe('EditEmailScreen', () => { describe('when the email does not have an @ followed by text on save', () => { it('displays an AlertBox and field error', () => { fireEvent.changeText(screen.getByTestId('emailAddressEditTestID'), 'myemail') - fireEvent.press(screen.getByRole('button', { name: 'Save' })) - expect(screen.getByText('Check your email address')).toBeTruthy() - expect(screen.getByText('Enter your email address again using this format: X@X.com')).toBeTruthy() + fireEvent.press(screen.getByRole('button', { name: t('save') })) + expect(screen.getByText(t('editEmail.alertError'))).toBeTruthy() + expect(screen.getByText(t('editEmail.fieldError'))).toBeTruthy() }) }) describe('when the email input is empty on save', () => { it('displays an AlertBox and field error', () => { - fireEvent.press(screen.getByRole('button', { name: 'Save' })) - expect(screen.getByText('Check your email address')).toBeTruthy() - expect(screen.getByText('Enter your email address again using this format: X@X.com')).toBeTruthy() + fireEvent.press(screen.getByRole('button', { name: t('save') })) + expect(screen.getByText(t('editEmail.alertError'))).toBeTruthy() + expect(screen.getByText(t('editEmail.fieldError'))).toBeTruthy() }) }) @@ -94,7 +95,7 @@ describe('EditEmailScreen', () => { .mockResolvedValue({}) fireEvent.changeText(screen.getByTestId('emailAddressEditTestID'), updatedEmail) - fireEvent.press(screen.getByRole('button', { name: 'Save' })) + fireEvent.press(screen.getByRole('button', { name: t('save') })) await waitFor(() => expect(put as jest.Mock).toBeCalledWith('/v0/user/emails', payload)) }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditPhoneNumberScreen/EditPhoneNumberScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditPhoneNumberScreen/EditPhoneNumberScreen.test.tsx index b57ec018ce1..42dcc9b8260 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditPhoneNumberScreen/EditPhoneNumberScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/EditPhoneNumberScreen/EditPhoneNumberScreen.test.tsx @@ -3,6 +3,7 @@ import React from 'react' import { StackScreenProps } from '@react-navigation/stack' import { fireEvent, screen, waitFor } from '@testing-library/react-native' +import { t } from 'i18next' import { PhoneData, PhoneType } from 'api/types' import { HomeStackParamList } from 'screens/HomeScreen/HomeStackScreens' @@ -31,7 +32,7 @@ describe('EditPhoneNumberScreen', () => { }, { params: { - displayTitle: 'Home phone', + displayTitle: t('editPhoneNumber.homePhoneTitle'), phoneData, ...data, }, @@ -87,7 +88,7 @@ describe('EditPhoneNumberScreen', () => { describe('when the phone number is saved', () => { it('navigates back to the previous screen', async () => { - fireEvent.press(screen.getByRole('button', { name: 'Save' })) + fireEvent.press(screen.getByRole('button', { name: t('save') })) await waitFor(() => expect(props.navigation.goBack).toBeCalled()) }) }) @@ -97,9 +98,9 @@ describe('EditPhoneNumberScreen', () => { const phoneNumberInput = screen.getByTestId('phoneNumberTestID') fireEvent.changeText(phoneNumberInput, '') - fireEvent.press(screen.getByRole('button', { name: 'Save' })) - expect(screen.getByText('Check your phone number')).toBeTruthy() - expect(screen.getByText('Enter a valid phone number')).toBeTruthy() + fireEvent.press(screen.getByRole('button', { name: t('save') })) + expect(screen.getByText(t('editPhoneNumber.checkPhoneNumber'))).toBeTruthy() + expect(screen.getByText(t('editPhoneNumber.numberFieldError'))).toBeTruthy() }) }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/HowWillYouScreen/HowWillYouScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/HowWillYouScreen/HowWillYouScreen.test.tsx index cc64bd77946..22d49dcead3 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/HowWillYouScreen/HowWillYouScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/ContactInformationScreen/HowWillYouScreen/HowWillYouScreen.test.tsx @@ -1,6 +1,7 @@ import React from 'react' import { screen } from '@testing-library/react-native' +import { t } from 'i18next' import { context, mockNavProps, render } from 'testUtils' @@ -13,16 +14,8 @@ context('HowWillYouScreen', () => { }) it('initializes correctly', () => { - expect(screen.getByText('How we use your contact information')).toBeTruthy() - expect( - screen.getByText( - 'We’ll use this information to contact you about certain benefits and services, like disability compensation, pension benefits, and claims and appeals.', - ), - ).toBeTruthy() - expect( - screen.getByText( - 'If you’re enrolled in VA health care, we’ll send your prescriptions to your mailing address. Your health care team may also use this information to contact you.', - ), - ).toBeTruthy() + expect(screen.getByText(t('contactInformation.howWillYouUseContactInfo'))).toBeTruthy() + expect(screen.getByText(t('howWillYou.useInfo.1'))).toBeTruthy() + expect(screen.getByText(t('howWillYou.useInfo.2'))).toBeTruthy() }) })