Skip to content

Commit

Permalink
chore: use i18n in unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kimmccaskill-oddball committed Dec 9, 2024
1 parent accaf6f commit 30b8a90
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 40 deletions.
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,11 +14,7 @@ context('AccountSecurity', () => {
})

it('initializes correctly', () => {
expect(screen.getByText('Sign-in information')).toBeTruthy()
expect(
screen.getByText(
'To access or update your sign-in information, go to the website where you manage your account information. Any updates you make there will automatically update on the mobile app.',
),
).toBeTruthy()
expect(screen.getByText(t('accountSecurity.signIn'))).toBeTruthy()
expect(screen.getByText(t('accountSecurity.description'))).toBeTruthy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react'
import { Alert } from 'react-native'

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

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

Expand Down Expand Up @@ -34,29 +35,29 @@ context('InAppRecruitmentScreen', () => {
})

it('renders screen correctly', () => {
expect(screen.getByLabelText('Give feedback')).toBeTruthy()
expect(screen.getByRole('header', { name: 'Make this app better for all Veterans' })).toBeTruthy()
expect(screen.getByText('You can help us improve this app by being part of online feedback sessions.')).toBeTruthy()
expect(screen.getByText('Register once by completing a 5-minute questionnaire.')).toBeTruthy()
expect(screen.getByText('Wait to be matched with a session.')).toBeTruthy()
expect(screen.getByText('Get paid for each session you complete (excludes VA employees).')).toBeTruthy()
expect(screen.getByRole('button', { name: 'Go to questionnaire' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'Learn more about the Veteran Usability Project' })).toBeTruthy()
expect(screen.getByText('VA contracts: 36C10B22C0011 & 36C10X18C0061')).toBeTruthy()
expect(screen.getByLabelText(t('giveFeedback'))).toBeTruthy()
expect(screen.getByRole('header', { name: t('inAppRecruitment.makeAppBetter.header') })).toBeTruthy()
expect(screen.getByText(t('inAppRecruitment.makeAppBetter.body'))).toBeTruthy()
expect(screen.getByText(t('inAppRecruitment.makeAppBetter.bullet.1'))).toBeTruthy()
expect(screen.getByText(t('inAppRecruitment.makeAppBetter.bullet.2'))).toBeTruthy()
expect(screen.getByText(t('inAppRecruitment.makeAppBetter.bullet.3'))).toBeTruthy()
expect(screen.getByRole('button', { name: t('inAppRecruitment.goToQuestionnaire') })).toBeTruthy()
expect(screen.getByRole('link', { name: t('inAppRecruitment.learnMore') })).toBeTruthy()
expect(screen.getByText(t('inAppRecruitment.contracts'))).toBeTruthy()
})

it('goes to the questionnaire when button is pressed', () => {
fireEvent.press(screen.getByRole('button', { name: 'Go to questionnaire' }))
fireEvent.press(screen.getByRole('button', { name: t('inAppRecruitment.goToQuestionnaire') }))
const expectNavArgs = {
url: 'https://docs.google.com/forms/d/e/1FAIpQLSfRb0OtW34qKm8tGoQwwwDFs8IqwOMCLTde3DeM-ukKOEZBnA/viewform',
displayTitle: 'va.gov',
loadingMessage: 'Loading questionnaire...',
displayTitle: t('webview.vagov'),
loadingMessage: t('inAppRecruitment.goToQuestionnaire.loading'),
}
expect(mockNavigationSpy).toHaveBeenCalledWith('Webview', expectNavArgs)
})

it('goes to the Veteran Usability Project when link is pressed', () => {
fireEvent.press(screen.getByRole('link', { name: 'Learn more about the Veteran Usability Project' }))
fireEvent.press(screen.getByRole('link', { name: t('inAppRecruitment.learnMore') }))
expect(Alert.alert).toBeCalled()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ context('NotificationsSettingsScreen', () => {
.mockResolvedValue(responseData)
renderWithProps(true, false, false, [apptPrefOff])
await waitFor(() => expect(screen.queryByRole('switch', { name: 'Upcoming appointments' })).toBeFalsy())
await waitFor(() =>
expect(screen.getByText('To get app notifications, turn them on in your device settings.')).toBeTruthy(),
)
await waitFor(() => expect(screen.getByText(t('notifications.settings.alert.text'))).toBeTruthy())
})
})
describe('when system notifications havent been requested', () => {
Expand All @@ -160,12 +158,6 @@ context('NotificationsSettingsScreen', () => {
.calledWith('/v0/push/prefs/1')
.mockResolvedValue(responseData)
renderWithProps(true, true, true, [])
await waitFor(() =>
expect(
screen.getByText(
"We're sorry. Something went wrong on our end. Please refresh this screen or try again later.",
),
).toBeTruthy(),
)
await waitFor(() => expect(screen.getByText(t('errors.callHelpCenter.sorryWithRefresh'))).toBeTruthy())
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Share } from 'react-native'
import { BIOMETRY_TYPE } from 'react-native-keychain'

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

import { InitialState } from 'store/slices'
import { context, mockNavProps, render, when } from 'testUtils'
Expand Down Expand Up @@ -73,34 +74,36 @@ context('SettingsScreen', () => {
})

it('initializes correctly', () => {
expect(screen.getByRole('link', { name: 'Account security' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'Notifications' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'Share the app' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'Privacy policy' })).toBeTruthy()
expect(screen.getByRole('link', { name: 'Developer Screen' })).toBeTruthy()
expect(screen.getByRole('button', { name: 'Sign out' })).toBeTruthy()
expect(screen.getByRole('link', { name: t('accountSecurity') })).toBeTruthy()
expect(screen.getByRole('link', { name: t('notifications.title') })).toBeTruthy()
expect(screen.getByRole('link', { name: t('shareApp.title') })).toBeTruthy()
expect(screen.getByRole('link', { name: t('privacyPolicy.title') })).toBeTruthy()
expect(screen.getByRole('link', { name: t('debug.title') })).toBeTruthy()
expect(screen.getByRole('button', { name: t('logout.title') })).toBeTruthy()
})

describe('when privacy policy is clicked', () => {
it('should launch external link', () => {
fireEvent.press(screen.getByRole('link', { name: 'Privacy policy' }))
fireEvent.press(screen.getByRole('link', { name: t('privacyPolicy.title') }))
expect(mockExternalLinkSpy).toHaveBeenCalled()
})
})

describe('when "Share the app" is clicked', () => {
it('should call Share.share', () => {
fireEvent.press(screen.getByRole('link', { name: 'Share the app' }))
fireEvent.press(screen.getByRole('link', { name: t('shareApp.title') }))
expect(Share.share).toBeCalledWith({
message:
'Download the VA: Health and Benefits on the App Store: https://apps.apple.com/us/app/va-health-and-benefits/id1559609596 or on Google Play: https://play.google.com/store/apps/details?id=gov.va.mobileapp',
message: t('shareApp.text', {
appleStoreLink: defaultEnvVars.APPLE_STORE_LINK,
googlePlayLink: defaultEnvVars.GOOGLE_PLAY_LINK,
}),
})
})
})

describe('on account security click', () => {
it('should call useRouteNavigation', () => {
fireEvent.press(screen.getByRole('link', { name: 'Account security' }))
fireEvent.press(screen.getByRole('link', { name: t('accountSecurity') }))
expect(mockNavigationSpy).toHaveBeenCalledWith('AccountSecurity')
})
})
Expand Down

0 comments on commit 30b8a90

Please sign in to comment.