diff --git a/src/libs/actions/Report/SuggestedFollowup.ts b/src/libs/actions/Report/SuggestedFollowup.ts index cb6fe1c26948..c791d522c59f 100644 --- a/src/libs/actions/Report/SuggestedFollowup.ts +++ b/src/libs/actions/Report/SuggestedFollowup.ts @@ -1,5 +1,6 @@ import type {OnyxEntry} from 'react-native-onyx'; import Onyx from 'react-native-onyx'; +import Log from '@libs/Log'; import {rand64} from '@libs/NumberUtils'; import type {Followup} from '@libs/ReportActionFollowupUtils'; import type {Ancestor, OptimisticReportAction} from '@libs/ReportUtils'; @@ -48,6 +49,13 @@ function resolveSuggestedFollowup( return; } + Log.info('[Followups] followup clicked', false, { + event: 'followup_clicked', + reportID, + reportActionID, + hasPregeneratedResponse: !!selectedFollowup.response, + }); + // Optimistically update the HTML to mark followup-list as resolved Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, { [reportActionID]: resolvedAction, diff --git a/tests/actions/ReportTest.ts b/tests/actions/ReportTest.ts index 60d241f0880e..9b2ecb5c06ee 100644 --- a/tests/actions/ReportTest.ts +++ b/tests/actions/ReportTest.ts @@ -5280,6 +5280,38 @@ describe('actions/Report', () => { expect(pendingResponse?.reportAction.created).toBeDefined(); expect(new Date(pendingResponse?.reportAction.created ?? 0).getTime()).toBeGreaterThan(new Date(userCommentAction?.created ?? 0).getTime()); }); + + it('should emit Log.info followup_clicked telemetry when a suggested followup is resolved', async () => { + const logInfoSpy = jest.spyOn(Log, 'info'); + const reportAction = { + reportActionID: REPORT_ACTION_ID, + actorAccountID: CONST.ACCOUNT_ID.CONCIERGE, + message: [ + { + html: '

Here is help

How do I set up QuickBooks?', + text: 'Here is help', + type: CONST.REPORT.MESSAGE.TYPE.COMMENT, + }, + ], + } as OnyxTypes.ReportAction; + + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT}${REPORT_ID}`, report); + await Onyx.merge(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}`, { + [REPORT_ACTION_ID]: reportAction, + }); + await waitForBatchedUpdates(); + + resolveSuggestedFollowup(report, undefined, reportAction, {text: 'How do I set up QuickBooks?'}, CONST.DEFAULT_TIME_ZONE, TEST_USER_ACCOUNT_ID, TEST_USER_EMAIL); + await waitForBatchedUpdates(); + + const telemetryCall = logInfoSpy.mock.calls.find((args) => { + const params = args.at(2); + return !!params && typeof params === 'object' && !Array.isArray(params) && (params as Record).event === 'followup_clicked'; + }); + expect(telemetryCall).toBeDefined(); + + logInfoSpy.mockRestore(); + }); }); // Shared test constants for leave functions