Skip to content

Commit

Permalink
9321-Chika-ImplementCopyChangesFromTicket9299 (#9331)
Browse files Browse the repository at this point in the history
  • Loading branch information
cadibemma authored Aug 15, 2024
1 parent 575a811 commit abacf52
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 4 deletions.
81 changes: 78 additions & 3 deletions VAMobile/src/screens/HomeScreen/HomeScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import { Linking } from 'react-native'
import { fireEvent, screen, waitFor } from '@testing-library/react-native'
import { DateTime } from 'luxon'

import { DisabilityRatingData, FacilitiesPayload, LetterBeneficiaryDataPayload } from 'api/types'
import {
DisabilityRatingData,
FacilitiesPayload,
LetterBeneficiaryDataPayload,
MilitaryServiceHistoryData,
ServiceHistoryAttributes,
} from 'api/types'
import { DEFAULT_UPCOMING_DAYS_LIMIT } from 'constants/appointments'
import { get } from 'store/api'
import { ErrorsState } from 'store/slices'
Expand Down Expand Up @@ -74,6 +80,14 @@ const getLetterBeneficiaryPayload = (monthlyAwardAmount: number): LetterBenefici
},
})

const getMilitaryServiceHistoryPayload = (serviceHistory: ServiceHistoryAttributes): MilitaryServiceHistoryData => ({
data: {
type: 'a',
id: 'string',
attributes: serviceHistory,
},
})

