Skip to content

Commit

Permalink
Merge pull request #10250 from department-of-veterans-affairs/chore/9…
Browse files Browse the repository at this point in the history
…999-Usei18nInUnitTests-Home-7

chore: Updated ContactInformationScreen tests with i18n
  • Loading branch information
matt-guest-wilcore authored Dec 4, 2024
2 parents 5cbc4ba + bc833ee commit 5a7b934
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 24 deletions.
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -51,25 +52,25 @@ describe('EditEmailScreen', () => {
describe('when the email is saved', () => {
it('navigates back to the previous screen', async () => {
fireEvent.changeText(screen.getByTestId('emailAddressEditTestID'), '[email protected]')
fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))
await waitFor(() => expect(onBackSpy).toHaveBeenCalled())
})
})

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: [email protected]')).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: [email protected]')).toBeTruthy()
fireEvent.press(screen.getByRole('button', { name: t('save') }))
expect(screen.getByText(t('editEmail.alertError'))).toBeTruthy()
expect(screen.getByText(t('editEmail.fieldError'))).toBeTruthy()
})
})

Expand All @@ -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))
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -31,7 +32,7 @@ describe('EditPhoneNumberScreen', () => {
},
{
params: {
displayTitle: 'Home phone',
displayTitle: t('editPhoneNumber.homePhoneTitle'),
phoneData,
...data,
},
Expand Down Expand Up @@ -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())
})
})
Expand All @@ -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()
})
})
})
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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()
})
})

0 comments on commit 5a7b934

Please sign in to comment.