-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Hide Payer row during incomplete bank account setup #90538
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
Open
MelvinBot
wants to merge
8
commits into
main
Choose a base branch
from
claude-payerButtonHiddenDuringBankSetup
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+232
−2
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fa9450d
Hide Payer row when bank account setup is incomplete
MelvinBot ab3ebb2
Use reimbursementChoice === REIMBURSEMENT_YES instead of isBankAccoun…
MelvinBot 570f30f
Gate Payer row on reimbursementChoice === REIMBURSEMENT_YES
MelvinBot 72f5ac3
Add unit tests for Payer row visibility on WorkspaceWorkflowsPage
MelvinBot 8de16ac
Fix typecheck errors in WorkspaceWorkflowsPayerRowTest
MelvinBot 8641865
Fix ESLint errors in WorkspaceWorkflowsPayerRowTest
MelvinBot ed119e8
Use negated reimbursementChoice check for Payer visibility
MelvinBot 1442a66
Remove redundant reimbursementChoice !== REIMBURSEMENT_NO check
MelvinBot 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
Some comments aren't visible on the classic Files Changed page.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,227 @@ | ||
| import {PortalProvider} from '@gorhom/portal'; | ||
| import {NavigationContainer} from '@react-navigation/native'; | ||
| import {act, render, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import {LocaleContextProvider} from '@components/LocaleContextProvider'; | ||
| import {ModalProvider} from '@components/Modal/Global/ModalContext'; | ||
| import OnyxListItemProvider from '@components/OnyxListItemProvider'; | ||
| import {CurrentReportIDContextProvider} from '@hooks/useCurrentReportID'; | ||
| import * as useResponsiveLayoutModule from '@hooks/useResponsiveLayout'; | ||
| import type ResponsiveLayoutResult from '@hooks/useResponsiveLayout/types'; | ||
| import createPlatformStackNavigator from '@libs/Navigation/PlatformStackNavigation/createPlatformStackNavigator'; | ||
| import type {WorkspaceSplitNavigatorParamList} from '@navigation/types'; | ||
| import WorkspaceWorkflowsPage from '@pages/workspace/workflows/WorkspaceWorkflowsPage'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import SCREENS from '@src/SCREENS'; | ||
| import type {BankAccountList, Policy} from '@src/types/onyx'; | ||
| import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
| import * as TestHelper from '../utils/TestHelper'; | ||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| jest.mock('@src/components/ConfirmedRoute.tsx'); | ||
|
|
||
| jest.mock('react-native-render-html', () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const {View: MockView} = require('react-native'); | ||
| return { | ||
| RenderHTMLConfigProvider: ({children}: {children: React.ReactNode}) => children, | ||
| RenderHTMLSource: () => <MockView />, | ||
| }; | ||
| }); | ||
|
|
||
| jest.mock('@components/Modal/ReanimatedModal', () => { | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const {useEffect, useRef}: {useEffect: typeof React.useEffect; useRef: typeof React.useRef} = require('react'); | ||
|
|
||
| return function MockReanimatedModal({isVisible, onModalHide, children}: {isVisible: boolean; onModalHide?: () => void; children: React.ReactNode}) { | ||
| const wasVisible = useRef<boolean>(isVisible); | ||
|
|
||
| useEffect(() => { | ||
| if (wasVisible.current && !isVisible) { | ||
| onModalHide?.(); | ||
| } | ||
| wasVisible.current = isVisible; | ||
| }, [isVisible, onModalHide]); | ||
|
|
||
| if (!isVisible) { | ||
| return null; | ||
| } | ||
|
|
||
| return children as React.ReactElement; | ||
| }; | ||
| }); | ||
|
|
||
| TestHelper.setupGlobalFetchMock(); | ||
|
|
||
| const POLICY_ID = 'workflows-payer-test'; | ||
|
|
||
| const Stack = createPlatformStackNavigator<WorkspaceSplitNavigatorParamList>(); | ||
|
|
||
| const buildPolicy = (overrides: Partial<Policy> = {}): Policy => | ||
| ({ | ||
| ...LHNTestUtils.getFakePolicy(POLICY_ID), | ||
| type: CONST.POLICY.TYPE.CORPORATE, | ||
| role: CONST.POLICY.ROLE.ADMIN, | ||
| outputCurrency: 'USD', | ||
| areWorkflowsEnabled: true, | ||
| ...overrides, | ||
| }) as Policy; | ||
|
|
||
| const renderPage = () => | ||
| render( | ||
| <ComposeProviders components={[OnyxListItemProvider, LocaleContextProvider, CurrentReportIDContextProvider]}> | ||
| <PortalProvider> | ||
| <ModalProvider> | ||
| <NavigationContainer> | ||
| <Stack.Navigator initialRouteName={SCREENS.WORKSPACE.WORKFLOWS}> | ||
| <Stack.Screen | ||
| name={SCREENS.WORKSPACE.WORKFLOWS} | ||
| component={WorkspaceWorkflowsPage} | ||
| initialParams={{policyID: POLICY_ID}} | ||
| /> | ||
| </Stack.Navigator> | ||
| </NavigationContainer> | ||
| </ModalProvider> | ||
| </PortalProvider> | ||
| </ComposeProviders>, | ||
| ); | ||
|
|
||
| describe('WorkspaceWorkflowsPage - Payer row visibility', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await act(async () => { | ||
| await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, CONST.LOCALES.EN); | ||
| }); | ||
| jest.spyOn(useResponsiveLayoutModule, 'default').mockReturnValue({ | ||
| isSmallScreenWidth: false, | ||
| shouldUseNarrowLayout: false, | ||
| } as ResponsiveLayoutResult); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => { | ||
| await Onyx.clear(); | ||
| }); | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('shows the Payer row when reimbursementChoice is REIMBURSEMENT_YES and a bank account exists', async () => { | ||
| await TestHelper.signInWithTestUser(); | ||
| await act(async () => { | ||
| await Onyx.merge( | ||
| `${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, | ||
| buildPolicy({ | ||
| reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES, | ||
| achAccount: { | ||
| reimburser: 'test@user.com', | ||
| bankAccountID: 123456, | ||
| accountNumber: '1234567890', | ||
| routingNumber: '011000015', | ||
| bankName: 'Test Bank', | ||
| addressName: 'Test Address', | ||
| state: CONST.BANK_ACCOUNT.STATE.OPEN, | ||
| }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| renderPage(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(screen.getByText(TestHelper.translateLocal('workflowsPayerPage.payer'))).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('hides the Payer row when reimbursementChoice is REIMBURSEMENT_MANUAL', async () => { | ||
| await TestHelper.signInWithTestUser(); | ||
| await act(async () => { | ||
| await Onyx.merge( | ||
| `${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, | ||
| buildPolicy({ | ||
| reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL, | ||
| achAccount: { | ||
| reimburser: 'test@user.com', | ||
| bankAccountID: 123456, | ||
| accountNumber: '1234567890', | ||
| routingNumber: '011000015', | ||
| bankName: 'Test Bank', | ||
| addressName: 'Test Address', | ||
| state: CONST.BANK_ACCOUNT.STATE.OPEN, | ||
| }, | ||
| }), | ||
| ); | ||
|
Comment on lines
+140
to
+157
|
||
| }); | ||
|
|
||
| renderPage(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(screen.queryByText(TestHelper.translateLocal('workflowsPayerPage.payer'))).not.toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('shows the Payer row when reimbursementChoice is undefined (legacy workspaces)', async () => { | ||
| await TestHelper.signInWithTestUser(); | ||
| await act(async () => { | ||
| await Onyx.merge( | ||
| `${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, | ||
| buildPolicy({ | ||
| reimbursementChoice: undefined, | ||
| achAccount: { | ||
| reimburser: 'test@user.com', | ||
| bankAccountID: 123456, | ||
| accountNumber: '1234567890', | ||
| routingNumber: '011000015', | ||
| bankName: 'Test Bank', | ||
| addressName: 'Test Address', | ||
| state: CONST.BANK_ACCOUNT.STATE.OPEN, | ||
| }, | ||
| }), | ||
| ); | ||
| }); | ||
|
|
||
| renderPage(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(screen.getByText(TestHelper.translateLocal('workflowsPayerPage.payer'))).toBeOnTheScreen(); | ||
| }); | ||
|
|
||
| it('shows the Payer row during partial bank setup when reimbursementChoice is REIMBURSEMENT_YES', async () => { | ||
| await TestHelper.signInWithTestUser(); | ||
|
|
||
| const bankAccountID = 123456; | ||
| const bankAccountList: BankAccountList = { | ||
| [bankAccountID]: { | ||
| methodID: bankAccountID, | ||
| bankCurrency: 'USD', | ||
| bankCountry: 'US', | ||
| accountData: { | ||
| additionalData: { | ||
| policyID: POLICY_ID, | ||
| bankName: CONST.BANK_NAMES.GENERIC_BANK, | ||
| }, | ||
| addressName: 'Test Address', | ||
| state: CONST.BANK_ACCOUNT.STATE.SETUP, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| await act(async () => { | ||
| await Onyx.merge( | ||
| `${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, | ||
| buildPolicy({ | ||
| reimbursementChoice: CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES, | ||
| }), | ||
| ); | ||
| await Onyx.set(ONYXKEYS.BANK_ACCOUNT_LIST, bankAccountList); | ||
| }); | ||
|
|
||
| renderPage(); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(screen.getByText(TestHelper.translateLocal('workflowsPayerPage.payer'))).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❌ CONSISTENCY-3 (docs)
The check
policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_NOon this line is redundant.shouldShowBankAccount(defined on line 304) already includes this exact condition:If
shouldShowBankAccountistrue, thenreimbursementChoiceis guaranteed to not beREIMBURSEMENT_NO. Remove this redundant condition:Reviewed at: ed119e8 | Please rate this suggestion with 👍 or 👎 to help us improve! Reactions are used to monitor reviewer efficiency.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good finding. @MelvinBot address #90538 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch — removed the redundant != REIMBURSEMENT_NO check since shouldShowBankAccount already guarantees that. Pushed in 1442a66.