Skip to content

Commit

Permalink
feature/9348-DemoModeAPIOverrides (#9544)
Browse files Browse the repository at this point in the history
Co-authored-by: Rachael Bontrager <[email protected]>
  • Loading branch information
Sparowhawk and rbontrager authored Nov 8, 2024
1 parent e261f14 commit 8da7b5f
Show file tree
Hide file tree
Showing 9 changed files with 568 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ import { screen } from '@testing-library/react-native'

import {
CategoryTypeFields,
SecureMessagingFolderMessagesGetData,
SecureMessagingFoldersGetData,
SecureMessagingMessageGetData,
SecureMessagingSystemFolderIdConstants,
SecureMessagingThreadGetData,
} from 'api/types'
import { LARGE_PAGE_SIZE } from 'constants/common'
import * as api from 'store/api'
import { context, mockNavProps, render, waitFor, when } from 'testUtils'

Expand Down Expand Up @@ -195,6 +198,47 @@ context('ViewMessageScreen', () => {
inboxUnreadCount: 0,
}

const messages: SecureMessagingFolderMessagesGetData = {
data: [
{
type: 'test',
id: 1,
attributes: {
messageId: 1,
category: CategoryTypeFields.other,
subject: 'test',
body: 'test',
hasAttachments: false,
attachment: false,
sentDate: '1-1-21',
senderId: 2,
senderName: 'mock sender',
recipientId: 3,
recipientName: 'mock recipient name',
readReceipt: 'mock read receipt',
},
},
],
links: {
self: '',
first: '',
prev: '',
next: '',
last: '',
},
meta: {
sort: {
sentDate: 'DESC',
},
pagination: {
currentPage: 1,
perPage: 1,
totalPages: 3,
totalEntries: 5,
},
},
}

const initializeTestInstance = (messageID: number = 3) => {
render(
<ViewMessageScreen
Expand Down Expand Up @@ -222,6 +266,12 @@ context('ViewMessageScreen', () => {
.mockResolvedValue(oldMessage)
.calledWith('/v0/messaging/health/folders')
.mockResolvedValue(listOfFolders)
.calledWith(`/v0/messaging/health/folders/${SecureMessagingSystemFolderIdConstants.INBOX}/messages`, {
page: '1',
per_page: LARGE_PAGE_SIZE.toString(),
useCache: 'false',
} as api.Params)
.mockResolvedValue(messages)
initializeTestInstance(45)
await waitFor(() => expect(screen.getByText('mock sender 45')).toBeTruthy())
await waitFor(() => expect(screen.getByText('Start new message')).toBeTruthy())
Expand All @@ -240,6 +290,12 @@ context('ViewMessageScreen', () => {
.mockResolvedValue(message)
.calledWith('/v0/messaging/health/folders')
.mockResolvedValue(listOfFolders)
.calledWith(`/v0/messaging/health/folders/${SecureMessagingSystemFolderIdConstants.INBOX}/messages`, {
page: '1',
per_page: LARGE_PAGE_SIZE.toString(),
useCache: 'false',
} as api.Params)
.mockResolvedValue(messages)
initializeTestInstance()
expect(screen.getByText('Loading your message...')).toBeTruthy()
await waitFor(() => expect(screen.queryByRole('link', { name: '1-800-698-2411.Thank' })).toBeFalsy())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import { useQueryClient } from '@tanstack/react-query'
import { DateTime } from 'luxon'
import _ from 'underscore'

import { secureMessagingKeys, useFolders, useMessage, useMoveMessage, useThread } from 'api/secureMessaging'
import {
secureMessagingKeys,
useFolderMessages,
useFolders,
useMessage,
useMoveMessage,
useThread,
} from 'api/secureMessaging'
import {
MoveMessageParameters,
SecureMessagingAttachment,
Expand Down Expand Up @@ -134,6 +141,15 @@ function ViewMessageScreen({ route, navigation }: ViewMessageScreenProps) {
enabled: isScreenContentAllowed && smNotInDowntime,
})

const {
data: inboxMessagesData,
isFetching: loadingFolderMessages,
error: folderMessagesError,
refetch: refetchFolderMessages,
} = useFolderMessages(currentFolderIdParam, {
enabled: isScreenContentAllowed && smNotInDowntime,
})

const folders = foldersData?.data || ([] as SecureMessagingFolderList)
const message = messageData?.data.attributes || ({} as SecureMessagingMessageAttributes)
const includedAttachments = messageData?.included?.filter((included) => included.type === 'attachments')
Expand All @@ -159,11 +175,7 @@ function ViewMessageScreen({ route, navigation }: ViewMessageScreenProps) {
useEffect(() => {
if (messageFetched && currentFolderIdParam === SecureMessagingSystemFolderIdConstants.INBOX && currentPage) {
let updateQueries = false
const inboxMessagesData = queryClient.getQueryData([
secureMessagingKeys.folderMessages,
currentFolderIdParam,
]) as SecureMessagingFolderMessagesGetData
const newInboxMessages = inboxMessagesData.data.map((m) => {
const newInboxMessages = inboxMessagesData?.data.map((m) => {
if (m.attributes.messageId === message.messageId && m.attributes.readReceipt !== READ) {
updateQueries = true
m.attributes.readReceipt = READ
Expand Down Expand Up @@ -209,6 +221,7 @@ function ViewMessageScreen({ route, navigation }: ViewMessageScreenProps) {
messageData?.included,
foldersData,
messageData,
inboxMessagesData,
])

const getFolders = (): PickerItem[] => {
Expand Down Expand Up @@ -354,8 +367,8 @@ function ViewMessageScreen({ route, navigation }: ViewMessageScreenProps) {

// If error is caused by an individual message, we want the error alert to be
// contained to that message, not to take over the entire screen
const hasError = foldersError || messageError || threadError || !smNotInDowntime
const isLoading = loadingFolder || loadingThread || loadingMessage || loadingMoveMessage
const hasError = folderMessagesError || foldersError || messageError || threadError || !smNotInDowntime
const isLoading = loadingFolder || loadingThread || loadingMessage || loadingMoveMessage || loadingFolderMessages
const isEmpty = !message || !thread
const loadingText = loadingMoveMessage ? t('secureMessaging.movingMessage') : t('secureMessaging.viewMessage.loading')

Expand Down Expand Up @@ -385,9 +398,17 @@ function ViewMessageScreen({ route, navigation }: ViewMessageScreenProps) {
) : hasError ? (
<ErrorComponent
screenID={screenID}
error={foldersError || messageError || threadError}
error={folderMessagesError || foldersError || messageError || threadError}
onTryAgain={
foldersError ? refetchFolders : messageError ? refetchMessage : threadError ? refetchThread : undefined
folderMessagesError
? refetchFolderMessages
: foldersError
? refetchFolders
: messageError
? refetchMessage
: threadError
? refetchThread
: undefined
}
/>
) : isEmpty ? (
Expand Down
6 changes: 6 additions & 0 deletions VAMobile/src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ import ProfileScreen from './ProfileScreen/ProfileScreen'
import SettingsScreen from './ProfileScreen/SettingsScreen'
import AccountSecurity from './ProfileScreen/SettingsScreen/AccountSecurity/AccountSecurity'
import DeveloperScreen from './ProfileScreen/SettingsScreen/DeveloperScreen'
import OverrideAPIScreen from './ProfileScreen/SettingsScreen/DeveloperScreen/OverrideApiScreen'
import RemoteConfigScreen from './ProfileScreen/SettingsScreen/DeveloperScreen/RemoteConfigScreen'
import NotificationsSettingsScreen from './ProfileScreen/SettingsScreen/NotificationsSettingsScreen/NotificationsSettingsScreen'

Expand Down Expand Up @@ -583,6 +584,11 @@ function HomeStackScreen({}: HomeStackScreenProps) {
options={FEATURE_LANDING_TEMPLATE_OPTIONS}
/>
<HomeScreenStack.Screen name="Developer" component={DeveloperScreen} options={FEATURE_LANDING_TEMPLATE_OPTIONS} />
<HomeScreenStack.Screen
name="OverrideAPI"
component={OverrideAPIScreen}
options={FEATURE_LANDING_TEMPLATE_OPTIONS}
/>
<HomeScreenStack.Screen
name="RemoteConfig"
component={RemoteConfigScreen}
Expand Down
1 change: 1 addition & 0 deletions VAMobile/src/screens/HomeScreen/HomeStackScreens.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export type HomeStackParamList = WebviewStackParams & {
PersonalInformation: undefined
PreferredName: undefined
ContactInformation: undefined
OverrideAPI: undefined
RemoteConfig: undefined
Settings: undefined
WaygateEdit: { waygateName: string; waygate: Waygate }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,11 @@ function DeveloperScreen({ navigation }: DeveloperScreenSettingsScreenProps) {
</TextView>
<SimpleList items={firebaseList} />
</Box>
<Box mt={theme.dimensions.standardMarginBetween}>
<TextArea>
<Button onPress={() => navigateTo('OverrideAPI')} label={'Override Api Calls'} />
</TextArea>
</Box>
<Box mt={theme.dimensions.condensedMarginBetween}>
<TextArea>
<TextView variant="MobileBodyBold" accessibilityRole="header">
Expand Down
Loading

0 comments on commit 8da7b5f

Please sign in to comment.