From 6b386202b877e9b7c5acd4d9fa7dbb24ac41eb06 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Wed, 18 Dec 2024 01:50:13 +0300 Subject: [PATCH 1/7] updated to set correct quick action for share and categorize flow --- src/libs/actions/IOU.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 696853f49fd7f..2e70793a8ebb3 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1499,11 +1499,12 @@ function buildOnyxDataForTrackExpense( const successData: OnyxUpdate[] = []; const failureData: OnyxUpdate[] = []; - let newQuickAction: ValueOf = CONST.QUICK_ACTIONS.TRACK_MANUAL; + const isSelfDM = ReportUtils.isSelfDM(chatReport); + let newQuickAction: ValueOf = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; if (isScanRequest) { - newQuickAction = CONST.QUICK_ACTIONS.TRACK_SCAN; + newQuickAction = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_SCAN : CONST.QUICK_ACTIONS.REQUEST_SCAN; } else if (isDistanceRequest) { - newQuickAction = CONST.QUICK_ACTIONS.TRACK_DISTANCE; + newQuickAction = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_DISTANCE : CONST.QUICK_ACTIONS.REQUEST_DISTANCE; } const existingTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingTransactionThreadReportID}`] ?? null; From ebce0d648228c0e8563e17b5e11b4acaf1fb5248 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Thu, 19 Dec 2024 16:21:02 +0300 Subject: [PATCH 2/7] added test --- tests/actions/IOUTest.ts | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 2127b4b819ca6..cb0dcb3b9f594 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -269,6 +269,54 @@ describe('actions/IOU', () => { }), ); }); + it('trackExpense - categorizing tracked expense should set the quick action to REQUEST_MANUAL with the correct chatReportID', () => { + const chatReportID = ReportUtils.generateReportID(); + // When we categorize a tracked expense with a given chatReportID + IOU.trackExpense( + {reportID: chatReportID}, + 1000, + 'USD', + '2024-10-30', + 'merchant', + undefined, + 0, + {accountID: 123456}, + 'comment', + true, + undefined, + 'category', + 'tag', + 'taxCode', + 0, + undefined, + undefined, + undefined, + undefined, + undefined, + undefined, + CONST.IOU.ACTION.CATEGORIZE, + 'actionableWhisperReportActionID', + {actionName: 'IOU', reportActionID: 'linkedTrackedExpenseReportAction', created: '2024-10-30'}, + 'linkedTrackedExpenseReportID', + ); + + return waitForBatchedUpdates().then( + () => + new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + callback: (quickAction) => { + Onyx.disconnect(connection); + // Then the quickAction.action should be set to REQUEST_MANUAL + expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.REQUEST_MANUAL); + // Then the quickAction.chatReportID should be set to the given chatReportID + expect(quickAction?.chatReportID).toBe(chatReportID); + resolve(); + }, + }); + }), + ); + }); it('updates existing chat report if there is one', () => { const amount = 10000; From ef806e76b15f2046fc5778a122b8e1378a8c2d0f Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 21 Jan 2025 01:42:42 +0300 Subject: [PATCH 3/7] fix lint --- src/libs/actions/IOU.ts | 8 ++++---- tests/actions/IOUTest.ts | 13 ++++++++++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 3ea3881896090..1ae5c41f0a46a 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -1755,12 +1755,12 @@ function buildOnyxDataForTrackExpense( const successData: OnyxUpdate[] = []; const failureData: OnyxUpdate[] = []; - const isSelfDM = ReportUtils.isSelfDM(chatReport); - let newQuickAction: ValueOf = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; + const isSelfDMReport = isSelfDM(chatReport); + let newQuickAction: ValueOf = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; if (isScanRequest) { - newQuickAction = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_SCAN : CONST.QUICK_ACTIONS.REQUEST_SCAN; + newQuickAction = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_SCAN : CONST.QUICK_ACTIONS.REQUEST_SCAN; } else if (isDistanceRequest) { - newQuickAction = isSelfDM ? CONST.QUICK_ACTIONS.TRACK_DISTANCE : CONST.QUICK_ACTIONS.REQUEST_DISTANCE; + newQuickAction = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_DISTANCE : CONST.QUICK_ACTIONS.REQUEST_DISTANCE; } const existingTransactionThreadReport = allReports?.[`${ONYXKEYS.COLLECTION.REPORT}${existingTransactionThreadReportID}`] ?? null; diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index cec8ad34def97..0cf007d00aac8 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -39,7 +39,14 @@ import { isActionOfType, isMoneyRequestAction, } from '@libs/ReportActionsUtils'; -import {buildOptimisticIOUReport, buildOptimisticIOUReportAction, buildTransactionThread, createDraftTransactionAndNavigateToParticipantSelector, isIOUReport} from '@libs/ReportUtils'; +import { + buildOptimisticIOUReport, + buildOptimisticIOUReportAction, + buildTransactionThread, + createDraftTransactionAndNavigateToParticipantSelector, + generateReportID, + isIOUReport, +} from '@libs/ReportUtils'; import type {OptimisticChatReport} from '@libs/ReportUtils'; import {buildOptimisticTransaction, getValidWaypoints, isDistanceRequest as isDistanceRequestUtil} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; @@ -537,9 +544,9 @@ describe('actions/IOU', () => { ); }); it('trackExpense - categorizing tracked expense should set the quick action to REQUEST_MANUAL with the correct chatReportID', () => { - const chatReportID = ReportUtils.generateReportID(); + const chatReportID = generateReportID(); // When we categorize a tracked expense with a given chatReportID - IOU.trackExpense( + trackExpense( {reportID: chatReportID}, 1000, 'USD', From 173526fcf831bc73bf3ead921f8496f88a0e384d Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Thu, 6 Feb 2025 18:23:57 +0300 Subject: [PATCH 4/7] update test --- tests/actions/IOUTest.ts | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 04ed3354da4d3..164e618dd79da 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -538,33 +538,13 @@ describe('actions/IOU', () => { it('trackExpense - categorizing tracked expense should set the quick action to REQUEST_MANUAL with the correct chatReportID', () => { const chatReportID = generateReportID(); // When we categorize a tracked expense with a given chatReportID - trackExpense( - {reportID: chatReportID}, - 1000, - 'USD', - '2024-10-30', - 'merchant', - undefined, - 0, - {accountID: 123456}, - 'comment', - true, - undefined, - 'category', - 'tag', - 'taxCode', - 0, - undefined, - undefined, - undefined, - undefined, - undefined, - undefined, - CONST.IOU.ACTION.CATEGORIZE, - 'actionableWhisperReportActionID', - {actionName: 'IOU', reportActionID: 'linkedTrackedExpenseReportAction', created: '2024-10-30'}, - 'linkedTrackedExpenseReportID', - ); + trackExpense({ + report: {reportID: chatReportID}, + isDraftPolicy: true, + transactionParams: {amount: 1000, currency: 'USD', created: '2024-10-30', merchant: 'merchant', comment: 'comment', category: 'category', tag: 'tag'}, + participantParams: {participant: {accountID: 123456}, payeeAccountID: 0, payeeEmail: undefined}, + action: CONST.IOU.ACTION.CATEGORIZE, + }); return waitForBatchedUpdates().then( () => From 800038b1f76c4365cccacf3f94bd774b6a0bd3bc Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Thu, 6 Feb 2025 18:51:10 +0300 Subject: [PATCH 5/7] merge test --- tests/actions/IOUTest.ts | 56 +++++++++++++--------------------------- 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 164e618dd79da..813360f3b817d 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -39,14 +39,7 @@ import { isActionOfType, isMoneyRequestAction, } from '@libs/ReportActionsUtils'; -import { - buildOptimisticIOUReport, - buildOptimisticIOUReportAction, - buildTransactionThread, - createDraftTransactionAndNavigateToParticipantSelector, - generateReportID, - isIOUReport, -} from '@libs/ReportUtils'; +import {buildOptimisticIOUReport, buildOptimisticIOUReportAction, buildTransactionThread, createDraftTransactionAndNavigateToParticipantSelector, isIOUReport} from '@libs/ReportUtils'; import type {OptimisticChatReport} from '@libs/ReportUtils'; import {buildOptimisticTransaction, getValidWaypoints, isDistanceRequest as isDistanceRequestUtil} from '@libs/TransactionUtils'; import CONST from '@src/CONST'; @@ -169,7 +162,7 @@ describe('actions/IOU', () => { }; // Given a policyExpenseChat report - const expenseReport = { + const policyExpenseChat = { ...createRandomReport(1), chatType: CONST.REPORT.CHAT_TYPE.POLICY_EXPENSE_CHAT, }; @@ -285,7 +278,7 @@ describe('actions/IOU', () => { // When the user confirms the category for the tracked expense trackExpense({ - report: expenseReport, + report: policyExpenseChat, isDraftPolicy: false, action: CONST.IOU.ACTION.CATEGORIZE, participantParams: { @@ -332,6 +325,21 @@ describe('actions/IOU', () => { }, }); }); + + await new Promise((resolve) => { + const connection = Onyx.connect({ + key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, + callback: (quickAction) => { + Onyx.disconnect(connection); + resolve(); + + // Then the quickAction.action should be set to REQUEST_DISTANCE + expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.REQUEST_DISTANCE); + // Then the quickAction.chatReportID should be set to the given chat reportID + expect(quickAction?.chatReportID).toBe(policyExpenseChat.reportID); + }, + }); + }); }); }); @@ -535,34 +543,6 @@ describe('actions/IOU', () => { }), ); }); - it('trackExpense - categorizing tracked expense should set the quick action to REQUEST_MANUAL with the correct chatReportID', () => { - const chatReportID = generateReportID(); - // When we categorize a tracked expense with a given chatReportID - trackExpense({ - report: {reportID: chatReportID}, - isDraftPolicy: true, - transactionParams: {amount: 1000, currency: 'USD', created: '2024-10-30', merchant: 'merchant', comment: 'comment', category: 'category', tag: 'tag'}, - participantParams: {participant: {accountID: 123456}, payeeAccountID: 0, payeeEmail: undefined}, - action: CONST.IOU.ACTION.CATEGORIZE, - }); - - return waitForBatchedUpdates().then( - () => - new Promise((resolve) => { - const connection = Onyx.connect({ - key: ONYXKEYS.NVP_QUICK_ACTION_GLOBAL_CREATE, - callback: (quickAction) => { - Onyx.disconnect(connection); - // Then the quickAction.action should be set to REQUEST_MANUAL - expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.REQUEST_MANUAL); - // Then the quickAction.chatReportID should be set to the given chatReportID - expect(quickAction?.chatReportID).toBe(chatReportID); - resolve(); - }, - }); - }), - ); - }); it('updates existing chat report if there is one', () => { const amount = 10000; From 401b728bc02431e5c226d42206c8180cba6f0bf4 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Thu, 6 Feb 2025 18:52:32 +0300 Subject: [PATCH 6/7] update comment --- tests/actions/IOUTest.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index 813360f3b817d..0119aa4a68c40 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -335,7 +335,7 @@ describe('actions/IOU', () => { // Then the quickAction.action should be set to REQUEST_DISTANCE expect(quickAction?.action).toBe(CONST.QUICK_ACTIONS.REQUEST_DISTANCE); - // Then the quickAction.chatReportID should be set to the given chat reportID + // Then the quickAction.chatReportID should be set to the given policyExpenseChat reportID expect(quickAction?.chatReportID).toBe(policyExpenseChat.reportID); }, }); From c7a0ff68a3422820cff4ab6f4937504931ecd517 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Tue, 25 Feb 2025 01:22:19 +0300 Subject: [PATCH 7/7] minor update --- src/libs/actions/IOU.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 95079a9ae5789..4e373f614274b 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -172,6 +172,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {Attendee, Participant, Split} from '@src/types/onyx/IOU'; import type {ErrorFields, Errors} from '@src/types/onyx/OnyxCommon'; import type {PaymentMethodType} from '@src/types/onyx/OriginalMessage'; +import type {QuickActionName} from '@src/types/onyx/QuickAction'; import type {InvoiceReceiver, InvoiceReceiverType} from '@src/types/onyx/Report'; import type ReportAction from '@src/types/onyx/ReportAction'; import type {OnyxData} from '@src/types/onyx/Request'; @@ -1883,7 +1884,7 @@ function buildOnyxDataForTrackExpense( const failureData: OnyxUpdate[] = []; const isSelfDMReport = isSelfDM(chatReport); - let newQuickAction: ValueOf = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; + let newQuickAction: QuickActionName = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_MANUAL : CONST.QUICK_ACTIONS.REQUEST_MANUAL; if (isScanRequest) { newQuickAction = isSelfDMReport ? CONST.QUICK_ACTIONS.TRACK_SCAN : CONST.QUICK_ACTIONS.REQUEST_SCAN; } else if (isDistanceRequest) {