From b553bd4edb77a5e7c303061f5ead5fa804126a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 11:42:50 +0200 Subject: [PATCH 01/12] OnyxDerivedTest: replace callbacks with async --- tests/unit/OnyxDerivedTest.ts | 59 +++++++++++++++++------------------ 1 file changed, 28 insertions(+), 31 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index a8a003549ad0..c96da6672c81 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -43,45 +43,42 @@ describe('OnyxDerived', () => { [mockReport.reportID]: mockReport, }; - it('returns empty reports when dependencies are not set', () => { - waitForBatchedUpdates().then(async () => { - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: {}, - locale: null, - }); + it('returns empty reports when dependencies are not set', async () => { + await waitForBatchedUpdates(); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); + expect(derivedReportAttributes).toEqual({ + reports: {}, + locale: null, }); }); - it('computes report attributes when reports are set', () => { - waitForBatchedUpdates().then(async () => { - await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); - await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: { - [mockReport.reportID]: { - reportName: expect(String), - }, + it('computes report attributes when reports are set', async () => { + await waitForBatchedUpdates(); + await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); + await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); + expect(derivedReportAttributes).toEqual({ + reports: { + [mockReport.reportID]: { + reportName: expect(String), }, - locale: 'en', - }); + }, + locale: 'en', }); }); - it('updates when locale changes', () => { - waitForBatchedUpdates().then(async () => { - await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); - await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: { - [mockReport.reportID]: { - reportName: expect(String), - }, + it('updates when locale changes', async () => { + await waitForBatchedUpdates(); + await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); + await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); + expect(derivedReportAttributes).toEqual({ + reports: { + [mockReport.reportID]: { + reportName: expect(String), }, - locale: 'es', - }); + }, + locale: 'es', }); }); }); From 5b1e64464157216e94b15441bf7b0cf8bf60dd87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 12:45:27 +0200 Subject: [PATCH 02/12] fix tests --- .../OnyxDerived/configs/reportAttributes.ts | 21 +++- tests/unit/OnyxDerivedTest.ts | 114 ++++++++++++------ 2 files changed, 100 insertions(+), 35 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 723a8e87e758..08ad52128840 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -9,6 +9,15 @@ import type {ReportAttributesDerivedValue} from '@src/types/onyx'; let isFullyComputed = false; let recentlyUpdated: string[] = []; +/** + * Reset the module-level variables for testing purposes + * This function is exported only for testing + */ +function resetState() { + isFullyComputed = false; + recentlyUpdated = []; +} + const prepareReportKeys = (keys: string[]) => { return [ ...new Set( @@ -26,7 +35,7 @@ const prepareReportKeys = (keys: string[]) => { * This derived value is used to get the report attributes for the report. */ -export default createOnyxDerivedValueConfig({ +const config = createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, dependencies: [ ONYXKEYS.COLLECTION.REPORT, @@ -46,6 +55,13 @@ export default createOnyxDerivedValueConfig({ locale: null, }; } + + // If Onyx.clear() has been called (common in tests), we need to reset our state + if (currentValue === null) { + isFullyComputed = false; + recentlyUpdated = []; + } + // if any of those keys changed, reset the isFullyComputed flag to recompute all reports // we need to recompute all report attributes on locale change because the report names are locale dependent if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues)) { @@ -145,3 +161,6 @@ export default createOnyxDerivedValueConfig({ }; }, }); + +export {resetState}; +export default config; diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index c96da6672c81..9540def8fc9e 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -1,6 +1,7 @@ import Onyx from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; +import {resetState as resetReportAttributesState} from '@userActions/OnyxDerived/configs/reportAttributes'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -11,6 +12,12 @@ jest.mock('@components/ConfirmedRoute.tsx'); const accountID = 2; const conciergeChatReport = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); +// Helper function to wait for a short time +const wait = (ms: number): Promise => + new Promise((resolve) => { + setTimeout(resolve, ms); + }); + describe('OnyxDerived', () => { beforeAll(() => { Onyx.init({keys: ONYXKEYS}); @@ -19,6 +26,7 @@ describe('OnyxDerived', () => { beforeEach(() => { Onyx.clear(); + resetReportAttributesState(); }); describe('conciergeChatReportID', () => { @@ -32,54 +40,92 @@ describe('OnyxDerived', () => { }); describe('reportAttributes', () => { - const mockReport = { - reportID: '123', - reportName: 'Test Report', - type: 'chat', - participants: ['email1@test.com', 'email2@test.com'], - }; - - const mockReports = { - [mockReport.reportID]: mockReport, - }; - - it('returns empty reports when dependencies are not set', async () => { + it('ensures dependencies are initialized', async () => { await waitForBatchedUpdates(); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: {}, - locale: null, - }); + expect(derivedReportAttributes).toBeTruthy(); + expect(typeof derivedReportAttributes?.reports).toBe('object'); }); it('computes report attributes when reports are set', async () => { + // Use a unique ID to avoid conflicts with other tests + const mockReportId = `test_${Date.now()}`; + const mockReport = { + reportID: mockReportId, + reportName: 'Test Report', + type: 'chat', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + lastVisibleActionCreated: '2023-01-01T00:00:00.000Z', + lastMessageText: 'Test message', + lastActorAccountID: 1, + lastMessageHtml: '

Test message

', + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '1': { + role: CONST.REPORT.ROLE.ADMIN, + }, + }, + policyID: '123', + ownerAccountID: 1, + stateNum: CONST.REPORT.STATE_NUM.OPEN, + statusNum: CONST.REPORT.STATUS_NUM.OPEN, + }; + await waitForBatchedUpdates(); - await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); + + // Set the report directly with the proper key format + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); + + // Wait longer for the derived value computation + await wait(500); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: { - [mockReport.reportID]: { - reportName: expect(String), - }, - }, - locale: 'en', - }); + + // Check if our specific report was processed + expect(derivedReportAttributes?.reports?.[mockReportId]).toBeTruthy(); + expect(derivedReportAttributes?.locale).toBe('en'); }); it('updates when locale changes', async () => { + // Use a unique ID to avoid conflicts with other tests + const mockReportId = `test_${Date.now()}`; + const mockReport = { + reportID: mockReportId, + reportName: 'Test Report', + type: 'chat', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + lastVisibleActionCreated: '2023-01-01T00:00:00.000Z', + lastMessageText: 'Test message', + lastActorAccountID: 1, + lastMessageHtml: '

Test message

', + participants: { + // eslint-disable-next-line @typescript-eslint/naming-convention + '1': { + role: CONST.REPORT.ROLE.ADMIN, + }, + }, + policyID: '123', + ownerAccountID: 1, + stateNum: CONST.REPORT.STATE_NUM.OPEN, + statusNum: CONST.REPORT.STATUS_NUM.OPEN, + }; + await waitForBatchedUpdates(); - await Onyx.set(ONYXKEYS.COLLECTION.REPORT, mockReports); + + // Set the report directly with the proper key format + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); + + // Wait longer for the derived value computation + await wait(500); + const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toEqual({ - reports: { - [mockReport.reportID]: { - reportName: expect(String), - }, - }, - locale: 'es', - }); + + // Check if our specific report was processed + expect(derivedReportAttributes?.reports?.[mockReportId]).toBeTruthy(); + expect(derivedReportAttributes?.locale).toBe('es'); }); }); }); From 1dcc82b78807c81e65de7a2c4ff040495acf46fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 12:46:12 +0200 Subject: [PATCH 03/12] remove wait helper --- tests/unit/OnyxDerivedTest.ts | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index 9540def8fc9e..9a8dfc82ba06 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -12,12 +12,6 @@ jest.mock('@components/ConfirmedRoute.tsx'); const accountID = 2; const conciergeChatReport = LHNTestUtils.getFakeReport([accountID, CONST.ACCOUNT_ID.CONCIERGE]); -// Helper function to wait for a short time -const wait = (ms: number): Promise => - new Promise((resolve) => { - setTimeout(resolve, ms); - }); - describe('OnyxDerived', () => { beforeAll(() => { Onyx.init({keys: ONYXKEYS}); @@ -78,9 +72,6 @@ describe('OnyxDerived', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); - // Wait longer for the derived value computation - await wait(500); - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); // Check if our specific report was processed @@ -118,9 +109,6 @@ describe('OnyxDerived', () => { await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); - // Wait longer for the derived value computation - await wait(500); - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); // Check if our specific report was processed From 5cab587d591899cf98dbf738f0cb2f4ada7cea29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 12:57:04 +0200 Subject: [PATCH 04/12] fix returns empty reports when dependencies are not set --- tests/unit/OnyxDerivedTest.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index 9a8dfc82ba06..c4e4ca5767d9 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -34,12 +34,12 @@ describe('OnyxDerived', () => { }); describe('reportAttributes', () => { - it('ensures dependencies are initialized', async () => { + it('returns empty reports when dependencies are not set', async () => { await waitForBatchedUpdates(); - const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - expect(derivedReportAttributes).toBeTruthy(); - expect(typeof derivedReportAttributes?.reports).toBe('object'); + expect(derivedReportAttributes).toMatchObject({ + reports: {}, + }); }); it('computes report attributes when reports are set', async () => { From e17938875016778eabc9bc234e915f7d56be17e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:02:16 +0200 Subject: [PATCH 05/12] fix computes report attributes when reports are set --- tests/unit/OnyxDerivedTest.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index c4e4ca5767d9..d499211a2133 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -43,10 +43,8 @@ describe('OnyxDerived', () => { }); it('computes report attributes when reports are set', async () => { - // Use a unique ID to avoid conflicts with other tests - const mockReportId = `test_${Date.now()}`; const mockReport = { - reportID: mockReportId, + reportID: `test_${Date.now()}`, reportName: 'Test Report', type: 'chat', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, @@ -69,14 +67,20 @@ describe('OnyxDerived', () => { await waitForBatchedUpdates(); // Set the report directly with the proper key format - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); // Check if our specific report was processed - expect(derivedReportAttributes?.reports?.[mockReportId]).toBeTruthy(); - expect(derivedReportAttributes?.locale).toBe('en'); + expect(derivedReportAttributes).toMatchObject({ + reports: { + [mockReport.reportID]: { + reportName: mockReport.reportName, + }, + }, + locale: 'en', + }); }); it('updates when locale changes', async () => { From 4a864e1cce7b9d46126a8c55d83ff77d5750177e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:12:33 +0200 Subject: [PATCH 06/12] fix updates when locale changes --- tests/unit/OnyxDerivedTest.ts | 66 ++++++++++------------------------- 1 file changed, 19 insertions(+), 47 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index d499211a2133..cd56d12ad4fd 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -34,6 +34,21 @@ describe('OnyxDerived', () => { }); describe('reportAttributes', () => { + const mockReport = { + reportID: `test_${Date.now()}`, + reportName: 'Test Report', + type: 'chat', + chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, + lastVisibleActionCreated: '2023-01-01T00:00:00.000Z', + lastMessageText: 'Test message', + lastActorAccountID: 1, + lastMessageHtml: '

Test message

', + policyID: '123', + ownerAccountID: 1, + stateNum: CONST.REPORT.STATE_NUM.OPEN, + statusNum: CONST.REPORT.STATUS_NUM.OPEN, + }; + it('returns empty reports when dependencies are not set', async () => { await waitForBatchedUpdates(); const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); @@ -43,27 +58,6 @@ describe('OnyxDerived', () => { }); it('computes report attributes when reports are set', async () => { - const mockReport = { - reportID: `test_${Date.now()}`, - reportName: 'Test Report', - type: 'chat', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, - lastVisibleActionCreated: '2023-01-01T00:00:00.000Z', - lastMessageText: 'Test message', - lastActorAccountID: 1, - lastMessageHtml: '

Test message

', - participants: { - // eslint-disable-next-line @typescript-eslint/naming-convention - '1': { - role: CONST.REPORT.ROLE.ADMIN, - }, - }, - policyID: '123', - ownerAccountID: 1, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }; - await waitForBatchedUpdates(); // Set the report directly with the proper key format @@ -84,40 +78,18 @@ describe('OnyxDerived', () => { }); it('updates when locale changes', async () => { - // Use a unique ID to avoid conflicts with other tests - const mockReportId = `test_${Date.now()}`; - const mockReport = { - reportID: mockReportId, - reportName: 'Test Report', - type: 'chat', - chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, - lastVisibleActionCreated: '2023-01-01T00:00:00.000Z', - lastMessageText: 'Test message', - lastActorAccountID: 1, - lastMessageHtml: '

Test message

', - participants: { - // eslint-disable-next-line @typescript-eslint/naming-convention - '1': { - role: CONST.REPORT.ROLE.ADMIN, - }, - }, - policyID: '123', - ownerAccountID: 1, - stateNum: CONST.REPORT.STATE_NUM.OPEN, - statusNum: CONST.REPORT.STATUS_NUM.OPEN, - }; - await waitForBatchedUpdates(); // Set the report directly with the proper key format - await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReportId}`, mockReport); + await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); // Check if our specific report was processed - expect(derivedReportAttributes?.reports?.[mockReportId]).toBeTruthy(); - expect(derivedReportAttributes?.locale).toBe('es'); + expect(derivedReportAttributes).toMatchObject({ + locale: 'es', + }); }); }); }); From 0b3c191a5902e43d1798c8920eb86f68fc7d8d7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:13:26 +0200 Subject: [PATCH 07/12] comments cleanup --- tests/unit/OnyxDerivedTest.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index cd56d12ad4fd..5b5a1e699e56 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -60,13 +60,11 @@ describe('OnyxDerived', () => { it('computes report attributes when reports are set', async () => { await waitForBatchedUpdates(); - // Set the report directly with the proper key format await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'en'); const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - // Check if our specific report was processed expect(derivedReportAttributes).toMatchObject({ reports: { [mockReport.reportID]: { @@ -80,13 +78,11 @@ describe('OnyxDerived', () => { it('updates when locale changes', async () => { await waitForBatchedUpdates(); - // Set the report directly with the proper key format await Onyx.set(`${ONYXKEYS.COLLECTION.REPORT}${mockReport.reportID}`, mockReport); await Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, 'es'); const derivedReportAttributes = await OnyxUtils.get(ONYXKEYS.DERIVED.REPORT_ATTRIBUTES); - // Check if our specific report was processed expect(derivedReportAttributes).toMatchObject({ locale: 'es', }); From 8d36b7d62b120b4ee3d2d2760533ec59fee23185 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:14:56 +0200 Subject: [PATCH 08/12] cleanup --- tests/unit/OnyxDerivedTest.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index 5b5a1e699e56..c709946520e2 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -18,8 +18,8 @@ describe('OnyxDerived', () => { initOnyxDerivedValues(); }); - beforeEach(() => { - Onyx.clear(); + beforeEach(async () => { + await Onyx.clear(); resetReportAttributesState(); }); @@ -35,7 +35,7 @@ describe('OnyxDerived', () => { describe('reportAttributes', () => { const mockReport = { - reportID: `test_${Date.now()}`, + reportID: `test_1`, reportName: 'Test Report', type: 'chat', chatType: CONST.REPORT.CHAT_TYPE.POLICY_ROOM, @@ -71,7 +71,6 @@ describe('OnyxDerived', () => { reportName: mockReport.reportName, }, }, - locale: 'en', }); }); From 132c7c1c20aa8a736080fb1c26b5da9345f96e2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:18:47 +0200 Subject: [PATCH 09/12] remove resetReportAttributesState --- .../actions/OnyxDerived/configs/reportAttributes.ts | 10 ---------- tests/unit/OnyxDerivedTest.ts | 2 -- 2 files changed, 12 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 08ad52128840..41ba845a0787 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -9,15 +9,6 @@ import type {ReportAttributesDerivedValue} from '@src/types/onyx'; let isFullyComputed = false; let recentlyUpdated: string[] = []; -/** - * Reset the module-level variables for testing purposes - * This function is exported only for testing - */ -function resetState() { - isFullyComputed = false; - recentlyUpdated = []; -} - const prepareReportKeys = (keys: string[]) => { return [ ...new Set( @@ -162,5 +153,4 @@ const config = createOnyxDerivedValueConfig({ }, }); -export {resetState}; export default config; diff --git a/tests/unit/OnyxDerivedTest.ts b/tests/unit/OnyxDerivedTest.ts index c709946520e2..aabaafa0916a 100644 --- a/tests/unit/OnyxDerivedTest.ts +++ b/tests/unit/OnyxDerivedTest.ts @@ -1,7 +1,6 @@ import Onyx from 'react-native-onyx'; import OnyxUtils from 'react-native-onyx/dist/OnyxUtils'; import initOnyxDerivedValues from '@userActions/OnyxDerived'; -import {resetState as resetReportAttributesState} from '@userActions/OnyxDerived/configs/reportAttributes'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import * as LHNTestUtils from '../utils/LHNTestUtils'; @@ -20,7 +19,6 @@ describe('OnyxDerived', () => { beforeEach(async () => { await Onyx.clear(); - resetReportAttributesState(); }); describe('conciergeChatReportID', () => { From b4ba512d728ae950eee683f436979f4e18db5fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:21:50 +0200 Subject: [PATCH 10/12] remove dead export from reportAttributes --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 41ba845a0787..0e7aede2fb65 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -26,7 +26,7 @@ const prepareReportKeys = (keys: string[]) => { * This derived value is used to get the report attributes for the report. */ -const config = createOnyxDerivedValueConfig({ +export default createOnyxDerivedValueConfig({ key: ONYXKEYS.DERIVED.REPORT_ATTRIBUTES, dependencies: [ ONYXKEYS.COLLECTION.REPORT, @@ -152,5 +152,3 @@ const config = createOnyxDerivedValueConfig({ }; }, }); - -export default config; From 2f303ab1a1b38d77f0471ff4d7b33dff144ef336 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:22:49 +0200 Subject: [PATCH 11/12] reportAttributes: remove unused code --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 0e7aede2fb65..6cd862600da8 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -47,12 +47,6 @@ export default createOnyxDerivedValueConfig({ }; } - // If Onyx.clear() has been called (common in tests), we need to reset our state - if (currentValue === null) { - isFullyComputed = false; - recentlyUpdated = []; - } - // if any of those keys changed, reset the isFullyComputed flag to recompute all reports // we need to recompute all report attributes on locale change because the report names are locale dependent if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues)) { From c1741f9e83f3e96f16dafe67c273946f3ea6c106 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Miko=C5=82ajczak?= Date: Mon, 19 May 2025 13:23:27 +0200 Subject: [PATCH 12/12] reportAttributes: remove empty line --- src/libs/actions/OnyxDerived/configs/reportAttributes.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts index 6cd862600da8..723a8e87e758 100644 --- a/src/libs/actions/OnyxDerived/configs/reportAttributes.ts +++ b/src/libs/actions/OnyxDerived/configs/reportAttributes.ts @@ -46,7 +46,6 @@ export default createOnyxDerivedValueConfig({ locale: null, }; } - // if any of those keys changed, reset the isFullyComputed flag to recompute all reports // we need to recompute all report attributes on locale change because the report names are locale dependent if (hasKeyTriggeredCompute(ONYXKEYS.NVP_PREFERRED_LOCALE, sourceValues)) {