Skip to content
Merged
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
78 changes: 77 additions & 1 deletion tests/unit/ReportNameUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import Onyx from 'react-native-onyx';
import {translate} from '@libs/Localize';
import {computeReportName, getGroupChatName, getPolicyExpenseChatName, getReportName as getSimpleReportName} from '@libs/ReportNameUtils';
import {
buildReportNameFromParticipantNames,
computeReportName,
getGroupChatName,
getInvoicePayerName,
getInvoicesChatName,
getPolicyExpenseChatName,
getReportName as getSimpleReportName,
} from '@libs/ReportNameUtils';
import CONST from '@src/CONST';
import IntlStore from '@src/languages/IntlStore';
import ONYXKEYS from '@src/ONYXKEYS';
Expand Down Expand Up @@ -320,6 +328,74 @@ describe('ReportNameUtils', () => {
});
});

describe('buildReportNameFromParticipantNames', () => {
test('Excludes current user and uses short names for multiple participants', () => {
const report = {
...createRegularChat(1000, [currentUserAccountID, 1, 2]),
};

const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails});
expect(name).toBe('Ragnar, floki@vikings.net');
});

test('Uses full name when only one participant remains after filtering current user', () => {
const report = {
...createRegularChat(1001, [currentUserAccountID, 1]),
};

const name = buildReportNameFromParticipantNames({report, personalDetailsList: participantsPersonalDetails});
expect(name).toBe('Ragnar Lothbrok');
});
});

describe('Invoice naming helpers', () => {
test('Invoice room uses policy name when current user is receiver', () => {
const receiverPolicy = {name: 'Personal Workspace'} as unknown as Policy;
const report: Report = {
reportID: 'invoice-chat-1',
invoiceReceiver: {type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, accountID: currentUserAccountID},
policyName: 'Personal Workspace',
};

const name = getInvoicesChatName({
report,
receiverPolicy,
personalDetails: participantsPersonalDetails,
});

expect(name).toBe('Personal Workspace');
});

test('Invoice room displays receiver name for other individuals', () => {
const receiverPolicy = {name: 'Vendor Workspace'} as unknown as Policy;
const report: Report = {
reportID: 'invoice-chat-2',
invoiceReceiver: {type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, accountID: 1},
policyName: 'Vendor Workspace',
};

const name = getInvoicesChatName({
report,
receiverPolicy,
personalDetails: participantsPersonalDetails,
});

const normalizedName = name?.replaceAll('\u00A0', ' ');
expect(normalizedName).toBe('Ragnar Lothbrok');
});

test('Invoice payer name falls back to provided personal details', () => {
const report: Report = {
reportID: 'invoice-chat-3',
invoiceReceiver: {type: CONST.REPORT.INVOICE_RECEIVER_TYPE.INDIVIDUAL, accountID: 1},
};
const name = getInvoicePayerName(report, undefined, null);

const normalizedName = name?.replaceAll('\u00A0', ' ');
expect(normalizedName).toBe('Ragnar Lothbrok');
});
});

describe('getPolicyExpenseChatName', () => {
it("returns owner's display name when available", () => {
const report = {
Expand Down
Loading