From 2e97d8e285ea37033b0871cdba6ed1feebcb9139 Mon Sep 17 00:00:00 2001 From: c3024 Date: Mon, 23 Sep 2024 12:45:46 +0530 Subject: [PATCH 1/6] conditional next step message based on account --- src/libs/NextStepUtils.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 6dc12d6d1211..de9a60120cfb 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -99,6 +99,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf, predictedNextStatus: ValueOf Date: Tue, 24 Sep 2024 19:33:00 +0530 Subject: [PATCH 2/6] match with backend and compare display name also --- src/libs/NextStepUtils.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index de9a60120cfb..027dfb70864e 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -25,6 +25,7 @@ Onyx.connect({ currentUserAccountID = value?.accountID ?? -1; currentUserEmail = value?.email ?? ''; + }, }); @@ -37,13 +38,13 @@ Onyx.connect({ function parseMessage(messages: Message[] | undefined) { let nextStepHTML = ''; - + const currentUserDisplayName = ReportUtils.getDisplayNameForParticipant(currentUserAccountID); messages?.forEach((part) => { const isEmail = Str.isValidEmail(part.text); let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); - if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { + if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail || part.text === currentUserDisplayName) { tagType = 'strong'; content = 'You'; } else if (isEmail) { @@ -271,7 +272,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Tue, 24 Sep 2024 19:46:13 +0530 Subject: [PATCH 3/6] clickToCopyText for step after approval --- src/libs/NextStepUtils.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index 55719675628c..c427599eab92 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -25,7 +25,6 @@ Onyx.connect({ currentUserAccountID = value?.accountID ?? -1; currentUserEmail = value?.email ?? ''; - }, }); @@ -38,8 +37,7 @@ Onyx.connect({ function parseMessage(messages: Message[] | undefined) { let nextStepHTML = ''; - - messages?.forEach((part, index) => { + const currentUserDisplayName = messages?.forEach((part, index) => { const isEmail = Str.isValidEmail(part.text); let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); @@ -47,7 +45,7 @@ function parseMessage(messages: Message[] | undefined) { const previousPart = messages[index - 1]; const nextPart = messages[index + 1]; - if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail || part.text === currentUserDisplayName) { + if (currentUserEmail === part.text || part.clickToCopyText === currentUserEmail) { tagType = 'strong'; content = nextPart?.text === `'s` ? 'Your' : 'You'; } else if (part.text === `'s` && (previousPart?.text === currentUserEmail || previousPart?.clickToCopyText === currentUserEmail)) { @@ -275,6 +273,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf Date: Tue, 24 Sep 2024 20:24:08 +0530 Subject: [PATCH 4/6] remove unused variable --- src/libs/NextStepUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index c427599eab92..c441f746b4dd 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -37,7 +37,7 @@ Onyx.connect({ function parseMessage(messages: Message[] | undefined) { let nextStepHTML = ''; - const currentUserDisplayName = messages?.forEach((part, index) => { + messages?.forEach((part, index) => { const isEmail = Str.isValidEmail(part.text); let tagType = part.type ?? 'span'; let content = Str.safeEscape(part.text); From dff3a34de5b2cbc163a79516263bce23ad505f6b Mon Sep 17 00:00:00 2001 From: c3024 Date: Tue, 24 Sep 2024 20:53:42 +0530 Subject: [PATCH 5/6] remove extra space and fix tests --- src/libs/NextStepUtils.ts | 2 +- tests/unit/NextStepUtilsTest.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libs/NextStepUtils.ts b/src/libs/NextStepUtils.ts index c441f746b4dd..894088499c79 100644 --- a/src/libs/NextStepUtils.ts +++ b/src/libs/NextStepUtils.ts @@ -279,7 +279,7 @@ function buildNextStep(report: OnyxEntry, predictedNextStatus: ValueOf { text: ' to ', }, { - text: 'pay', + text: 'finish setting up', }, { - text: ' %expenses.', + text: ' a business bank account.', }, ]; @@ -543,10 +543,10 @@ describe('libs/NextStepUtils', () => { text: ' to ', }, { - text: 'pay', + text: 'finish setting up', }, { - text: ' %expenses.', + text: ' a business bank account.', }, ]; // mock the report as approved From 57ec6c2f4aa6eadf041d8a913c4c3bfbabffdbc6 Mon Sep 17 00:00:00 2001 From: c3024 Date: Tue, 8 Oct 2024 12:52:22 +0530 Subject: [PATCH 6/6] add tests for validated bank account --- tests/unit/NextStepUtilsTest.ts | 89 +++++++++++++++++++++++++++++---- 1 file changed, 80 insertions(+), 9 deletions(-) diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 3658c701f589..776c5f95cce7 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -402,7 +402,7 @@ describe('libs/NextStepUtils', () => { test('self review', () => { optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS; - // Waiting for an admin to pay expense(s) + // Waiting for an admin to set up a bank account optimisticNextStep.message = [ { text: 'Waiting for ', @@ -426,6 +426,44 @@ describe('libs/NextStepUtils', () => { expect(result).toMatchObject(optimisticNextStep); }); + test('self review with bank account setup', () => { + optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS; + + // Waiting for an admin to pay expense(s) + optimisticNextStep.message = [ + { + text: 'Waiting for ', + }, + { + text: `an admin`, + }, + { + text: ' to ', + }, + { + text: 'pay', + }, + { + text: ' %expenses.', + }, + ]; + + return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { + achAccount: { + accountNumber: '123456789', + }, + }).then(() => { + const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); + + expect(result).toMatchObject(optimisticNextStep); + + // restore to previous state + Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { + achAccount: null, + }); + }); + }); + test('another reviewer', () => { report.managerID = strangeAccountID; optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS; @@ -536,7 +574,7 @@ describe('libs/NextStepUtils', () => { test('payer', () => { optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS; - // Waiting for an admin to pay expense(s). + // Waiting for an admin to set up a bank account optimisticNextStep.message = [ { text: 'Waiting for ', @@ -567,20 +605,53 @@ describe('libs/NextStepUtils', () => { report.stateNum = originalState.stateNum; report.statusNum = originalState.statusNum; }); - }); - describe('it generates an optimistic nextStep once a report has been paid', () => { - test('paid with wallet / outside of Expensify', () => { - optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.CHECKMARK; + test('payer with bank account setup', () => { + optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS; + + // Waiting for an admin to pay expense(s) optimisticNextStep.message = [ { - text: 'No further action required!', + text: 'Waiting for ', + }, + { + text: 'an admin', + }, + { + text: ' to ', + }, + { + text: 'pay', + }, + { + text: ' %expenses.', }, ]; - const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED); + return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, { + achAccount: { + accountNumber: '123456789', + }, + }).then(() => { + const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED); - expect(result).toMatchObject(optimisticNextStep); + expect(result).toMatchObject(optimisticNextStep); + }); + }); + + describe('it generates an optimistic nextStep once a report has been paid', () => { + test('paid with wallet / outside of Expensify', () => { + optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.CHECKMARK; + optimisticNextStep.message = [ + { + text: 'No further action required!', + }, + ]; + + const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.REIMBURSED); + + expect(result).toMatchObject(optimisticNextStep); + }); }); }); });