Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/libs/actions/Report/SuggestedFollowup.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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,
Expand Down
32 changes: 32 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '<p>Here is help</p><followup-list><followup><followup-text>How do I set up QuickBooks?</followup-text></followup></followup-list>',
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<string, unknown>).event === 'followup_clicked';
});
expect(telemetryCall).toBeDefined();

logInfoSpy.mockRestore();
});
});

// Shared test constants for leave functions
Expand Down
Loading