Repository navigation
Remove contacts prompt #106089
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mountiny
merged 5 commits into
Expensify:main
from
software-mansion-labs:fix/remove-contacts-prompt
Nov 7, 2026
Merged
Remove contacts prompt #106089
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
tests/unit/components/Share/ShareTabParticipantsSelectorTest.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| import {render} from '@testing-library/react-native'; | ||
|
|
||
| import ShareTabParticipantsSelector from '@components/Share/ShareTabParticipantsSelector'; | ||
|
|
||
| import type MoneyRequestParticipantsSelector from '@pages/iou/request/MoneyRequestParticipantsSelector'; | ||
|
|
||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import ROUTES from '@src/ROUTES'; | ||
|
|
||
| import type {ComponentProps} from 'react'; | ||
|
|
||
| import React from 'react'; | ||
|
|
||
| type CapturedSelectorProps = Pick<ComponentProps<typeof MoneyRequestParticipantsSelector>, 'shouldShowContactImportPrompt' | 'shouldDeferTextInputAutoFocus'>; | ||
|
|
||
| let lastSelectorProps: CapturedSelectorProps | undefined; | ||
| jest.mock('@pages/iou/request/MoneyRequestParticipantsSelector', () => { | ||
| function MockMoneyRequestParticipantsSelector({shouldShowContactImportPrompt, shouldDeferTextInputAutoFocus}: CapturedSelectorProps) { | ||
| lastSelectorProps = {shouldShowContactImportPrompt, shouldDeferTextInputAutoFocus}; | ||
| return null; | ||
| } | ||
| MockMoneyRequestParticipantsSelector.displayName = 'MoneyRequestParticipantsSelector'; | ||
| return MockMoneyRequestParticipantsSelector; | ||
| }); | ||
|
|
||
| // Onyx values by key; each test sets the ones it needs before rendering. | ||
| const mockOnyxValues: Record<string, unknown> = {}; | ||
| jest.mock('@hooks/useOnyx', () => (key: string) => [mockOnyxValues[key], {status: 'loaded'}]); | ||
|
|
||
| jest.mock('@hooks/useCurrentUserPersonalDetails', () => () => ({accountID: 1})); | ||
| jest.mock('@hooks/usePreferredPolicy', () => () => ({isRestrictedToPreferredPolicy: false, preferredPolicyID: undefined})); | ||
| jest.mock('@libs/telemetry/activeSpans', () => ({cancelSpan: jest.fn(), getSpan: jest.fn(), startSpan: jest.fn()})); | ||
| jest.mock('@libs/actions/IOU/MoneyRequest', () => ({clearMoneyRequest: jest.fn()})); | ||
| jest.mock('@libs/actions/Share', () => ({saveUnknownUserDetails: jest.fn()})); | ||
| jest.mock('@libs/Navigation/Navigation', () => ({navigate: jest.fn(), getActiveRoute: jest.fn(() => '')})); | ||
| jest.mock('@libs/ReportUtils', () => ({getPolicyExpenseChat: jest.fn()})); | ||
| jest.mock('@userActions/Report', () => ({getOptimisticChatReport: jest.fn(), saveReportDraft: jest.fn()})); | ||
|
|
||
| const sharedHeic = {id: 'shared.heic', content: 'file:///sharedFiles/shared.heic', mimeType: CONST.SHARE_FILE_MIMETYPE.HEIC}; | ||
| const sharedJpeg = {id: 'shared.jpeg', content: 'file:///sharedFiles/shared.jpeg', mimeType: CONST.SHARE_FILE_MIMETYPE.JPEG}; | ||
|
|
||
| function renderSelector() { | ||
| return render(<ShareTabParticipantsSelector detailsPageRouteObject={ROUTES.SHARE_SUBMIT_DETAILS} />); | ||
| } | ||
|
|
||
| describe('ShareTabParticipantsSelector', () => { | ||
| beforeEach(() => { | ||
| lastSelectorProps = undefined; | ||
| for (const key of Object.keys(mockOnyxValues)) { | ||
| delete mockOnyxValues[key]; | ||
| } | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['Submit', ROUTES.SHARE_SUBMIT_DETAILS], | ||
| ['Share', ROUTES.SHARE_DETAILS], | ||
| ])('does not show the import contacts prompt in the %s tab', (_tabName, detailsPageRouteObject) => { | ||
| // Given the share flow is open on this tab | ||
| // When its participant picker renders | ||
| render(<ShareTabParticipantsSelector detailsPageRouteObject={detailsPageRouteObject} />); | ||
|
|
||
| // Then it turns the prompt off, so it can't open over the share flow's file error bottom sheet | ||
| expect(lastSelectorProps?.shouldShowContactImportPrompt).toBe(false); | ||
| }); | ||
|
|
||
| it('waits to focus the search input until the shared file is known', () => { | ||
| // Given the shared file hasn't been read yet | ||
| // When the picker renders | ||
| renderSelector(); | ||
|
|
||
| // Then the keyboard stays closed for now, because the file may still need checking | ||
| expect(lastSelectorProps?.shouldDeferTextInputAutoFocus).toBe(true); | ||
| }); | ||
|
|
||
| it('focuses the search input right away for a shared file that needs no checking', () => { | ||
| // Given a shared JPEG, which skips the HEIC/image check | ||
| mockOnyxValues[ONYXKEYS.SHARE_TEMP_FILE] = sharedJpeg; | ||
|
|
||
| // When the picker renders | ||
| renderSelector(); | ||
|
|
||
| // Then the search input can focus right away | ||
| expect(lastSelectorProps?.shouldDeferTextInputAutoFocus).toBe(false); | ||
| }); | ||
|
|
||
| it('keeps the keyboard closed while a shared HEIC is checked, and opens it only once the file has passed', () => { | ||
| // Given a shared HEIC that is still being converted, or failed and is showing the error bottom sheet | ||
| mockOnyxValues[ONYXKEYS.SHARE_TEMP_FILE] = sharedHeic; | ||
| const {rerender} = renderSelector(); | ||
|
|
||
| // Then the search input waits, so the keyboard can't open under the error bottom sheet | ||
| expect(lastSelectorProps?.shouldDeferTextInputAutoFocus).toBe(true); | ||
|
|
||
| // When the converted file is saved | ||
| mockOnyxValues[ONYXKEYS.VALIDATED_FILE_OBJECT] = {uri: 'file:///converted.jpg', name: 'shared.jpg', type: 'image/jpeg'}; | ||
| rerender(<ShareTabParticipantsSelector detailsPageRouteObject={ROUTES.SHARE_SUBMIT_DETAILS} />); | ||
|
|
||
| // Then the search input may focus | ||
| expect(lastSelectorProps?.shouldDeferTextInputAutoFocus).toBe(false); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import {renderHook, waitFor} from '@testing-library/react-native'; | ||
|
|
||
| import useContactPermissionModal from '@hooks/useContactPermissionModal/index.native'; | ||
|
|
||
| import {getContactPermission} from '@libs/ContactPermission'; | ||
|
|
||
| import {RESULTS} from 'react-native-permissions'; | ||
|
|
||
| import type * as MockUseConfirmModalUtil from '../../utils/mockUseConfirmModal'; | ||
|
|
||
| import {mockShowConfirmModal, resetMockConfirmModal} from '../../utils/mockUseConfirmModal'; | ||
|
|
||
| jest.mock('@hooks/useConfirmModal', () => { | ||
| const {default: mockUseConfirmModal} = jest.requireActual<typeof MockUseConfirmModalUtil>('../../utils/mockUseConfirmModal'); | ||
| return mockUseConfirmModal; | ||
| }); | ||
|
|
||
| jest.mock('@components/Modal/Global/ModalContext', () => { | ||
| const {createMockModalContextModule} = jest.requireActual<typeof MockUseConfirmModalUtil>('../../utils/mockUseConfirmModal'); | ||
| return createMockModalContextModule(); | ||
| }); | ||
|
|
||
| jest.mock('@hooks/useLazyAsset', () => ({ | ||
| useMemoizedLazyIllustrations: () => ({ToddWithPhones: 'ToddWithPhones'}), | ||
| })); | ||
|
|
||
| jest.mock('@hooks/useLocalize', () => () => ({ | ||
| translate: (key: string) => key, | ||
| })); | ||
|
|
||
| jest.mock('@hooks/useThemeStyles', () => () => ({ | ||
| mb0: {}, | ||
| mb4: {}, | ||
| mt2: {}, | ||
| textHeadline: {}, | ||
| textLabelSupportingEmptyValue: {}, | ||
| })); | ||
|
|
||
| jest.mock('@hooks/useOnyx', () => () => [false, {status: 'loaded'}]); | ||
|
|
||
| jest.mock('@libs/actions/ContactPermissions', () => ({ | ||
| setHasDeniedContactImportPrompt: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@libs/ContactPermission', () => ({ | ||
| getContactPermission: jest.fn(), | ||
| requestContactPermission: jest.fn(), | ||
| })); | ||
|
|
||
| const mockGetContactPermission = jest.mocked(getContactPermission); | ||
|
|
||
| function renderContactPermissionModal(isEnabled?: boolean) { | ||
| const params = {onDeny: jest.fn(), onGrant: jest.fn(), onFocusTextInput: jest.fn(), isEnabled}; | ||
| return {params, ...renderHook(() => useContactPermissionModal(params))}; | ||
| } | ||
|
|
||
| describe('useContactPermissionModal', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| resetMockConfirmModal(); | ||
| // Contacts permission hasn't been asked yet, which is when the prompt normally shows. | ||
| mockGetContactPermission.mockResolvedValue(RESULTS.DENIED); | ||
| }); | ||
|
|
||
| it('shows the import contacts prompt when contacts permission has not been asked yet', async () => { | ||
| // Given the prompt is enabled (the default) and contacts permission hasn't been asked yet | ||
| // When the hook mounts | ||
| renderContactPermissionModal(); | ||
|
|
||
| // Then the import contacts prompt opens | ||
| await waitFor(() => expect(mockShowConfirmModal).toHaveBeenCalledTimes(1)); | ||
|
mountiny marked this conversation as resolved.
Resolved
|
||
| }); | ||
|
|
||
| it('does not show the prompt when it is disabled, and focuses the text input instead', async () => { | ||
| // Given a picker that turned the prompt off, as the share flow does | ||
| // When the hook mounts | ||
| const {params} = renderContactPermissionModal(false); | ||
|
|
||
| // Then the text input is focused as if the prompt weren't needed | ||
| await waitFor(() => expect(params.onFocusTextInput).toHaveBeenCalledTimes(1)); | ||
|
|
||
| // And neither the prompt nor the permission check runs | ||
| expect(mockShowConfirmModal).not.toHaveBeenCalled(); | ||
| expect(mockGetContactPermission).not.toHaveBeenCalled(); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.