From 6c3e7fbf0fd40a0ee17c5923ac865d37be83e294 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Wed, 15 Oct 2025 11:55:17 +0200 Subject: [PATCH 1/4] Temporarily remove rNVP dependency when checking if report names should be computed --- src/libs/OptimisticReportNames.ts | 32 +++++++++++++++++++++---- tests/unit/OptimisticReportNamesTest.ts | 3 ++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/libs/OptimisticReportNames.ts b/src/libs/OptimisticReportNames.ts index ef38240d27e0..dfedc371c888 100644 --- a/src/libs/OptimisticReportNames.ts +++ b/src/libs/OptimisticReportNames.ts @@ -11,16 +11,35 @@ import {compute, FORMULA_PART_TYPES, parse} from './Formula'; import Log from './Log'; import type {UpdateContext} from './OptimisticReportNamesConnectionManager'; import Permissions from './Permissions'; -import {isArchivedReport} from './ReportUtils'; +import {getTitleReportField, isArchivedReport} from './ReportUtils'; /** * Get the title field from report name value pairs */ +// eslint-disable-next-line @typescript-eslint/no-unused-vars -- this will be used in near future function getTitleFieldFromRNVP(reportID: string, context: UpdateContext) { const reportNameValuePairs = context.allReportNameValuePairs[`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`]; return reportNameValuePairs?.expensify_text_title; } +/** + * Temporary function to get the title field from a policy. Eventually we want to move this to report name value pairs. + * @param policyId + * @param context + */ +function getTitleFieldFromPolicy(policyId: string | undefined, context: UpdateContext) { + if (!policyId) { + return; + } + + const policy = context.allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${policyId}`]; + if (!policy || !policy.fieldList) { + return; + } + + return getTitleReportField(policy.fieldList); +} + /** * Get the object type from an Onyx key */ @@ -145,6 +164,7 @@ function getReportKey(reportID: string): OnyxKey { * Check if a report should have its name automatically computed */ function shouldComputeReportName(report: Report, context: UpdateContext): boolean { + console.log('morwa report', report); if (!report) { return false; } @@ -154,9 +174,10 @@ function shouldComputeReportName(report: Report, context: UpdateContext): boolea } // Only compute names for expense reports with policies that have title fields - // Check if the report has a title field with a formula in rNVP - const reportTitleField = getTitleFieldFromRNVP(report.reportID, context); - if (!reportTitleField?.defaultValue) { + // Check if the report has a title field with a formula in policy + const policyTitleField = getTitleFieldFromPolicy(report.policyID, context); + console.log('morwa policyTitleField', policyTitleField); + if (!policyTitleField?.defaultValue) { return false; } return true; @@ -194,7 +215,8 @@ function computeReportNameIfNeeded(report: Report | undefined, incomingUpdate: O return null; } - const titleField = getTitleFieldFromRNVP(targetReport.reportID, context); + const titleField = getTitleFieldFromPolicy(targetReport.policyID, context); + console.log('morwa titleField', titleField); // Quick check: see if the update might affect the report name const updateType = determineObjectTypeByKey(incomingUpdate.key); diff --git a/tests/unit/OptimisticReportNamesTest.ts b/tests/unit/OptimisticReportNamesTest.ts index 5a3d0ffe3144..ec7831961776 100644 --- a/tests/unit/OptimisticReportNamesTest.ts +++ b/tests/unit/OptimisticReportNamesTest.ts @@ -20,7 +20,8 @@ jest.mock('@libs/CurrencyUtils', () => ({ const mockReportUtils = ReportUtils as jest.Mocked; -describe('OptimisticReportNames', () => { +// Temporarily skip tests until rNVP check in optimistic report names is stabilized +describe.skip('OptimisticReportNames', () => { const mockPolicy = { id: 'policy1', } as unknown as Policy; From a0c4419f2dd62819ca9b0580dea9ef51f1e00ee9 Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Wed, 15 Oct 2025 12:04:44 +0200 Subject: [PATCH 2/4] Remove console statements --- src/libs/OptimisticReportNames.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libs/OptimisticReportNames.ts b/src/libs/OptimisticReportNames.ts index dfedc371c888..f630b6a68565 100644 --- a/src/libs/OptimisticReportNames.ts +++ b/src/libs/OptimisticReportNames.ts @@ -164,7 +164,6 @@ function getReportKey(reportID: string): OnyxKey { * Check if a report should have its name automatically computed */ function shouldComputeReportName(report: Report, context: UpdateContext): boolean { - console.log('morwa report', report); if (!report) { return false; } @@ -176,7 +175,6 @@ function shouldComputeReportName(report: Report, context: UpdateContext): boolea // Only compute names for expense reports with policies that have title fields // Check if the report has a title field with a formula in policy const policyTitleField = getTitleFieldFromPolicy(report.policyID, context); - console.log('morwa policyTitleField', policyTitleField); if (!policyTitleField?.defaultValue) { return false; } @@ -216,7 +214,6 @@ function computeReportNameIfNeeded(report: Report | undefined, incomingUpdate: O } const titleField = getTitleFieldFromPolicy(targetReport.policyID, context); - console.log('morwa titleField', titleField); // Quick check: see if the update might affect the report name const updateType = determineObjectTypeByKey(incomingUpdate.key); From de7d41db90eed8eb53f8e847b6ac54302f9eda1a Mon Sep 17 00:00:00 2001 From: Hubert Sosinski Date: Fri, 17 Oct 2025 09:00:12 +0200 Subject: [PATCH 3/4] Skip only failing tests --- tests/unit/OptimisticReportNamesTest.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tests/unit/OptimisticReportNamesTest.ts b/tests/unit/OptimisticReportNamesTest.ts index ec7831961776..ef32ac778406 100644 --- a/tests/unit/OptimisticReportNamesTest.ts +++ b/tests/unit/OptimisticReportNamesTest.ts @@ -21,7 +21,7 @@ jest.mock('@libs/CurrencyUtils', () => ({ const mockReportUtils = ReportUtils as jest.Mocked; // Temporarily skip tests until rNVP check in optimistic report names is stabilized -describe.skip('OptimisticReportNames', () => { +describe('OptimisticReportNames', () => { const mockPolicy = { id: 'policy1', } as unknown as Policy; @@ -66,7 +66,7 @@ describe.skip('OptimisticReportNames', () => { }); describe('shouldComputeReportName()', () => { - test('should return true for report with title field formula', () => { + test.skip('should return true for report with title field formula', () => { const result = shouldComputeReportName(mockReport, mockContext); expect(result).toBe(true); }); @@ -101,7 +101,7 @@ describe.skip('OptimisticReportNames', () => { }); describe('computeReportNameIfNeeded()', () => { - test('should compute name when report data changes', () => { + test.skip('should compute name when report data changes', () => { const update = { key: 'report_123' as OnyxKey, onyxMethod: Onyx.METHOD.MERGE, @@ -156,7 +156,7 @@ describe.skip('OptimisticReportNames', () => { }); }); - test('should handle existing report updates', () => { + test.skip('should handle existing report updates', () => { const updates = [ { key: 'report_123' as OnyxKey, @@ -170,7 +170,7 @@ describe.skip('OptimisticReportNames', () => { expect(result.at(1)?.value).toEqual({reportName: 'Expense Report - $250.00'}); }); - test('should handle policy updates affecting multiple reports', () => { + test.skip('should handle policy updates affecting multiple reports', () => { const contextWithMultipleReports = { ...mockContext, allReports: { @@ -258,7 +258,7 @@ describe.skip('OptimisticReportNames', () => { }); describe('Transaction Updates', () => { - test('should process transaction updates and trigger report name updates', () => { + test.skip('should process transaction updates and trigger report name updates', () => { const contextWithTransaction = { ...mockContext, allTransactions: { @@ -337,7 +337,7 @@ describe.skip('OptimisticReportNames', () => { expect(result).toBeUndefined(); }); - test('should handle transaction updates that rely on context lookup', () => { + test.skip('should handle transaction updates that rely on context lookup', () => { const contextWithTransaction = { ...mockContext, allTransactions: { @@ -370,7 +370,7 @@ describe.skip('OptimisticReportNames', () => { expect(result.at(1)?.key).toBe('report_123'); }); - test('should use optimistic transaction data in formula computation', () => { + test.skip('should use optimistic transaction data in formula computation', () => { const contextWithTransaction = { ...mockContext, allReportNameValuePairs: { From 3bf0fc8385674bcd472c7cb493418dbd6603971f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Str=C3=B3=C5=BC?= Date: Tue, 21 Oct 2025 11:15:23 +0200 Subject: [PATCH 4/4] feat: fix tests by adding policies --- tests/unit/OptimisticReportNamesTest.ts | 48 ++++++++++++++++++++----- 1 file changed, 39 insertions(+), 9 deletions(-) diff --git a/tests/unit/OptimisticReportNamesTest.ts b/tests/unit/OptimisticReportNamesTest.ts index ef32ac778406..8d6200f67a96 100644 --- a/tests/unit/OptimisticReportNamesTest.ts +++ b/tests/unit/OptimisticReportNamesTest.ts @@ -20,10 +20,15 @@ jest.mock('@libs/CurrencyUtils', () => ({ const mockReportUtils = ReportUtils as jest.Mocked; -// Temporarily skip tests until rNVP check in optimistic report names is stabilized describe('OptimisticReportNames', () => { const mockPolicy = { id: 'policy1', + fieldList: { + [CONST.REPORT_FIELD_TITLE_FIELD_ID]: { + fieldID: CONST.REPORT_FIELD_TITLE_FIELD_ID, + defaultValue: '{report:type} - {report:total}', + }, + }, } as unknown as Policy; const mockReport = { @@ -66,7 +71,7 @@ describe('OptimisticReportNames', () => { }); describe('shouldComputeReportName()', () => { - test.skip('should return true for report with title field formula', () => { + test('should return true for report with title field formula', () => { const result = shouldComputeReportName(mockReport, mockContext); expect(result).toBe(true); }); @@ -81,6 +86,7 @@ describe('OptimisticReportNames', () => { private_isArchived: '', }, }, + allPolicies: {}, }; const result = shouldComputeReportName(mockReport, context); expect(result).toBe(false); @@ -101,7 +107,7 @@ describe('OptimisticReportNames', () => { }); describe('computeReportNameIfNeeded()', () => { - test.skip('should compute name when report data changes', () => { + test('should compute name when report data changes', () => { const update = { key: 'report_123' as OnyxKey, onyxMethod: Onyx.METHOD.MERGE, @@ -132,7 +138,7 @@ describe('OptimisticReportNames', () => { }); describe('updateOptimisticReportNamesFromUpdates()', () => { - test.skip('should detect new report creation and add name update', () => { + test('should detect new report creation and add name update', () => { const updates = [ { key: 'report_456' as OnyxKey, @@ -156,7 +162,7 @@ describe('OptimisticReportNames', () => { }); }); - test.skip('should handle existing report updates', () => { + test('should handle existing report updates', () => { const updates = [ { key: 'report_123' as OnyxKey, @@ -170,7 +176,7 @@ describe('OptimisticReportNames', () => { expect(result.at(1)?.value).toEqual({reportName: 'Expense Report - $250.00'}); }); - test.skip('should handle policy updates affecting multiple reports', () => { + test('should handle policy updates affecting multiple reports', () => { const contextWithMultipleReports = { ...mockContext, allReports: { @@ -181,6 +187,18 @@ describe('OptimisticReportNames', () => { // eslint-disable-next-line @typescript-eslint/naming-convention report_789: {...mockReport, reportID: '789'}, }, + allPolicies: { + // eslint-disable-next-line @typescript-eslint/naming-convention + policy_policy1: { + id: 'policy1', + fieldList: { + [CONST.REPORT_FIELD_TITLE_FIELD_ID]: { + fieldID: CONST.REPORT_FIELD_TITLE_FIELD_ID, + defaultValue: 'Policy: {report:policyname}', + }, + }, + } as unknown as Policy, + }, allReportNameValuePairs: { // eslint-disable-next-line @typescript-eslint/naming-convention reportNameValuePairs_123: {private_isArchived: '', expensify_text_title: {defaultValue: 'Policy: {report:policyname}'}} as unknown as ReportNameValuePairs, @@ -258,7 +276,7 @@ describe('OptimisticReportNames', () => { }); describe('Transaction Updates', () => { - test.skip('should process transaction updates and trigger report name updates', () => { + test('should process transaction updates and trigger report name updates', () => { const contextWithTransaction = { ...mockContext, allTransactions: { @@ -337,7 +355,7 @@ describe('OptimisticReportNames', () => { expect(result).toBeUndefined(); }); - test.skip('should handle transaction updates that rely on context lookup', () => { + test('should handle transaction updates that rely on context lookup', () => { const contextWithTransaction = { ...mockContext, allTransactions: { @@ -370,7 +388,7 @@ describe('OptimisticReportNames', () => { expect(result.at(1)?.key).toBe('report_123'); }); - test.skip('should use optimistic transaction data in formula computation', () => { + test('should use optimistic transaction data in formula computation', () => { const contextWithTransaction = { ...mockContext, allReportNameValuePairs: { @@ -382,6 +400,18 @@ describe('OptimisticReportNames', () => { }, } as unknown as ReportNameValuePairs, }, + allPolicies: { + // eslint-disable-next-line @typescript-eslint/naming-convention + policy_policy1: { + id: 'policy1', + fieldList: { + [CONST.REPORT_FIELD_TITLE_FIELD_ID]: { + fieldID: CONST.REPORT_FIELD_TITLE_FIELD_ID, + defaultValue: 'Report from {report:startdate}', + }, + }, + } as unknown as Policy, + }, allTransactions: { // eslint-disable-next-line @typescript-eslint/naming-convention transactions_formula123: {