From 6f25a7577f2013a374e93f5dec65bcc99bdbe814 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 29 Apr 2025 01:23:13 +0530 Subject: [PATCH 1/5] fix: Onboarding - Onboarding tasks in #admins room are grayed out in offline mode. Signed-off-by: krishna2323 --- src/libs/ReportUtils.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3aa5a6147df73..c856276076367 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9825,7 +9825,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, value: { - [taskReportAction.reportAction.reportActionID]: {pendingAction: null}, + [taskReportAction.reportAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, }, }, { @@ -9851,7 +9851,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, value: { - [taskCreatedAction.reportActionID]: {pendingAction: null}, + [taskCreatedAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, }, }, ); @@ -9861,7 +9861,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, value: { - [completedTaskReportAction.reportActionID]: {pendingAction: null}, + [completedTaskReportAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, }, }); } @@ -9919,7 +9919,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, value: { - [textCommentAction.reportActionID]: {pendingAction: null}, + [textCommentAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, }, }); } @@ -10107,7 +10107,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${targetChatReportID}`, value: { - [welcomeSignOffCommentAction.reportActionID]: {pendingAction: null}, + [welcomeSignOffCommentAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, }, }); From 1bc6d6826cf10253c6e1d8ba4c7385846111c8c5 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 29 Apr 2025 01:27:02 +0530 Subject: [PATCH 2/5] minor update. Signed-off-by: krishna2323 --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index c856276076367..8fd40009b4e08 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -9851,7 +9851,7 @@ function prepareOnboardingOnyxData( onyxMethod: Onyx.METHOD.MERGE, key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${currentTask.reportID}`, value: { - [taskCreatedAction.reportActionID]: {pendingAction: null, isOptimisticAction: null}, + [taskCreatedAction.reportActionID]: {pendingAction: null}, }, }, ); From 29c8e9787312a16f5f798474077362f69d806fcb Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Sat, 3 May 2025 15:18:02 +0530 Subject: [PATCH 3/5] add tests for 'completeOnboarding' api. Signed-off-by: krishna2323 --- tests/unit/onboardingApiTest.ts | 61 +++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 tests/unit/onboardingApiTest.ts diff --git a/tests/unit/onboardingApiTest.ts b/tests/unit/onboardingApiTest.ts new file mode 100644 index 0000000000000..824f5e880d80f --- /dev/null +++ b/tests/unit/onboardingApiTest.ts @@ -0,0 +1,61 @@ +/* eslint-disable @typescript-eslint/naming-convention */ +import Onyx from 'react-native-onyx'; +import type {OnyxEntry} from 'react-native-onyx'; +import CONST from '@src/CONST'; +import * as Report from '@src/libs/actions/Report'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type {ReportActions} from '@src/types/onyx/ReportAction'; +import * as TestHelper from '../utils/TestHelper'; +import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; + +const ESH_EMAIL = 'eshgupta1217@gmail.com'; +const ESH_ACCOUNT_ID = 1; + +describe('actions/Report', () => { + beforeAll(() => { + Onyx.init({ + keys: ONYXKEYS, + }); + }); + + beforeEach(() => { + global.fetch = TestHelper.getGlobalFetchMock(); + return Onyx.clear().then(waitForBatchedUpdates); + }); + + describe('completeOnboarding', () => { + it('should set "isOptimisticAction" to false/null for all actions in admins report after completing onboarding setup', async () => { + await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID}); + await waitForBatchedUpdates(); + + const adminsChatReportID = '7957055873634067'; + const onboardingPolicyID = 'A70D00C752416807'; + + Report.completeOnboarding({ + engagementChoice: 'newDotManageTeam', + onboardingMessage: CONST.ONBOARDING_MESSAGES.newDotManageTeam, + adminsChatReportID, + onboardingPolicyID, + companySize: '1-10', + userReportedIntegration: null, + }); + + await waitForBatchedUpdates(); + + const reportActions: OnyxEntry = await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`, + callback: (id) => { + Onyx.disconnect(connection); + resolve(id); + }, + }); + }); + expect(reportActions).not.toBeNull(); + expect(reportActions).not.toBeUndefined(); + Object.values(reportActions ?? {}).forEach((action) => { + expect(action.isOptimisticAction).toBeFalsy(); + }); + }); + }); +}); From 3c3e8ca71854a4831574a32ad04b5de9a5021f25 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Mon, 5 May 2025 10:10:17 +0530 Subject: [PATCH 4/5] add completeOnboarding in ReportTest.ts. Signed-off-by: krishna2323 --- tests/actions/ReportTest.ts | 42 +++++++++++++++++++++++ tests/unit/onboardingApiTest.ts | 61 --------------------------------- 2 files changed, 42 insertions(+), 61 deletions(-) delete mode 100644 tests/unit/onboardingApiTest.ts diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index e7c4271c14888..8ddbf7603c1e9 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -68,6 +68,7 @@ describe('actions/Report', () => { beforeEach(() => { HttpUtils.xhr = originalXHR; const promise = Onyx.clear().then(jest.useRealTimers); + if (getIsUsingFakeTimers()) { // flushing pending timers // Onyx.clear() promise is resolved in batch which happens after the current microtasks cycle @@ -1606,4 +1607,45 @@ describe('actions/Report', () => { expect(derivedConciergeChatReportID).toBe(conciergeChatReport2.reportID); }); }); + + describe('completeOnboarding', () => { + const TEST_USER_LOGIN = 'test@gmail.com'; + const TEST_USER_ACCOUNT_ID = 1; + global.fetch = TestHelper.getGlobalFetchMock(); + + it('should set "isOptimisticAction" to false/null for all actions in admins report after completing onboarding setup', async () => { + await Onyx.set(ONYXKEYS.SESSION, {email: TEST_USER_LOGIN, accountID: TEST_USER_ACCOUNT_ID}); + await waitForBatchedUpdates(); + + const adminsChatReportID = '7957055873634067'; + const onboardingPolicyID = 'A70D00C752416807'; + const engagementChoice = CONST.INTRO_CHOICES.MANAGE_TEAM; + + Report.completeOnboarding({ + engagementChoice, + onboardingMessage: CONST.ONBOARDING_MESSAGES.newDotManageTeam, + adminsChatReportID, + onboardingPolicyID, + companySize: '1-10', + userReportedIntegration: null, + }); + + await waitForBatchedUpdates(); + + const reportActions: OnyxEntry = await new Promise((resolve) => { + const connection = Onyx.connect({ + key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`, + callback: (id) => { + Onyx.disconnect(connection); + resolve(id); + }, + }); + }); + expect(reportActions).not.toBeNull(); + expect(reportActions).not.toBeUndefined(); + Object.values(reportActions ?? {}).forEach((action) => { + expect(action.isOptimisticAction).toBeFalsy(); + }); + }); + }); }); diff --git a/tests/unit/onboardingApiTest.ts b/tests/unit/onboardingApiTest.ts deleted file mode 100644 index 824f5e880d80f..0000000000000 --- a/tests/unit/onboardingApiTest.ts +++ /dev/null @@ -1,61 +0,0 @@ -/* eslint-disable @typescript-eslint/naming-convention */ -import Onyx from 'react-native-onyx'; -import type {OnyxEntry} from 'react-native-onyx'; -import CONST from '@src/CONST'; -import * as Report from '@src/libs/actions/Report'; -import ONYXKEYS from '@src/ONYXKEYS'; -import type {ReportActions} from '@src/types/onyx/ReportAction'; -import * as TestHelper from '../utils/TestHelper'; -import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; - -const ESH_EMAIL = 'eshgupta1217@gmail.com'; -const ESH_ACCOUNT_ID = 1; - -describe('actions/Report', () => { - beforeAll(() => { - Onyx.init({ - keys: ONYXKEYS, - }); - }); - - beforeEach(() => { - global.fetch = TestHelper.getGlobalFetchMock(); - return Onyx.clear().then(waitForBatchedUpdates); - }); - - describe('completeOnboarding', () => { - it('should set "isOptimisticAction" to false/null for all actions in admins report after completing onboarding setup', async () => { - await Onyx.set(ONYXKEYS.SESSION, {email: ESH_EMAIL, accountID: ESH_ACCOUNT_ID}); - await waitForBatchedUpdates(); - - const adminsChatReportID = '7957055873634067'; - const onboardingPolicyID = 'A70D00C752416807'; - - Report.completeOnboarding({ - engagementChoice: 'newDotManageTeam', - onboardingMessage: CONST.ONBOARDING_MESSAGES.newDotManageTeam, - adminsChatReportID, - onboardingPolicyID, - companySize: '1-10', - userReportedIntegration: null, - }); - - await waitForBatchedUpdates(); - - const reportActions: OnyxEntry = await new Promise((resolve) => { - const connection = Onyx.connect({ - key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${adminsChatReportID}`, - callback: (id) => { - Onyx.disconnect(connection); - resolve(id); - }, - }); - }); - expect(reportActions).not.toBeNull(); - expect(reportActions).not.toBeUndefined(); - Object.values(reportActions ?? {}).forEach((action) => { - expect(action.isOptimisticAction).toBeFalsy(); - }); - }); - }); -}); From 2ba53393eb62bcdfb4f2bca1f7a28a99f2e9480d Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Tue, 6 May 2025 12:35:49 +0530 Subject: [PATCH 5/5] minor update. Signed-off-by: krishna2323 --- tests/actions/ReportTest.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 8ddbf7603c1e9..c5ffd3b12eaa2 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -1623,10 +1623,10 @@ describe('actions/Report', () => { Report.completeOnboarding({ engagementChoice, - onboardingMessage: CONST.ONBOARDING_MESSAGES.newDotManageTeam, + onboardingMessage: CONST.ONBOARDING_MESSAGES[engagementChoice], adminsChatReportID, onboardingPolicyID, - companySize: '1-10', + companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO, userReportedIntegration: null, });