diff --git a/config/eslint/eslint.seatbelt.tsv b/config/eslint/eslint.seatbelt.tsv index 4bcd11676429..f689394506aa 100644 --- a/config/eslint/eslint.seatbelt.tsv +++ b/config/eslint/eslint.seatbelt.tsv @@ -81,6 +81,7 @@ "../../src/components/AmountTextInput.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/AnchorForAttachmentsOnly/index.tsx" "no-restricted-syntax" 1 "../../src/components/AnchorForCommentsOnly/index.tsx" "no-restricted-syntax" 1 +"../../src/components/AnimatedCollapsible/index.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/AnimatedFlatListWithCellRenderer.tsx" "@typescript-eslint/no-deprecated/Animated.createAnimatedComponent" 1 "../../src/components/AnimatedFlatListWithCellRenderer.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/AnimatedFlatListWithCellRenderer.tsx" "react-hooks/refs" 2 @@ -88,6 +89,7 @@ "../../src/components/AnimatedSubmitButton/index.tsx" "no-restricted-imports" 1 "../../src/components/AnimatedSubmitButton/index.tsx" "react-hooks/refs" 6 "../../src/components/AnimatedSubmitButton/index.tsx" "react-hooks/set-state-in-effect" 1 +"../../src/components/ApprovalWorkflowSection.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/AttachmentPicker/index.native.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/AttachmentPicker/index.native.tsx" "react-hooks/refs" 1 "../../src/components/AttachmentPicker/index.tsx" "react-hooks/refs" 1 @@ -114,9 +116,18 @@ "../../src/components/AvatarWithImagePicker.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/AvatarWithImagePicker.tsx" "react-hooks/set-state-in-effect" 2 "../../src/components/BookTravelButton.tsx" "no-restricted-imports" 1 +"../../src/components/Button/index.tsx" "@typescript-eslint/no-deprecated/extraSmall" 2 +"../../src/components/Button/index.tsx" "@typescript-eslint/no-deprecated/large" 2 +"../../src/components/Button/index.tsx" "@typescript-eslint/no-deprecated/medium" 2 +"../../src/components/Button/index.tsx" "@typescript-eslint/no-deprecated/small" 2 "../../src/components/Button/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/Button/validateSubmitShortcut/index.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/ButtonComposed/Button.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 +"../../src/components/ButtonComposed/primitives/ButtonIcon.tsx" "@typescript-eslint/no-deprecated/large" 1 +"../../src/components/ButtonComposed/primitives/ButtonIcon.tsx" "@typescript-eslint/no-deprecated/medium" 1 +"../../src/components/ButtonComposed/primitives/ButtonIcon.tsx" "@typescript-eslint/no-deprecated/small" 1 +"../../src/components/ButtonWithDropdownMenu/index.tsx" "@typescript-eslint/no-deprecated/medium" 1 +"../../src/components/ButtonWithDropdownMenu/index.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/ButtonWithDropdownMenu/index.tsx" "react-hooks/preserve-manual-memoization" 1 "../../src/components/ButtonWithDropdownMenu/index.tsx" "react-hooks/refs" 3 "../../src/components/ButtonWithDropdownMenu/index.tsx" "react-hooks/set-state-in-effect" 1 @@ -143,6 +154,7 @@ "../../src/components/ConnectToXeroFlow/index.tsx" "react-hooks/set-state-in-effect" 1 "../../src/components/ContactPermissionModal/index.native.tsx" "@typescript-eslint/no-deprecated/ConfirmModal" 1 "../../src/components/ContactPermissionModal/index.native.tsx" "@typescript-eslint/no-deprecated/InteractionManager.runAfterInteractions" 2 +"../../src/components/ContextMenuItem.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/CountryPicker/CountrySelectorModal.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/CountryPicker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/DatePicker/CalendarPicker/MonthPickerModal.tsx" "react-hooks/set-state-in-effect" 1 @@ -192,6 +204,7 @@ "../../src/components/Form/FormProvider.tsx" "react-hooks/refs" 2 "../../src/components/Form/InputWrapper.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/Form/InputWrapper.tsx" "react-hooks/refs" 1 +"../../src/components/FormHelpMessage.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/FullscreenLoadingIndicator.tsx" "@typescript-eslint/no-deprecated/StyleSheet.absoluteFillObject" 1 "../../src/components/GPSInProgressModal/index.native.tsx" "@typescript-eslint/no-deprecated/ConfirmModal" 1 "../../src/components/GPSTripStateChecker/index.native.tsx" "@typescript-eslint/no-deprecated/ConfirmModal" 1 @@ -235,6 +248,7 @@ "../../src/components/InteractiveStepSubPageHeader.tsx" "no-restricted-syntax" 1 "../../src/components/KYCWall/BaseKYCWall.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/components/KYCWall/BaseKYCWall.tsx" "react-hooks/refs" 2 +"../../src/components/LHNOptionsList/LHNEmptyState.tsx" "@typescript-eslint/no-deprecated/small" 2 "../../src/components/LHNOptionsList/LHNEmptyState.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/LHNOptionsList/OptionRowLHN/OptionRow/Pressable.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/LoadingIndicator.tsx" "@typescript-eslint/no-deprecated/StyleSheet.absoluteFillObject" 1 @@ -320,6 +334,7 @@ "../../src/components/PDFView/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/PDFView/index.tsx" "react-hooks/set-state-in-effect" 1 "../../src/components/ParentNavigationSubtitle.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 +"../../src/components/PaymentCardDetails.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/components/Picker/BasePicker.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/Picker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/PlanTypeSelector.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 @@ -333,6 +348,7 @@ "../../src/components/PressableWithSecondaryInteraction/index.native.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/PressableWithSecondaryInteraction/index.native.tsx" "no-restricted-syntax" 1 "../../src/components/PressableWithSecondaryInteraction/index.tsx" "no-restricted-syntax" 1 +"../../src/components/ProductTrainingContext/index.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/components/RNMarkdownTextInput.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/RNMaskedTextInput.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/RadioButtonWithLabel.tsx" "no-restricted-syntax" 1 @@ -392,12 +408,16 @@ "../../src/components/Search/SearchList/ListItem/BaseListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/CardListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/components/Search/SearchList/ListItem/ChatListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 +"../../src/components/Search/SearchList/ListItem/ExpandCollapseArrowButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Search/SearchList/ListItem/ExpenseReportListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 5 "../../src/components/Search/SearchList/ListItem/ExpenseReportListItemRow/ExpenseReportListItemRowWide.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 +"../../src/components/Search/SearchList/ListItem/ExportedIconCell.tsx" "@typescript-eslint/no-deprecated/small" 2 "../../src/components/Search/SearchList/ListItem/GroupChildrenContent.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/components/Search/SearchList/ListItem/GroupHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/components/Search/SearchList/ListItem/MemberListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 +"../../src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Search/SearchList/ListItem/ReportListItemHeader.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 +"../../src/components/Search/SearchList/ListItem/SearchQueryListItem.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/components/Search/SearchList/ListItem/TaskListItem.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchList/ListItem/TaskListItemRow.tsx" "no-restricted-imports" 1 "../../src/components/Search/SearchList/ListItem/TransactionGroupListExpanded.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 @@ -410,8 +430,15 @@ "../../src/components/Search/SearchMultipleSelectionPicker.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchPageHeader/SearchActionsBarCreateButton.tsx" "no-restricted-imports" 1 +"../../src/components/Search/SearchPageHeader/SearchAdvancedFiltersButton.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 +"../../src/components/Search/SearchPageHeader/SearchAdvancedFiltersButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Search/SearchPageHeader/SearchAdvancedFiltersButton.tsx" "no-restricted-imports" 1 +"../../src/components/Search/SearchPageHeader/SearchDisplayDropdownButton.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 +"../../src/components/Search/SearchPageHeader/SearchDisplayDropdownButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Search/SearchPageHeader/SearchFilterBar.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 +"../../src/components/Search/SearchPageHeader/SearchFiltersClearButton.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 +"../../src/components/Search/SearchPageHeader/SearchSaveButton.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 +"../../src/components/Search/SearchPageHeader/SearchSaveButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Search/SearchPageHeader/SearchSaveButton.tsx" "no-restricted-imports" 1 "../../src/components/Search/SearchPageHeader/useSearchFiltersBar.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Search/SearchPageHeader/useSearchPageInput.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 @@ -452,6 +479,7 @@ "../../src/components/SoftKillTestToolRow/index.native.tsx" "no-restricted-imports" 1 "../../src/components/SpendRules/SpendRuleRestrictionTypeToggle.tsx" "no-restricted-imports" 1 "../../src/components/SpendRules/SpendRuleRestrictionTypeToggleRevamp.tsx" "no-restricted-imports" 1 +"../../src/components/SpendRules/configuration/SpendRulesCurrencyBase.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/components/StatePicker/StateSelectorModal.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/StatePicker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/StatusBadge.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 @@ -466,14 +494,18 @@ "../../src/components/SubStepForms/PushRowFieldsStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/components/SubStepForms/RegistrationNumberStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/components/SwipeableView/index.native.tsx" "react-hooks/refs" 2 +"../../src/components/SymbolButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/SymbolButton.tsx" "no-restricted-syntax" 1 +"../../src/components/TabSelector/TabIcon.tsx" "@typescript-eslint/no-deprecated/small" 2 "../../src/components/TabSelector/getBackground.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Table/Table.tsx" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/components/Table/TableContext.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 +"../../src/components/Table/TableFilterBar/TableFilterTrigger.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/Table/middlewares/filtering.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Tables/WorkspaceCompanyCardsTable/WorkspaceCompanyCardsTableRow.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Tables/WorkspaceCompanyCardsTable/WorkspaceCompanyCardsTableRow.tsx" "no-restricted-imports" 1 "../../src/components/Tables/WorkspaceCompanyCardsTable/index.tsx" "no-restricted-imports" 1 +"../../src/components/Tables/WorkspaceExpensifyCardsTable/WorkspaceExpensifyCardsTableRow.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/TagPicker/index.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/TaxPicker.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/TestCrash/index.native.tsx" "no-restricted-imports" 1 @@ -509,13 +541,16 @@ "../../src/components/Tooltip/PopoverAnchorTooltip.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/Tooltip/PopoverAnchorTooltip.tsx" "react-hooks/refs" 7 "../../src/components/TransactionItemRow/DataCells/MerchantCell.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 +"../../src/components/TransactionItemRow/EditableCell/EditableCell.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 "../../src/components/UpdateAppModal.tsx" "@typescript-eslint/no-deprecated/ConfirmModal" 1 +"../../src/components/UploadFile.tsx" "@typescript-eslint/no-deprecated/medium" 2 "../../src/components/UploadFile.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/ValidateCodeActionModal/ValidateCodeForm/BaseValidateCodeForm.tsx" "no-restricted-imports" 1 "../../src/components/VideoPlayer/BaseVideoPlayer.tsx" "@typescript-eslint/no-unsafe-type-assertion" 7 "../../src/components/VideoPlayer/BaseVideoPlayer.tsx" "no-restricted-syntax" 1 "../../src/components/VideoPlayer/BaseVideoPlayer.tsx" "react-hooks/refs" 13 "../../src/components/VideoPlayer/BaseVideoPlayer.tsx" "react-hooks/set-state-in-effect" 2 +"../../src/components/VideoPlayer/IconButton.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/components/VideoPlayer/useHandleNativeVideoControls/index.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/VideoPlayerContexts/PlaybackContext/playbackContextReportIDUtils.ts" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/components/WalletStatementModal/index.native.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 @@ -1124,6 +1159,7 @@ "../../src/pages/ReimbursementAccount/USD/ConnectBankAccount/components/BankAccountValidationForm.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/ReimbursementAccount/USD/KYBDocuments/index.tsx" "no-restricted-imports" 1 "../../src/pages/ReimbursementAccount/USD/USDVerifiedBankAccountFlowPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 +"../../src/pages/ReimbursementAccount/VerifiedBankAccountFlowEntryPoint.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/pages/ReimbursementAccount/utils/getSubStepValues.ts" "@typescript-eslint/no-unsafe-type-assertion" 4 "../../src/pages/ReportDescriptionPage.tsx" "no-restricted-imports" 1 "../../src/pages/ReportDescriptionPage.tsx" "no-restricted-syntax" 1 @@ -1152,6 +1188,7 @@ "../../src/pages/Search/SearchEditMultiple/SearchEditMultipleUtils.ts" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/pages/Search/SearchMoneyRequestReportPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/Search/SearchPage.tsx" "react-hooks/set-state-in-effect" 1 +"../../src/pages/Search/SearchPageNarrow/StaticSearchActionsBar.tsx" "@typescript-eslint/no-deprecated/small" 3 "../../src/pages/Search/SearchSavePage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/pages/Search/SearchTransactionsChangeReport.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/Share/ShareButton.tsx" "no-restricted-imports" 1 @@ -1185,6 +1222,7 @@ "../../src/pages/ValidateLoginPage/index.web.tsx" "react-hooks/set-state-in-effect" 1 "../../src/pages/domain/Admins/DomainAdminsPage.tsx" "no-restricted-imports" 1 "../../src/pages/domain/BaseDomainRequireTwoFactorAuthPage.tsx" "no-restricted-imports" 1 +"../../src/pages/domain/BaseVerifyDomainPage.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/pages/domain/DomainAccessRestrictedPage.tsx" "no-restricted-imports" 1 "../../src/pages/domain/DomainsListPage.tsx" "no-restricted-imports" 1 "../../src/pages/domain/Groups/DomainGroupsPage.tsx" "no-restricted-imports" 1 @@ -1216,6 +1254,7 @@ "../../src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/inbox/report/ContextMenu/PopoverReportActionContextMenu.tsx" "react-hooks/refs" 30 "../../src/pages/inbox/report/EnableNotificationsBanner.tsx" "no-restricted-imports" 1 +"../../src/pages/inbox/report/FloatingMessageCounter.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/pages/inbox/report/FloatingMessageCounter.tsx" "no-restricted-imports" 1 "../../src/pages/inbox/report/ListBoundaryLoader.tsx" "react-hooks/set-state-in-effect" 1 "../../src/pages/inbox/report/ReactionList/HeaderReactionList.tsx" "no-restricted-syntax" 1 @@ -1239,6 +1278,7 @@ "../../src/pages/inbox/report/ReportActionsList.tsx" "react-hooks/refs" 1 "../../src/pages/inbox/report/ShowPreviousMessagesButton.tsx" "no-restricted-imports" 1 "../../src/pages/inbox/report/TripSummary.tsx" "rulesdir/no-default-id-values" 1 +"../../src/pages/inbox/report/WhisperBanner.tsx" "@typescript-eslint/no-deprecated/small" 1 "../../src/pages/inbox/report/WhisperBanner.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/pages/inbox/report/actionContents/ActionContentRouter.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/inbox/report/actionContents/ChatMessageContent.tsx" "no-restricted-imports" 1 @@ -1384,6 +1424,7 @@ "../../src/pages/settings/Subscription/CardAuthenticationModal/index.tsx" "react-hooks/set-state-in-effect" 1 "../../src/pages/settings/Subscription/CardSection/BillingBanner/EarlyDiscountBanner.tsx" "no-restricted-imports" 1 "../../src/pages/settings/Subscription/CardSection/CardSectionButton/index.tsx" "no-restricted-imports" 1 +"../../src/pages/settings/Subscription/CardSection/CardSectionDataEmpty/index.native.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/pages/settings/Subscription/CardSection/CardSectionDataEmpty/index.tsx" "no-restricted-imports" 1 "../../src/pages/settings/Subscription/FreeTrial.tsx" "no-restricted-imports" 1 "../../src/pages/settings/Subscription/PaymentCard/ChangeBillingCurrency/index.tsx" "no-restricted-syntax" 1 @@ -1407,6 +1448,7 @@ "../../src/pages/settings/Wallet/InternationalDepositAccount/PersonalInfo/PersonalInfo.tsx" "@typescript-eslint/no-deprecated/useSubStep" 1 "../../src/pages/settings/Wallet/InternationalDepositAccount/PersonalInfo/substeps/AddressStep.tsx" "@typescript-eslint/no-unsafe-type-assertion" 6 "../../src/pages/settings/Wallet/InternationalDepositAccount/PersonalInfo/substeps/AddressStep.tsx" "react-hooks/set-state-in-effect" 1 +"../../src/pages/settings/Wallet/InternationalDepositAccount/subPages/AccountFlowEntryPoint.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/pages/settings/Wallet/InternationalDepositAccount/subPages/Confirmation.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/settings/Wallet/InternationalDepositAccount/utils.ts" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/settings/Wallet/PaymentMethodList.tsx" "@typescript-eslint/no-unsafe-type-assertion" 7 @@ -1442,6 +1484,7 @@ "../../src/pages/signin/SignInPageLayout/FooterRow/index.native.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/pages/signin/SignUpWelcomeForm.tsx" "no-restricted-imports" 1 "../../src/pages/signin/UnlinkLoginForm.tsx" "no-restricted-imports" 1 +"../../src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx" "@typescript-eslint/no-deprecated/medium" 1 "../../src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx" "no-restricted-imports" 1 "../../src/pages/signin/ValidateCodeForm/BaseValidateCodeForm.tsx" "react-hooks/set-state-in-effect" 4 "../../src/pages/tasks/TaskShareDestinationSelectorModal.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 @@ -1654,6 +1697,7 @@ "../../src/pages/workspace/withPolicyAndFullscreenLoading.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 "../../src/pages/workspace/workflows/WorkspaceAutoReportingFrequencyPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 2 "../../src/pages/workspace/workflows/WorkspaceAutoReportingMonthlyOffsetPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 1 +"../../src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx" "@typescript-eslint/no-deprecated/extraSmall" 1 "../../src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx" "@typescript-eslint/no-unsafe-type-assertion" 3 "../../src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx" "@typescript-eslint/no-deprecated/ConfirmModal" 2 "../../src/pages/workspace/workflows/approvals/WorkspaceWorkflowsApprovalsApprovalLimitPage.tsx" "no-restricted-imports" 1 diff --git a/src/hooks/useChatWithAgent.ts b/src/hooks/useChatWithAgent.ts index c9d305cb0f59..e3a9deec2565 100644 --- a/src/hooks/useChatWithAgent.ts +++ b/src/hooks/useChatWithAgent.ts @@ -10,6 +10,8 @@ import useOnyx from './useOnyx'; /** * Encapsulates the data fetching and navigation logic for opening a DM chat with an agent. * Returns a function that, given an accountID, navigates to the DM report with that agent. + * Pass `shouldDismissModal` when the caller lives on the RHP/modal stack (e.g. the add-agent + * flow) so the modal is dismissed before navigating and the new DM is actually shown. */ function useChatWithAgent() { const currentUserPersonalDetails = useCurrentUserPersonalDetails(); @@ -18,8 +20,8 @@ function useChatWithAgent() { const [betas] = useOnyx(ONYXKEYS.BETAS); const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST); - const chatWithAgent = (accountID: number) => { - navigateToAndOpenReportWithAccountIDs([accountID], currentUserPersonalDetails.accountID, introSelected, isSelfTourViewed, betas, personalDetails); + const chatWithAgent = (accountID: number, {shouldDismissModal = false}: {shouldDismissModal?: boolean} = {}) => { + navigateToAndOpenReportWithAccountIDs([accountID], currentUserPersonalDetails.accountID, introSelected, isSelfTourViewed, betas, personalDetails, false, shouldDismissModal); }; return chatWithAgent; diff --git a/src/hooks/useOpenDMWithCreatedAgent.ts b/src/hooks/useOpenDMWithCreatedAgent.ts new file mode 100644 index 000000000000..25f0794f1ab8 --- /dev/null +++ b/src/hooks/useOpenDMWithCreatedAgent.ts @@ -0,0 +1,90 @@ +import Navigation from '@libs/Navigation/Navigation'; + +import CONST from '@src/CONST'; +import ONYXKEYS from '@src/ONYXKEYS'; + +import {useEffect, useRef} from 'react'; + +import useChatWithAgent from './useChatWithAgent'; +import useOnyx from './useOnyx'; + +type PendingCreatedAgent = { + optimisticAccountID: number; + // The agents that already existed before this one was created. Null until the collection has loaded and + // includes our optimistic entry, so agents that load later aren't treated as the new one. + knownAgentAccountIDs: Set | null; +}; + +function getAgentAccountIDFromKey(key: string): number { + return Number(key.slice(ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT.length)); +} + +/** + * Waits for the agent created by the most recent `createAgent` call to appear in Onyx, then opens its DM. + * The client can't pick an agent's real accountID; it's set by the server, so we watch for it to arrive. + * If creation fails, we go back instead so the error shows on the Agents list. + * + * Returns a function to start watching, given the optimistic accountID that `createAgent` returned. + */ +function useOpenDMWithCreatedAgent() { + const chatWithAgent = useChatWithAgent(); + const [agentPrompts, agentPromptsMetadata] = useOnyx(ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT); + const pendingCreatedAgentRef = useRef(null); + + useEffect(() => { + const pendingCreatedAgent = pendingCreatedAgentRef.current; + if (!pendingCreatedAgent) { + return; + } + + // Wait for the collection to finish loading, or an existing agent could be matched as the new one. + if (agentPromptsMetadata.status !== 'loaded') { + return; + } + + const optimisticAgentKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${pendingCreatedAgent.optimisticAccountID}`; + + // Record which agents already exist, using the first loaded snapshot that includes our optimistic entry. + // Doing it here instead of when watching starts means agents that load later aren't treated as the new one. + if (!pendingCreatedAgent.knownAgentAccountIDs) { + if (!agentPrompts?.[optimisticAgentKey]) { + return; + } + pendingCreatedAgent.knownAgentAccountIDs = new Set(Object.keys(agentPrompts).map(getAgentAccountIDFromKey)); + return; + } + const {knownAgentAccountIDs} = pendingCreatedAgent; + + // Creation failed: the optimistic entry now has an error. Go back so the error shows on the Agents list. + if (agentPrompts?.[optimisticAgentKey]?.errors) { + pendingCreatedAgentRef.current = null; + Navigation.goBack(); + return; + } + + const createdAgentKey = Object.keys(agentPrompts ?? {}).find((key) => { + const accountID = getAgentAccountIDFromKey(key); + + // Skip agents that already existed and this request's own optimistic entry. + if (accountID === pendingCreatedAgent.optimisticAccountID || knownAgentAccountIDs.has(accountID)) { + return false; + } + + // The created agent is the one from the server, which has no ADD pending action. Another agent the + // user just created still has one. + return agentPrompts?.[key]?.pendingAction !== CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD; + }); + if (!createdAgentKey) { + return; + } + + pendingCreatedAgentRef.current = null; + chatWithAgent(getAgentAccountIDFromKey(createdAgentKey), {shouldDismissModal: true}); + }, [agentPrompts, agentPromptsMetadata.status, chatWithAgent]); + + return (optimisticAccountID: number) => { + pendingCreatedAgentRef.current = {optimisticAccountID, knownAgentAccountIDs: null}; + }; +} + +export default useOpenDMWithCreatedAgent; diff --git a/src/libs/actions/Report/index.ts b/src/libs/actions/Report/index.ts index e297074aa153..c695091be616 100644 --- a/src/libs/actions/Report/index.ts +++ b/src/libs/actions/Report/index.ts @@ -2412,6 +2412,7 @@ function navigateToAndOpenReportWithAccountIDs( betas: OnyxEntry, personalDetails: OnyxEntry, shouldRevalidateExistingChat = false, + shouldDismissModal = false, ) { const participants = participantAccountIDs.map((accountID): ParticipantInfo => { return { @@ -2441,7 +2442,7 @@ function navigateToAndOpenReportWithAccountIDs( betas, }); - navigateToReport(fallbackChat.reportID, {shouldDismissModal: false}); + navigateToReport(fallbackChat.reportID, {shouldDismissModal}); }; if (!chat || isReportNotFound(chat)) { @@ -2450,7 +2451,7 @@ function navigateToAndOpenReportWithAccountIDs( } if (!shouldRevalidateExistingChat) { - navigateToReport(chat.reportID, {shouldDismissModal: false}); + navigateToReport(chat.reportID, {shouldDismissModal}); return; } @@ -2476,7 +2477,7 @@ function navigateToAndOpenReportWithAccountIDs( // Re-open existing chats to re-validate server-side access and refresh stale local state. openReport({reportID: chat.reportID, introSelected, isSelfTourViewed, betas}); - navigateToReport(chat.reportID, {shouldDismissModal: false}); + navigateToReport(chat.reportID, {shouldDismissModal}); } /** diff --git a/src/pages/settings/Agents/AddAgentPage.tsx b/src/pages/settings/Agents/AddAgentPage.tsx index ff0eb09dd6c0..1e7b059381c8 100644 --- a/src/pages/settings/Agents/AddAgentPage.tsx +++ b/src/pages/settings/Agents/AddAgentPage.tsx @@ -11,6 +11,7 @@ import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails' import useIsInLandscapeMode from '@hooks/useIsInLandscapeMode'; import {useMemoizedLazyExpensifyIcons} from '@hooks/useLazyAsset'; import useLocalize from '@hooks/useLocalize'; +import useOpenDMWithCreatedAgent from '@hooks/useOpenDMWithCreatedAgent'; import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; @@ -21,6 +22,7 @@ import type {CustomRNImageManipulatorResult} from '@libs/cropOrRotateImage/types import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackScreenProps} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; +import {getIsOffline} from '@libs/NetworkState'; import type {AvatarSource} from '@libs/UserAvatarUtils'; import {createAgent} from '@userActions/Agent'; @@ -47,12 +49,14 @@ function AddAgentPage({route}: AddAgentPageProps) { const {windowWidth, windowHeight} = useWindowDimensions(); const shouldUseScrollableLayout = useIsInLandscapeMode() || (isMobile() && windowWidth > windowHeight); const {displayName} = useCurrentUserPersonalDetails(); + const watchForCreatedAgent = useOpenDMWithCreatedAgent(); const defaultAgentName = displayName ? translate('addAgentPage.defaultAgentName', displayName) : undefined; const defaultPrompt = translate('addAgentPage.defaultPrompt'); const expensifyIcons = useMemoizedLazyExpensifyIcons(['Pencil']); const avatarStyle = [styles.avatarXLarge, styles.alignSelfCenter]; const [selectedPresetID, setSelectedPresetID] = useState(() => AGENT_AVATARS.ordered.at(Math.floor(Math.random() * AGENT_AVATARS.ordered.length))?.id ?? null); const [uploadedURI, setUploadedURI] = useState(null); + const [isCreatingAgent, setIsCreatingAgent] = useState(false); const pendingFileRef = useRef<{file: File | CustomRNImageManipulatorResult; uri: string} | null>(null); useFocusEffect( @@ -97,16 +101,22 @@ function AddAgentPage({route}: AddAgentPageProps) { const prompt = values[INPUT_IDS.PROMPT].trim(); const pendingFile = pendingFileRef.current; - // Pure optimistic flow — no waiting on the server, online or offline. `createAgent` - // returns the optimistic accountID it wrote into Onyx so we can hand it to the next - // screen and let it render the agent with opacity until CREATE_AGENT resolves. - if (pendingFile) { - createAgent(firstName, prompt, undefined, pendingFile.file, pendingFile.uri, policyID); - } else { - createAgent(firstName, prompt, selectedPresetID ?? undefined, undefined, undefined, policyID); + // createAgent writes the agent right away (works offline) and returns the optimistic accountID. The real + // accountID comes from the server once CREATE_AGENT responds. + const {optimisticAccountID} = pendingFile + ? createAgent(firstName, prompt, undefined, pendingFile.file, pendingFile.uri, policyID) + : createAgent(firstName, prompt, selectedPresetID ?? undefined, undefined, undefined, policyID); + + // Offline: the real accountID won't arrive until reconnect, so don't wait. Go back to the list; the user + // can open the agent themselves. + if (getIsOffline()) { + Navigation.goBack(); + return; } - Navigation.goBack(); + // Online: stay here with the submit spinner until the created agent appears, then its DM opens. + watchForCreatedAgent(optimisticAccountID); + setIsCreatingAgent(true); }; return ( @@ -125,6 +135,7 @@ function AddAgentPage({route}: AddAgentPageProps) { onSubmit={handleSubmit} validate={validate} submitButtonText={translate('addAgentPage.createAgent')} + isLoading={isCreatingAgent} style={[styles.flex1, styles.ph5]} shouldUseScrollView={shouldUseScrollableLayout} submitFlexEnabled={shouldUseScrollableLayout ? undefined : false} diff --git a/tests/unit/hooks/useOpenDMWithCreatedAgent.test.ts b/tests/unit/hooks/useOpenDMWithCreatedAgent.test.ts new file mode 100644 index 000000000000..138a9028be68 --- /dev/null +++ b/tests/unit/hooks/useOpenDMWithCreatedAgent.test.ts @@ -0,0 +1,172 @@ +import {act, renderHook, waitFor} from '@testing-library/react-native'; + +import useChatWithAgent from '@hooks/useChatWithAgent'; +import useOpenDMWithCreatedAgent from '@hooks/useOpenDMWithCreatedAgent'; + +import Navigation from '@libs/Navigation/Navigation'; + +import ONYXKEYS from '@src/ONYXKEYS'; + +import type {OnyxKey} from 'react-native-onyx'; + +import Onyx from 'react-native-onyx'; + +import waitForBatchedUpdates from '../../utils/waitForBatchedUpdates'; + +jest.mock('@hooks/useChatWithAgent'); +jest.mock('@libs/Navigation/Navigation', () => ({goBack: jest.fn()})); + +const mockChatWithAgent = jest.fn(); +const mockUseChatWithAgent = jest.mocked(useChatWithAgent); +const mockGoBack = jest.mocked(Navigation.goBack); + +const OPTIMISTIC_ACCOUNT_ID = -123456; +const REAL_ACCOUNT_ID = 22542959; +const optimisticAgentKey: OnyxKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${OPTIMISTIC_ACCOUNT_ID}`; +const realAgentKey: OnyxKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}${REAL_ACCOUNT_ID}`; + +describe('useOpenDMWithCreatedAgent', () => { + beforeAll(() => { + Onyx.init({keys: ONYXKEYS}); + }); + + beforeEach(async () => { + jest.clearAllMocks(); + mockUseChatWithAgent.mockReturnValue(mockChatWithAgent); + await Onyx.clear(); + await waitForBatchedUpdates(); + }); + + it('does nothing until asked to watch for a created agent', async () => { + renderHook(() => useOpenDMWithCreatedAgent()); + + await act(async () => { + await Onyx.merge(realAgentKey, {}); + await waitForBatchedUpdates(); + }); + + expect(mockChatWithAgent).not.toHaveBeenCalled(); + expect(mockGoBack).not.toHaveBeenCalled(); + }); + + it('opens the DM with the created agent once it appears, ignoring the optimistic entry', async () => { + const {result} = renderHook(() => useOpenDMWithCreatedAgent()); + + act(() => result.current(OPTIMISTIC_ACCOUNT_ID)); + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + expect(mockChatWithAgent).not.toHaveBeenCalled(); + + await act(async () => { + await Onyx.merge(realAgentKey, {}); + await waitForBatchedUpdates(); + }); + + await waitFor(() => expect(mockChatWithAgent).toHaveBeenCalledWith(REAL_ACCOUNT_ID, {shouldDismissModal: true})); + expect(mockChatWithAgent).toHaveBeenCalledTimes(1); + expect(mockGoBack).not.toHaveBeenCalled(); + }); + + it('ignores another agent that is still an optimistic (pending ADD) entry', async () => { + const {result} = renderHook(() => useOpenDMWithCreatedAgent()); + const otherOptimisticAgentKey: OnyxKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}999`; + + act(() => result.current(OPTIMISTIC_ACCOUNT_ID)); + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + + // A second agent the user created shows up as a new optimistic entry (pendingAction ADD). + // It must not be picked as the created agent. + await act(async () => { + await Onyx.merge(otherOptimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + expect(mockChatWithAgent).not.toHaveBeenCalled(); + + // The created agent arrives from the server without an ADD pending action. + await act(async () => { + await Onyx.merge(realAgentKey, {}); + await waitForBatchedUpdates(); + }); + + await waitFor(() => expect(mockChatWithAgent).toHaveBeenCalledWith(REAL_ACCOUNT_ID, {shouldDismissModal: true})); + }); + + it('does not treat an agent that loads after watching starts as the newly created one', async () => { + // Cold open or direct link: the collection has not loaded yet when watching starts. + const {result} = renderHook(() => useOpenDMWithCreatedAgent()); + const preExistingAgentKey: OnyxKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}555`; + + act(() => result.current(OPTIMISTIC_ACCOUNT_ID)); + + // An existing agent loads before our optimistic entry. It must not be picked, since we don't record + // existing agents until our entry is present. + await act(async () => { + await Onyx.merge(preExistingAgentKey, {}); + await waitForBatchedUpdates(); + }); + expect(mockChatWithAgent).not.toHaveBeenCalled(); + + // The optimistic entry appears, so the existing agent is now recorded as already existing. + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + expect(mockChatWithAgent).not.toHaveBeenCalled(); + + // Only the created agent opens the DM. + await act(async () => { + await Onyx.merge(realAgentKey, {}); + await waitForBatchedUpdates(); + }); + + await waitFor(() => expect(mockChatWithAgent).toHaveBeenCalledWith(REAL_ACCOUNT_ID, {shouldDismissModal: true})); + }); + + it('goes back instead of opening a DM when creation fails', async () => { + const {result} = renderHook(() => useOpenDMWithCreatedAgent()); + + act(() => result.current(OPTIMISTIC_ACCOUNT_ID)); + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + + // Creation failed: the optimistic entry now has an error. + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add', errors: {error: 'genericAdd'}}); + await waitForBatchedUpdates(); + }); + + await waitFor(() => expect(mockGoBack).toHaveBeenCalledTimes(1)); + expect(mockChatWithAgent).not.toHaveBeenCalled(); + }); + + it('stops watching after opening a DM, and does not react to further collection changes', async () => { + const {result} = renderHook(() => useOpenDMWithCreatedAgent()); + + act(() => result.current(OPTIMISTIC_ACCOUNT_ID)); + await act(async () => { + await Onyx.merge(optimisticAgentKey, {pendingAction: 'add'}); + await waitForBatchedUpdates(); + }); + await act(async () => { + await Onyx.merge(realAgentKey, {}); + await waitForBatchedUpdates(); + }); + await waitFor(() => expect(mockChatWithAgent).toHaveBeenCalledTimes(1)); + + const unrelatedAgentKey: OnyxKey = `${ONYXKEYS.COLLECTION.SHARED_NVP_AGENT_PROMPT}777`; + await act(async () => { + await Onyx.merge(unrelatedAgentKey, {}); + await waitForBatchedUpdates(); + }); + + expect(mockChatWithAgent).toHaveBeenCalledTimes(1); + expect(mockGoBack).not.toHaveBeenCalled(); + }); +}); diff --git a/tests/unit/pages/settings/AddAgentPageTest.tsx b/tests/unit/pages/settings/AddAgentPageTest.tsx index a98ddb358ba5..89087bd9c894 100644 --- a/tests/unit/pages/settings/AddAgentPageTest.tsx +++ b/tests/unit/pages/settings/AddAgentPageTest.tsx @@ -1,29 +1,42 @@ -import {render} from '@testing-library/react-native'; +import {act, render} from '@testing-library/react-native'; import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails'; +import useOpenDMWithCreatedAgent from '@hooks/useOpenDMWithCreatedAgent'; import Navigation from '@libs/Navigation/Navigation'; import type {PlatformStackRouteProp} from '@libs/Navigation/PlatformStackNavigation/types'; import type {SettingsNavigatorParamList} from '@libs/Navigation/types'; +import {getIsOffline} from '@libs/NetworkState'; import AddAgentPage from '@pages/settings/Agents/AddAgentPage'; import {setInitialPresetID, setNavigationToken} from '@pages/settings/Agents/pendingAgentAvatarStore'; +import {createAgent} from '@userActions/Agent'; + import ROUTES from '@src/ROUTES'; -import type SCREENS from '@src/SCREENS'; +import SCREENS from '@src/SCREENS'; import React from 'react'; +import createMock from '../../../utils/createMock'; +import waitForBatchedUpdates from '../../../utils/waitForBatchedUpdates'; + jest.mock('@userActions/Agent', () => ({ - createAgent: jest.fn(() => ({optimisticAccountID: -123456, avatarURI: undefined})), + createAgent: jest.fn(), })); +const mockCreateAgent = jest.mocked(createAgent); + const mockTranslate = jest.fn().mockImplementation((key: string, param?: string) => (param !== undefined ? `${key}(${param})` : key)); jest.mock('@hooks/useLocalize', () => jest.fn(() => ({translate: mockTranslate}))); jest.mock('@hooks/useCurrentUserPersonalDetails', () => jest.fn(() => ({}))); +const mockWatchForCreatedAgent = jest.fn(); + +jest.mock('@hooks/useOpenDMWithCreatedAgent', () => jest.fn(() => mockWatchForCreatedAgent)); + jest.mock('@hooks/useTheme', () => jest.fn(() => ({textLight: '#fff'}))); jest.mock('@hooks/useThemeStyles', () => @@ -43,13 +56,22 @@ jest.mock('@hooks/useLazyAsset', () => ({ useMemoizedLazyExpensifyIcons: jest.fn(() => ({Pencil: 1})), })); -jest.mock('@hooks/useOnyx', () => jest.fn(() => [undefined, {status: 'loaded'}])); - jest.mock('@libs/Navigation/Navigation', () => ({ goBack: jest.fn(), navigate: jest.fn(), + isActiveRoute: jest.fn(() => true), })); +jest.mock('@libs/NetworkState', () => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const actual = jest.requireActual('@libs/NetworkState'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return { + ...actual, + getIsOffline: jest.fn(() => false), + }; +}); + jest.mock('@react-navigation/native', () => { // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const actual = jest.requireActual('@react-navigation/native'); @@ -77,10 +99,12 @@ jest.mock('@components/HeaderWithBackButton', () => { }); let mockFormOnSubmit: ((values: {firstName: string; prompt: string}) => void) | undefined; +let mockFormIsLoading: boolean | undefined; jest.mock('@components/Form/FormProvider', () => { - function MockFormProvider({children, onSubmit}: {children: React.ReactNode; onSubmit: (values: {firstName: string; prompt: string}) => void}) { + function MockFormProvider({children, onSubmit, isLoading}: {children: React.ReactNode; onSubmit: (values: {firstName: string; prompt: string}) => void; isLoading?: boolean}) { mockFormOnSubmit = onSubmit; + mockFormIsLoading = isLoading; return children; } return MockFormProvider; @@ -115,19 +139,39 @@ const mockSetInitialPresetID = jest.mocked(setInitialPresetID); const mockSetNavigationToken = jest.mocked(setNavigationToken); const mockNavigate = jest.mocked(Navigation.navigate); const mockGoBack = jest.mocked(Navigation.goBack); +const mockIsActiveRoute = jest.mocked(Navigation.isActiveRoute); +const mockGetIsOffline = jest.mocked(getIsOffline); const mockUseCurrentUserPersonalDetails = jest.mocked(useCurrentUserPersonalDetails); +const mockUseOpenDMWithCreatedAgent = jest.mocked(useOpenDMWithCreatedAgent); type AddAgentRouteProp = PlatformStackRouteProp; function makeRoute(params: AddAgentRouteProp['params'] = {}): AddAgentRouteProp { - return {name: '', key: '', params} as unknown as AddAgentRouteProp; + return createMock({name: SCREENS.SETTINGS.AGENTS.ADD, key: '', params}); +} + +const OPTIMISTIC_ACCOUNT_ID = -123456; +const mockNavigation = undefined as never; + +function renderAddAgentPage(params: AddAgentRouteProp['params'] = {}) { + return render( + , + ); } describe('AddAgentPage', () => { beforeEach(() => { jest.clearAllMocks(); mockUseCurrentUserPersonalDetails.mockReturnValue({accountID: 0}); + mockUseOpenDMWithCreatedAgent.mockReturnValue(mockWatchForCreatedAgent); + mockCreateAgent.mockReturnValue({optimisticAccountID: OPTIMISTIC_ACCOUNT_ID, avatarURI: undefined}); + mockGetIsOffline.mockReturnValue(false); + mockIsActiveRoute.mockReturnValue(true); mockAvatarOnPress = undefined; + mockFormIsLoading = undefined; }); it('renders page title', () => { @@ -230,37 +274,43 @@ describe('AddAgentPage', () => { expect(mockSetInitialPresetID).toHaveBeenCalledTimes(1); }); + // Matching the created agent and opening its DM is covered by useOpenDMWithCreatedAgent.test.ts. + // These tests only cover how AddAgentPage wires into that hook. describe('submit branching', () => { beforeEach(() => { mockFormOnSubmit = undefined; }); - it('goes back when policyID is absent in route params', () => { - render( - , - ); + it('starts watching for the created agent and shows the loading state when online (policyID absent)', () => { + renderAddAgentPage({}); - mockFormOnSubmit?.({firstName: 'Bot', prompt: 'Reject gambling.'}); + act(() => mockFormOnSubmit?.({firstName: 'Bot', prompt: 'Reject gambling.'})); - expect(mockGoBack).toHaveBeenCalledTimes(1); - expect(mockNavigate).not.toHaveBeenCalled(); + expect(mockWatchForCreatedAgent).toHaveBeenCalledWith(OPTIMISTIC_ACCOUNT_ID); + expect(mockFormIsLoading).toBe(true); + expect(mockGoBack).not.toHaveBeenCalled(); }); - it('goes back when policyID is present without navigating to a workflow editor', () => { - render( - , - ); + it('starts watching for the created agent when online (policyID present)', () => { + renderAddAgentPage({policyID: 'POL_42'}); + + act(() => mockFormOnSubmit?.({firstName: 'Bot', prompt: 'Reject gambling.'})); + + expect(mockWatchForCreatedAgent).toHaveBeenCalledWith(OPTIMISTIC_ACCOUNT_ID); + expect(mockFormIsLoading).toBe(true); + }); + + it('goes back right away and does not start watching when created offline', async () => { + mockGetIsOffline.mockReturnValue(true); + + renderAddAgentPage({}); - mockFormOnSubmit?.({firstName: 'Bot', prompt: 'Reject gambling.'}); + act(() => mockFormOnSubmit?.({firstName: 'Bot', prompt: 'Reject gambling.'})); expect(mockGoBack).toHaveBeenCalledTimes(1); - expect(mockNavigate).not.toHaveBeenCalled(); + await waitForBatchedUpdates(); + expect(mockWatchForCreatedAgent).not.toHaveBeenCalled(); + expect(mockFormIsLoading).toBeFalsy(); }); }); });