From 30b8a908f8dcd5b53c5ea908d42ff0cefab557ec Mon Sep 17 00:00:00 2001 From: Kim McCaskill <187308860+kimmccaskill-oddball@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:53:04 -0700 Subject: [PATCH] chore: use i18n in unit tests --- .../AccountSecurity/AccountSecurity.test.tsx | 9 +++---- .../InAppRecruitmentScreen.test.tsx | 27 ++++++++++--------- .../NotificationsSettingsScreen.test.tsx | 12 ++------- .../SettingsScreen/SettingsScreen.test.tsx | 25 +++++++++-------- 4 files changed, 33 insertions(+), 40 deletions(-) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/AccountSecurity/AccountSecurity.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/AccountSecurity/AccountSecurity.test.tsx index 70fc2f50c6a..d8aeb7b37aa 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/AccountSecurity/AccountSecurity.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/AccountSecurity/AccountSecurity.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,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() }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/InAppRecruitmentScreen/InAppRecruitmentScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/InAppRecruitmentScreen/InAppRecruitmentScreen.test.tsx index 0cfb2d7749a..5eb7d01031c 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/InAppRecruitmentScreen/InAppRecruitmentScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/InAppRecruitmentScreen/InAppRecruitmentScreen.test.tsx @@ -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' @@ -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() }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/NotificationsSettingsScreen/NotificationsSettingsScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/NotificationsSettingsScreen/NotificationsSettingsScreen.test.tsx index 83474786887..72994ec5e42 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/NotificationsSettingsScreen/NotificationsSettingsScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/NotificationsSettingsScreen/NotificationsSettingsScreen.test.tsx @@ -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', () => { @@ -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()) }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/SettingsScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/SettingsScreen.test.tsx index adca3573a2d..ece33a4b97b 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/SettingsScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/SettingsScreen/SettingsScreen.test.tsx @@ -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' @@ -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') }) })