diff --git a/src/libs/actions/Report.ts b/src/libs/actions/Report.ts index 9e06930afa7c..cfb1c454a06f 100644 --- a/src/libs/actions/Report.ts +++ b/src/libs/actions/Report.ts @@ -4337,24 +4337,27 @@ function completeOnboarding({ // Only add the dismissed state of the test drive modal when the user is not redirected to oldDot, // because we don't want the modal to reappear when returning from oldDot. + // We should only set testDriveModalDismissed to false if it's not already true (i.e., if the modal hasn't been dismissed yet). if (!shouldSkipTestDriveModal && !(engagementChoice === CONST.ONBOARDING_CHOICES.MANAGE_TEAM && willRedirectToOldDotFromOnboarding)) { - optimisticData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.NVP_ONBOARDING, - value: {testDriveModalDismissed: false}, - }); + if (onboarding?.testDriveModalDismissed !== true) { + optimisticData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_ONBOARDING, + value: {testDriveModalDismissed: false}, + }); - successData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.NVP_ONBOARDING, - value: {testDriveModalDismissed: false}, - }); + successData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_ONBOARDING, + value: {testDriveModalDismissed: false}, + }); - failureData.push({ - onyxMethod: Onyx.METHOD.MERGE, - key: ONYXKEYS.NVP_ONBOARDING, - value: {testDriveModalDismissed: null}, - }); + failureData.push({ + onyxMethod: Onyx.METHOD.MERGE, + key: ONYXKEYS.NVP_ONBOARDING, + value: {testDriveModalDismissed: null}, + }); + } } API.write(WRITE_COMMANDS.COMPLETE_GUIDED_SETUP, parameters, {optimisticData, successData, failureData}); diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 88b4d946bd0f..fce1db6afa2f 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -2298,4 +2298,42 @@ describe('actions/Report', () => { expect(upperCaseRequest?.data?.searchInput).toBe(lowerCaseRequest?.data?.searchInput); }); }); + + it('should not overwrite testDriveModalDismissed when it is already true', async () => { + const TEST_USER_ACCOUNT_ID = 1; + const TEST_USER_LOGIN = 'test@test.com'; + + await Onyx.set(ONYXKEYS.SESSION, {email: TEST_USER_LOGIN, accountID: TEST_USER_ACCOUNT_ID}); + await Onyx.set(ONYXKEYS.NVP_ONBOARDING, {testDriveModalDismissed: true}); + await waitForBatchedUpdates(); + + const adminsChatReportID = '7957055873634067'; + const onboardingPolicyID = 'A70D00C752416807'; + const engagementChoice = CONST.INTRO_CHOICES.MANAGE_TEAM; + const {onboardingMessages} = getOnboardingMessages(); + + Report.completeOnboarding({ + engagementChoice, + onboardingMessage: onboardingMessages[engagementChoice], + adminsChatReportID, + onboardingPolicyID, + companySize: CONST.ONBOARDING_COMPANY_SIZE.MICRO, + userReportedIntegration: null, + }); + + await waitForBatchedUpdates(); + + const onboarding = await new Promise>((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.NVP_ONBOARDING, + callback: (data) => { + Onyx.disconnect(connection); + resolve(data); + }, + }); + }); + + // testDriveModalDismissed should remain true and not be overwritten to false + expect(onboarding?.testDriveModalDismissed).toBe(true); + }); });