Repository navigation
Hide redundant Reimbursable rows; show "· Non-reimbursable" on Amount #90411
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
Merged
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import type * as NativeNavigation from '@react-navigation/native'; | ||
| import {act, render, screen, waitFor} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import ComposeProviders from '@components/ComposeProviders'; | ||
| import OnyxListItemProvider from '@components/OnyxListItemProvider'; | ||
| import MoneyReportView from '@components/ReportActionItem/MoneyReportView'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import type * as OnyxTypes from '@src/types/onyx'; | ||
| import * as LHNTestUtils from '../utils/LHNTestUtils'; | ||
| import * as TestHelper from '../utils/TestHelper'; | ||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| jest.mock('@hooks/useLocalize', () => | ||
| jest.fn(() => ({ | ||
| translate: jest.fn((key: string) => key), | ||
| numberFormat: jest.fn((num: number) => num.toString()), | ||
| toLocaleDigit: jest.fn((digit: string) => digit), | ||
| })), | ||
| ); | ||
|
|
||
| jest.mock('@react-navigation/native', () => ({ | ||
| ...((): typeof NativeNavigation => jest.requireActual('@react-navigation/native'))(), | ||
| useNavigation: jest.fn(() => ({navigate: jest.fn(), addListener: jest.fn(() => jest.fn())})), | ||
| useIsFocused: jest.fn(() => true), | ||
| useRoute: jest.fn(() => ({key: '', name: '', params: {reportID: '1'}})), | ||
| })); | ||
|
|
||
| jest.mock('@pages/inbox/report/AnimatedEmptyStateBackground', () => { | ||
| const RN = jest.requireActual<Record<string, React.ComponentType<{testID?: string}>>>('react-native'); | ||
| return () => <RN.View testID="animated-bg" />; | ||
| }); | ||
|
|
||
| TestHelper.setupGlobalFetchMock(); | ||
|
|
||
| const policyID = 'policy_mrv_breakdown'; | ||
| const reportID = 'report_mrv_breakdown'; | ||
|
|
||
| const buildExpenseReport = (overrides: Partial<OnyxTypes.Report> = {}): OnyxTypes.Report => ({ | ||
| ...LHNTestUtils.getFakeReport([1, 2]), | ||
| reportID, | ||
| type: CONST.REPORT.TYPE.EXPENSE, | ||
| policyID, | ||
| currency: CONST.CURRENCY.USD, | ||
| total: 0, | ||
| ...overrides, | ||
| }); | ||
|
|
||
| const buildTransaction = (id: string, amount: number, reimbursable: boolean | undefined): OnyxTypes.Transaction => | ||
| ({ | ||
| transactionID: id, | ||
| reportID, | ||
| amount, | ||
| currency: CONST.CURRENCY.USD, | ||
| created: '2025-06-01', | ||
| merchant: 'Merchant', | ||
| comment: {}, | ||
| reimbursable, | ||
| }) as OnyxTypes.Transaction; | ||
|
|
||
| const seedReportAndTransactions = async (transactions: OnyxTypes.Transaction[], reportOverrides: Partial<OnyxTypes.Report> = {}) => { | ||
| await act(async () => { | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { | ||
| id: policyID, | ||
| type: CONST.POLICY.TYPE.TEAM, | ||
| role: CONST.POLICY.ROLE.ADMIN, | ||
| name: 'Policy', | ||
| outputCurrency: CONST.CURRENCY.USD, | ||
| }); | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${reportID}`, buildExpenseReport(reportOverrides)); | ||
| for (const transaction of transactions) { | ||
| await Onyx.merge(`${ONYXKEYS.COLLECTION.TRANSACTION}${transaction.transactionID}`, transaction); | ||
| } | ||
| }); | ||
| await waitForBatchedUpdatesWithAct(); | ||
| }; | ||
|
|
||
| const renderMoneyReportView = (report: OnyxTypes.Report) => | ||
| render( | ||
| <ComposeProviders components={[OnyxListItemProvider]}> | ||
| <MoneyReportView | ||
| report={report} | ||
| policy={undefined} | ||
| shouldHideThreadDividerLine={false} | ||
| shouldShowAnimatedBackground={false} | ||
| /> | ||
| </ComposeProviders>, | ||
| ); | ||
|
|
||
| describe('MoneyReportView reimbursable/non-reimbursable breakdown rows', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS, evictableKeys: [ONYXKEYS.COLLECTION.REPORT_ACTIONS]}); | ||
| }); | ||
|
|
||
| afterEach(async () => { | ||
| await act(async () => { | ||
| await Onyx.clear(); | ||
| }); | ||
| }); | ||
|
|
||
| it('hides both breakdown rows for a single non-reimbursable expense', async () => { | ||
| const transactions = [buildTransaction('t1', 5000, false)]; | ||
| await seedReportAndTransactions(transactions, {nonReimbursableTotal: -5000, unheldNonReimbursableTotal: -5000}); | ||
|
|
||
| renderMoneyReportView(buildExpenseReport({nonReimbursableTotal: -5000, unheldNonReimbursableTotal: -5000})); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.queryByText('cardTransactions.outOfPocket')).not.toBeOnTheScreen(); | ||
| expect(screen.queryByText('cardTransactions.companySpend')).not.toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
|
|
||
| it('shows both breakdown rows when reimbursable and non-reimbursable transactions coexist', async () => { | ||
| const transactions = [buildTransaction('t1', 5000, true), buildTransaction('t2', 3000, false)]; | ||
| await seedReportAndTransactions(transactions, {nonReimbursableTotal: -3000, unheldNonReimbursableTotal: -3000, unheldTotal: -8000, total: -8000}); | ||
|
|
||
| renderMoneyReportView(buildExpenseReport({nonReimbursableTotal: -3000, unheldNonReimbursableTotal: -3000, unheldTotal: -8000, total: -8000})); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('cardTransactions.outOfPocket')).toBeOnTheScreen(); | ||
| expect(screen.getByText('cardTransactions.companySpend')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
|
|
||
| it('still shows both breakdown rows when reimbursable expenses + credits net to zero alongside non-reimbursable spend', async () => { | ||
| const transactions = [buildTransaction('t1', 5000, true), buildTransaction('t2', -5000, true), buildTransaction('t3', 3000, false)]; | ||
| await seedReportAndTransactions(transactions, {nonReimbursableTotal: -3000, unheldNonReimbursableTotal: -3000, unheldTotal: -3000, total: -3000}); | ||
|
|
||
| renderMoneyReportView(buildExpenseReport({nonReimbursableTotal: -3000, unheldNonReimbursableTotal: -3000, unheldTotal: -3000, total: -3000})); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| await waitFor(() => { | ||
| expect(screen.getByText('cardTransactions.outOfPocket')).toBeOnTheScreen(); | ||
| expect(screen.getByText('cardTransactions.companySpend')).toBeOnTheScreen(); | ||
| }); | ||
| }); | ||
| }); |
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
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.
We should apply this to all money requests, not just single requests, to maintain consistency. Addressed this in #101587