Skip to content
Draft
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
2 changes: 1 addition & 1 deletion src/libs/WorkspaceReportFieldUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ function hasFormulaPartsInInitialValue(initialValue?: string): boolean {
* Checks if a report field name already exists in the policy's field list (case-insensitive).
*/
function isReportFieldNameExisting(fieldList: Record<string, PolicyReportField> | undefined, fieldName: string): boolean {
return Object.values(fieldList ?? {}).some((reportField) => reportField.name.toLowerCase() === fieldName.toLowerCase());
return Object.entries(fieldList ?? {}).some(([key, reportField]) => key !== CONST.POLICY.FIELDS.FIELD_LIST_TITLE && reportField.name.toLowerCase() === fieldName.toLowerCase());
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/unit/WorkspaceReportFieldUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {getUnsupportedReportFieldFormulaParts, hasFormulaPartsInInitialValue, isReportFieldNameExisting} from '@libs/WorkspaceReportFieldUtils';
import CONST from '@src/CONST';
import type {PolicyReportField} from '@src/types/onyx/Policy';

describe('WorkspaceReportFieldUtils.hasFormulaPartsInInitialValue', () => {
Expand Down Expand Up @@ -100,4 +101,16 @@ describe('WorkspaceReportFieldUtils.isReportFieldNameExisting', () => {
expect(isReportFieldNameExisting(fieldList, 'FIELD1')).toBe(true);
expect(isReportFieldNameExisting(fieldList, 'field1')).toBe(true);
});

it('should ignore the default title field when checking for duplicates', () => {
const fieldListWithTitle: Record<string, PolicyReportField> = {
[CONST.POLICY.FIELDS.FIELD_LIST_TITLE]: {name: 'title', type: 'text'} as PolicyReportField,
field1: {name: 'Field1', type: 'text'} as PolicyReportField,
};

expect(isReportFieldNameExisting(fieldListWithTitle, 'title')).toBe(false);
expect(isReportFieldNameExisting(fieldListWithTitle, 'Title')).toBe(false);
expect(isReportFieldNameExisting(fieldListWithTitle, 'TITLE')).toBe(false);
expect(isReportFieldNameExisting(fieldListWithTitle, 'Field1')).toBe(true);
});
});
Loading