context('HomeScreen', () => {
const initializeTestInstance = (options?: RenderParams) => {
const props = mockNavProps(undefined, { setOptions: jest.fn(), navigate: mockNavigationSpy })
Expand Down Expand Up @@ -478,13 +492,20 @@ context('HomeScreen', () => {
await waitFor(() => expect(screen.queryByText('Disability rating')).toBeFalsy())
})

it('does not display disability rating percentage when disability ratings API call fails', async () => {
it('does not display disability rating percentage and show error message when disability ratings API call fails', async () => {
when(get as jest.Mock)
.calledWith('/v0/disability-rating')
.mockRejectedValue('fail')
.calledWith('/v0/letters/beneficiary')
.mockResolvedValue(getLetterBeneficiaryPayload(3084.75))
.calledWith('/v0/military-service-history')
.mockResolvedValue(getMilitaryServiceHistoryPayload({} as ServiceHistoryAttributes))
initializeTestInstance()
await waitFor(() => expect(screen.queryByText('Loading your information...')).toBeFalsy())
await waitFor(() => expect(screen.queryByText('Disability rating')).toBeFalsy())
await waitFor(() =>
expect(screen.queryByText('We can’t show all your information right now. Check back later.')).toBeTruthy(),
)
})

it('displays monthly payment amount when veteran has monthly compensation payment', async () => {
Expand All @@ -504,13 +525,20 @@ context('HomeScreen', () => {
await waitFor(() => expect(screen.queryByText('Monthly compensation payment')).toBeFalsy())
})

it('does not display monthly payment amount when the beneficiary API call fails', async () => {
it('does not display monthly payment and show error message when the beneficiary API call fails', async () => {
when(get as jest.Mock)
.calledWith('/v0/disability-rating')
.mockResolvedValue(getDisabilityRatingPayload(100))
.calledWith('/v0/letters/beneficiary')
.mockRejectedValue('fail')
.calledWith('/v0/military-service-history')
.mockResolvedValue(getMilitaryServiceHistoryPayload({} as ServiceHistoryAttributes))
initializeTestInstance()
await waitFor(() => expect(screen.queryByText('Loading your information...')).toBeFalsy())
await waitFor(() => expect(screen.queryByText('Monthly compensation payment')).toBeFalsy())
await waitFor(() =>
expect(screen.queryByText('We can’t show all your information right now. Check back later.')).toBeTruthy(),
)
})

it("displays message when no 'About you' info exists", async () => {
Expand All @@ -519,9 +547,56 @@ context('HomeScreen', () => {
.mockResolvedValue(getDisabilityRatingPayload(0))
.calledWith('/v0/letters/beneficiary')
.mockResolvedValue(getLetterBeneficiaryPayload(0))
.calledWith('/v0/military-service-history')
.mockResolvedValue(getMilitaryServiceHistoryPayload({} as ServiceHistoryAttributes))

initializeTestInstance()
await waitFor(() => expect(screen.queryByText('We can’t show your information right now.')).toBeTruthy())
await waitFor(() =>
expect(screen.queryByText('We can’t show all your information right now. Check back later.')).toBeFalsy(),
)
})

it('displays error message when one of the features are in downtime', async () => {
when(get as jest.Mock)
.calledWith('/v0/disability-rating')
.mockResolvedValue(getDisabilityRatingPayload(100))
.calledWith('/v0/letters/beneficiary')
.mockResolvedValue(getLetterBeneficiaryPayload(3000))
.calledWith('/v0/military-service-history')
.mockResolvedValue(getMilitaryServiceHistoryPayload({} as ServiceHistoryAttributes))
initializeTestInstance({
preloadedState: {
errors: {
downtimeWindowsByFeature: {
letters_and_documents: {
startTime: DateTime.now(),
endTime: DateTime.now().plus({ minutes: 1 }),
},
},
} as ErrorsState,
},
})
await waitFor(() => expect(screen.queryByText('Loading your information...')).toBeFalsy())
await waitFor(() =>
expect(screen.queryByText('We can’t show all your information right now. Check back later.')).toBeTruthy(),
)
})

it("displays error message when some 'About you' info doesn't exist and rest of info has errors", async () => {
when(get as jest.Mock)
.calledWith('/v0/disability-rating')
.mockResolvedValue(getDisabilityRatingPayload(0))
.calledWith('/v0/letters/beneficiary')
.mockResolvedValue(getLetterBeneficiaryPayload(0))
.calledWith('/v0/military-service-history')
.mockRejectedValue('fail')

initializeTestInstance()
await waitFor(() => expect(screen.queryByText('We can’t show your information right now.')).toBeFalsy())
await waitFor(() =>
expect(screen.queryByText('We can’t show all your information right now. Check back later.')).toBeTruthy(),
)
})
})

Expand Down
17 changes: 16 additions & 1 deletion VAMobile/src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,18 @@ export function HomeScreen({}: HomeScreenProps) {
!!letterBeneficiaryQuery.data?.benefitInformation.monthlyAwardAmount ||
!!serviceHistoryQuery.data?.mostRecentBranch

const aboutYouFeatureInDowntime = !!(
(authorizedServicesQuery.data?.militaryServiceHistory && serviceHistoryInDowntime) ||
(authorizedServicesQuery.data?.disabilityRating && disabilityRatingInDowntime) ||
(authorizedServicesQuery.data?.lettersAndDocuments && lettersInDowntime)
)

const hasAboutYouError = !!(
disabilityRatingQuery.isError ||
letterBeneficiaryQuery.isError ||
serviceHistoryQuery.isError
)

const onFacilityLocator = () => {
logAnalyticsEvent(Events.vama_find_location())
navigateTo('Webview', {
Expand Down Expand Up @@ -418,7 +430,7 @@ export function HomeScreen({}: HomeScreenProps) {
spinnerColor={theme.colors.icon.inlineSpinner}
/>
</Box>
) : !hasAboutYouInfo ? (
) : !hasAboutYouInfo && !hasAboutYouError ? (
<Box mx={theme.dimensions.condensedMarginBetween} mb={theme.dimensions.condensedMarginBetween}>
<CategoryLandingAlert text={t('aboutYou.noInformation')} />
</Box>
Expand Down Expand Up @@ -481,6 +493,9 @@ export function HomeScreen({}: HomeScreenProps) {
</Box>
)}
</Box>
{(hasAboutYouError || aboutYouFeatureInDowntime) && (
<CategoryLandingAlert text={t('aboutYou.error.cantShowAllInfo')} isError={hasAboutYouError} />
)}
</Box>
)}
</Box>
Expand Down
1 change: 1 addition & 0 deletions VAMobile/src/translations/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"aboutYou": "About you",
"aboutYou.loading": "Loading your information...",
"aboutYou.noInformation": "We can’t show your information right now.",
"aboutYou.error.cantShowAllInfo": "We can’t show all your information right now. Check back later.",
"accountSecurity": "Account security",
"accountSecurity.signIn": "Sign-in information",
"accountSecurity.description": "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.",
Expand Down

0 comments on commit abacf52

Please sign in to comment.