Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/libs/TransactionPreviewUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type {TranslationPaths} from '@src/languages/types';
import ROUTES from '@src/ROUTES';
import type * as OnyxTypes from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import {getCurrentUserAccountID} from './actions/Report';
import {abandonReviewDuplicateTransactions, setReviewDuplicatesKey} from './actions/Transaction';
import {convertToDisplayString} from './CurrencyUtils';
import DateUtils from './DateUtils';
Expand Down Expand Up @@ -324,8 +325,8 @@ function createTransactionPreviewConditionals({

// When there are no settled transactions in duplicates, show the "Keep this one" button
const shouldShowKeepButton = areThereDuplicates;
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0;

const participantAccountIDs = isMoneyRequestAction(action) && isBillSplit ? (getOriginalMessage(action)?.participantAccountIDs ?? []) : [];
const shouldShowSplitShare = isBillSplit && !!requestAmount && requestAmount > 0 && participantAccountIDs.includes(getCurrentUserAccountID());
/*
Show the merchant for IOUs and expenses only if:
- the merchant is not empty, is custom, or is not related to scanning smartscan;
Expand Down
45 changes: 45 additions & 0 deletions tests/unit/TransactionPreviewUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,13 @@ describe('TransactionPreviewUtils', () => {
});

describe('createTransactionPreviewConditionals', () => {
beforeAll(() => {
Onyx.merge(ONYXKEYS.SESSION, {accountID: 999});
});
afterAll(() => {
Onyx.clear([ONYXKEYS.SESSION]);
});

it('should determine RBR visibility according to violation and hold conditions', () => {
const functionArgs = {
...basicProps,
Expand Down Expand Up @@ -203,6 +210,15 @@ describe('TransactionPreviewUtils', () => {
transactionDetails: {
amount: 1,
},
action: {
...basicProps.action,
originalMessage: {
participantAccountIDs: [999],
amount: 100,
currency: 'USD',
type: CONST.REPORT.ACTIONS.TYPE.IOU,
},
},
};
const result = createTransactionPreviewConditionals(functionArgs);
expect(result.shouldShowSplitShare).toBeTruthy();
Expand Down Expand Up @@ -256,6 +272,35 @@ describe('TransactionPreviewUtils', () => {
const result = createTransactionPreviewConditionals(functionArgs);
expect(result.shouldShowDescription).toBeTruthy();
});

it('should show split share only if user is part of the split bill transaction', () => {
const functionArgs = {
...basicProps,
isBillSplit: true,
transactionDetails: {amount: 100},
action: {
...basicProps.action,
originalMessage: {
participantAccountIDs: [999],
amount: 100,
currency: 'USD',
type: CONST.REPORT.ACTIONS.TYPE.IOU,
},
},
};
const result = createTransactionPreviewConditionals(functionArgs);
expect(result.shouldShowSplitShare).toBeTruthy();
});

it('should not show split share if user is not a participant', () => {
const functionArgs = {
...basicProps,
isBillSplit: true,
transactionDetails: {amount: 100},
};
const result = createTransactionPreviewConditionals(functionArgs);
expect(result.shouldShowSplitShare).toBeFalsy();
});
});

describe('getViolationTranslatePath', () => {
Expand Down