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
5 changes: 4 additions & 1 deletion src/libs/actions/Report/SuggestedFollowup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ function resolveSuggestedFollowup(
},
});

// Use the full delay as createdOffset so the Concierge response timestamp is
// strictly after the user's comment — a 1ms offset was not enough to guarantee
// correct sort order when both actions are queued to Onyx near-simultaneously.
const optimisticConciergeAction = buildOptimisticAddCommentReportAction({
text: selectedFollowup.response,
actorAccountID: CONST.ACCOUNT_ID.CONCIERGE,
createdOffset: 1,
createdOffset: CONCIERGE_RESPONSE_DELAY_MS,

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In reality, any value ≥1000ms would work, but using this one since it's the delay we use to post the optimistic Concierge response

reportActionID: optimisticConciergeReportActionID,
reportID,
isHTML: true,
Expand Down
47 changes: 47 additions & 0 deletions tests/actions/ReportTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4953,6 +4953,53 @@ describe('actions/Report', () => {
const typingStatus = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_USER_IS_TYPING}${REPORT_ID}` as const);
expect(typingStatus?.[CONST.ACCOUNT_ID.CONCIERGE]).toBe(true);
});

it('should create Concierge response with timestamp strictly after the user comment', async () => {
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-response>To set up QuickBooks, go to Settings...</followup-response></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?', response: 'To set up QuickBooks, go to Settings...'},
CONST.DEFAULT_TIME_ZONE,
TEST_USER_ACCOUNT_ID,
TEST_USER_EMAIL,
);
await waitForBatchedUpdates();

// Get the pending Concierge response and verify its created timestamp
const pendingResponse = await getOnyxValue(`${ONYXKEYS.COLLECTION.PENDING_CONCIERGE_RESPONSE}${REPORT_ID}` as const);
expect(pendingResponse).not.toBeNull();

// Find the user's comment action (any new action that isn't the original Concierge message)
const reportActions = await getOnyxValue(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${REPORT_ID}` as const);
const userCommentAction = Object.values(reportActions ?? {}).find(
(action) => action?.reportActionID !== REPORT_ACTION_ID && action?.actorAccountID !== CONST.ACCOUNT_ID.CONCIERGE,
);

// The Concierge response timestamp should be strictly after the user comment
expect(userCommentAction).toBeDefined();
expect(userCommentAction?.created).toBeDefined();
expect(pendingResponse?.reportAction.created).toBeDefined();
expect(new Date(pendingResponse?.reportAction.created ?? 0).getTime()).toBeGreaterThan(new Date(userCommentAction?.created ?? 0).getTime());
});
});

// Shared test constants for leave functions
Expand Down
16 changes: 16 additions & 0 deletions tests/unit/ReportActionsFollowupUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,22 @@ describe('ReportActionsFollowupUtils', () => {
]);
});

it('should preserve HTML formatting in followup-response (bullets, breaks, strong tags)', () => {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is not related to the main change, but it's a regression coverage for the HTML preservation

const html = `<followup-list>
<followup>
<followup-text>How do I set up QuickBooks?</followup-text>
<followup-response>To set up QuickBooks:<br><ul><li><strong>Step 1</strong>: Go to Settings</li><li><strong>Step 2</strong>: Click Integrations</li></ul></followup-response>
</followup>
</followup-list>`;
const result = parseFollowupsFromHtml(html);
expect(result).toEqual([
{
text: 'How do I set up QuickBooks?',
response: 'To set up QuickBooks:<br><ul><li><strong>Step 1</strong>: Go to Settings</li><li><strong>Step 2</strong>: Click Integrations</li></ul>',
},
]);
});

it('should handle empty followup-response element', () => {
const html = `<followup-list>
<followup>
Expand Down
Loading