Skip to content

Commit

Permalink
chore: use i18n in unit tests - Home 6 (#10353)
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmccaskill-oddball authored Dec 13, 2024
1 parent 1574896 commit 86880c7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 34 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 { contactInformationKeys } from 'api/contactInformation/queryKeys'
import { AddressData, UserContactInformation } from 'api/types'
Expand Down Expand Up @@ -76,7 +77,11 @@ describe('AddressSummary', () => {

describe('when there is no mailing address', () => {
it('displays the message for adding a mailing address', () => {
expect(screen.getByText('Add your mailing address')).toBeTruthy()
expect(
screen.getByText(
t('contactInformation.addYour', { field: t(`contactInformation.mailingAddress`).toLowerCase() }),
),
).toBeTruthy()
})
})

Expand All @@ -91,7 +96,11 @@ describe('AddressSummary', () => {
describe('when there is no residential address', () => {
it('displays the message for adding a home address', () => {
renderWithData()
expect(screen.getByText('Add your home address')).toBeTruthy()
expect(
screen.getByText(
t('contactInformation.addYour', { field: t(`contactInformation.residentialAddress`).toLowerCase() }),
),
).toBeTruthy()
})
})

Expand Down Expand Up @@ -209,7 +218,11 @@ describe('AddressSummary', () => {
}

renderWithData({ mailingAddress: noCountryCodeAddress })
expect(screen.getByText('Add your mailing address')).toBeTruthy()
expect(
screen.getByText(
t('contactInformation.addYour', { field: t(`contactInformation.mailingAddress`).toLowerCase() }),
),
).toBeTruthy()
})
})

Expand Down Expand Up @@ -237,9 +250,9 @@ describe('AddressSummary', () => {

describe('when the address summary is clicked', () => {
it('calls onPress', () => {
fireEvent.press(screen.getByRole('link', { name: 'Mailing address' }))
fireEvent.press(screen.getByRole('link', { name: t('contactInformation.mailingAddress') }))
expect(mailingAddressOnPressSpy).toBeCalled()
fireEvent.press(screen.getByRole('link', { name: 'Home address' }))
fireEvent.press(screen.getByRole('link', { name: t('contactInformation.residentialAddress') }))
expect(residentialAddressOnPressSpy).toBeCalled()
})
})
Expand Down
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 { AddressData, ValidateAddressData } from 'api/types'
import { SnackbarMessages } from 'components/SnackBar'
Expand Down Expand Up @@ -89,18 +90,18 @@ describe('AddressValidation', () => {

describe('when the address validation scenario type is SHOW_SUGGESTIONS_OVERRIDE', () => {
it('displays the alert texts', () => {
const collapsibleAlert = screen.getByText('Verify your address')
const collapsibleAlert = screen.getByText(t('editAddress.validation.verifyAddress.title'))

expect(collapsibleAlert).toBeTruthy()
fireEvent.press(collapsibleAlert)
expect(screen.getByText("We can't confirm the address you entered with the U.S. Postal Service.")).toBeTruthy()
expect(screen.getByText(t('editAddress.validation.verifyAddress.body.1'))).toBeTruthy()
})
})

describe('when use this address button is pressed', () => {
it('calls updateAddress', () => {
fireEvent.press(screen.getByTestId('youEnteredTestID'))
fireEvent.press(screen.getByRole('button', { name: 'Use this address' }))
fireEvent.press(screen.getByRole('button', { name: t('editAddress.validation.useThisAddress') }))
expect(saveAddressSpy).toBeCalled()
})
})
Expand Down
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'
import { AddressData, DeliveryPointValidationTypesConstants, UserContactInformation } from 'api/types'
Expand Down Expand Up @@ -134,7 +135,7 @@ describe('EditAddressScreen', () => {

fireEvent.press(countrySelector)
fireEvent.press(screen.getByText('Algeria'))
fireEvent.press(screen.getByRole('button', { name: 'Done' }))
fireEvent.press(screen.getByRole('button', { name: t('done') }))
expect(countrySelector.props.children).toEqual('Algeria')
})

Expand All @@ -148,7 +149,7 @@ describe('EditAddressScreen', () => {

fireEvent.press(screen.getByTestId('countryPickerTestID'))
fireEvent.press(screen.getByText('Algeria'))
fireEvent.press(screen.getByRole('button', { name: 'Done' }))
fireEvent.press(screen.getByRole('button', { name: t('done') }))

expect(screen.getByTestId('stateTestID').props.value).toEqual('')
expect(zipCodeInput.props.value).toEqual('')
Expand Down Expand Up @@ -180,7 +181,7 @@ describe('EditAddressScreen', () => {

fireEvent.press(screen.getByTestId('countryPickerTestID'))
fireEvent.press(screen.getByText('Algeria'))
fireEvent.press(screen.getByRole('button', { name: 'Done' }))
fireEvent.press(screen.getByRole('button', { name: t('done') }))

expect(screen.getByTestId('stateTestID').props.value).toEqual('Northern Territory')
expect(screen.getByTestId('zipCodeTestID').props.value).toEqual('5922')
Expand Down Expand Up @@ -247,7 +248,7 @@ describe('EditAddressScreen', () => {

fireEvent.press(militaryPostOfficeSelector)
fireEvent.press(screen.getByText('APO'))
fireEvent.press(screen.getByRole('button', { name: 'Done' }))
fireEvent.press(screen.getByRole('button', { name: t('done') }))
expect(militaryPostOfficeSelector.props.children).toEqual('APO')
})
})
Expand All @@ -256,7 +257,7 @@ describe('EditAddressScreen', () => {
it('updates the value of state', () => {
fireEvent.press(screen.getByTestId('stateTestID'))
fireEvent.press(screen.getByText('California'))
fireEvent.press(screen.getByRole('button', { name: 'Done' }))
fireEvent.press(screen.getByRole('button', { name: t('done') }))
expect(screen.getByTestId('stateTestID').props.children).toEqual('California')
})
})
Expand Down Expand Up @@ -425,7 +426,7 @@ describe('EditAddressScreen', () => {

renderWithData(false, { mailingAddress: newAddress })

fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))
await waitFor(() => expect(goBackSpy).toBeCalled())
})
})
Expand Down Expand Up @@ -486,43 +487,43 @@ describe('EditAddressScreen', () => {

renderWithData(false, { mailingAddress: newAddress })

fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))
await waitFor(() =>
expect(post as jest.Mock).toBeCalledWith('/v0/user/addresses/validate', newAddress, undefined, abortSignal),
)
await waitFor(() => expect(screen.getByText('Verify your address')).toBeTruthy())
await waitFor(() => expect(screen.getByText(t('editAddress.validation.verifyAddress.title'))).toBeTruthy())
})
})

