Skip to content

fix: incorrect next step message when approval mode enabled #57985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 3 additions & 2 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {getNextApproverAccountID} from './actions/IOU';
import DateUtils from './DateUtils';
import EmailUtils from './EmailUtils';
import {getLoginsByAccountIDs, getPersonalDetailsByIDs} from './PersonalDetailsUtils';
import {getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
import {getApprovalWorkflow, getCorrectedAutoReportingFrequency, getReimburserAccountID} from './PolicyUtils';
import {getDisplayNameForParticipant, getPersonalDetailsForAccountID, hasViolations as hasViolationsReportUtils, isExpenseReport, isInvoiceReport, isPayer} from './ReportUtils';

let currentUserAccountID = -1;
Expand Down Expand Up @@ -297,7 +297,8 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
icon: CONST.NEXT_STEP.ICONS.HOURGLASS,
};
// We want to show pending approval next step for cases where the policy has approvals enabled
if (autoReportingFrequency !== CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT) {
const policyApprovalMode = getApprovalWorkflow(policy);
if ([CONST.POLICY.APPROVAL_MODE.BASIC, CONST.POLICY.APPROVAL_MODE.ADVANCED].some((approvalMode) => approvalMode === policyApprovalMode)) {
optimisticNextStep.message = [
{
text: 'Waiting for ',
Expand Down
32 changes: 32 additions & 0 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,38 @@ describe('libs/NextStepUtils', () => {
expect(result).toMatchObject(optimisticNextStep);
});
});

test('approval mode enabled', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you please add more test case for advance approval mode?

report.managerID = strangeAccountID;
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: ownerEmail,
type: 'strong',
clickToCopyText: ownerEmail,
},
{
text: ' to ',
},
{
text: 'approve',
},
{
text: ' %expenses.',
},
];

return Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
approvalMode: CONST.POLICY.APPROVAL_MODE.BASIC,
}).then(() => {
const result = buildNextStep(report, CONST.REPORT.STATUS_NUM.SUBMITTED);

expect(result).toMatchObject(optimisticNextStep);
});
});
});

describe('it generates an optimistic nextStep once a report has been approved', () => {
Expand Down