describe('when content is invalid for domestic address', () => {
it('displays an AlertBox and a field error for each required field', () => {
fireEvent.press(screen.getByRole('button', { name: 'Save' }))
expect(screen.getByText('Please check your mailing address')).toBeTruthy()
expect(screen.getByText('Country is required')).toBeTruthy()
expect(screen.getByText('Street address is required')).toBeTruthy()
expect(screen.getByText('City is required')).toBeTruthy()
expect(screen.getByText('State is required')).toBeTruthy()
expect(screen.getByText('Postal code is required')).toBeTruthy()
fireEvent.press(screen.getByRole('button', { name: t('save') }))
expect(screen.getByText(t('editAddress.alertError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.countryFieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.streetAddressLine1FieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.cityFieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.stateFieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.zipCodeFieldError'))).toBeTruthy()
})
})

describe('when content is invalid for military address', () => {
it('displays an AlertBox and a field error for each required field', () => {
fireEvent.press(screen.getByRole('button', { name: 'Save' }))
expect(screen.getByText('Please check your mailing address')).toBeTruthy()
expect(screen.getByText('Street address is required')).toBeTruthy()
expect(screen.getByText('Postal code is required')).toBeTruthy()
fireEvent.press(screen.getByRole('button', { name: t('save') }))
expect(screen.getByText(t('editAddress.alertError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.streetAddressLine1FieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.zipCodeFieldError'))).toBeTruthy()
})
})

describe('when content is invalid for an international address', () => {
it('displays an AlertBox and a field error for each required field', () => {
fireEvent.press(screen.getByTestId('countryPickerTestID'))
fireEvent.press(screen.getByText('Algeria'))
fireEvent.press(screen.getByRole('button', { name: 'Save' }))
expect(screen.getByText('Street address is required')).toBeTruthy()
expect(screen.getByText('City is required')).toBeTruthy()
expect(screen.getByText('Postal code is required')).toBeTruthy()
fireEvent.press(screen.getByRole('button', { name: t('save') }))
expect(screen.getByText(t('editAddress.streetAddressLine1FieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.cityFieldError'))).toBeTruthy()
expect(screen.getByText(t('editAddress.internationalPostCodeFieldError'))).toBeTruthy()
})
})

Expand Down Expand Up @@ -553,7 +554,7 @@ describe('EditAddressScreen', () => {

renderWithData(false, { mailingAddress: newAddress })

fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))

const abortController = new AbortController()
const abortSignal = abortController.signal
Expand Down Expand Up @@ -601,7 +602,7 @@ describe('EditAddressScreen', () => {
}
renderWithData(false, { mailingAddress: newAddress })

fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))

const abortController = new AbortController()
const abortSignal = abortController.signal
Expand Down Expand Up @@ -648,7 +649,7 @@ describe('EditAddressScreen', () => {
}
renderWithData(false, { mailingAddress: newAddress })

fireEvent.press(screen.getByRole('button', { name: 'Save' }))
fireEvent.press(screen.getByRole('button', { name: t('save') }))

const abortController = new AbortController()
const abortSignal = abortController.signal
Expand Down

0 comments on commit 86880c7

Please sign in to comment.