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
6 changes: 3 additions & 3 deletions src/libs/NextStepUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Onyx.connect({

function parseMessage(messages: Message[] | undefined) {
let nextStepHTML = '';

messages?.forEach((part, index) => {
const isEmail = Str.isValidEmail(part.text);
let tagType = part.type ?? 'span';
Expand Down Expand Up @@ -94,6 +93,7 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
const nextApproverDisplayName = getNextApproverDisplayName(report);

const reimburserAccountID = PolicyUtils.getReimburserAccountID(policy);
const hasValidAccount = !!policy?.achAccount?.accountNumber;
const type: ReportNextStep['type'] = 'neutral';
let optimisticNextStep: ReportNextStep | null;

Expand Down Expand Up @@ -272,10 +272,10 @@ function buildNextStep(report: OnyxEntry<Report>, predictedNextStatus: ValueOf<t
text: ' to ',
},
{
text: 'pay',
text: hasValidAccount ? 'pay' : 'finish setting up',
},
{
text: ' %expenses.',
text: hasValidAccount ? ' %expenses.' : ' a business bank account.',
},
],
};
Expand Down
95 changes: 83 additions & 12 deletions tests/unit/NextStepUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,33 @@ describe('libs/NextStepUtils', () => {
test('self review', () => {
optimisticNextStep.icon = CONST.NEXT_STEP.ICONS.HOURGLASS;

// Waiting for an admin to set up a bank account
optimisticNextStep.message = [
{
text: 'Waiting for ',
},
{
text: `an admin`,
},
{
text: ' to ',
},
{
text: 'finish setting up',
},
{
text: ' a business bank account.',
},
];

const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);

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 = [
{
Expand All @@ -421,9 +448,20 @@ describe('libs/NextStepUtils', () => {
},
];

const result = NextStepUtils.buildNextStep(report, CONST.REPORT.STATUS_NUM.APPROVED);
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);

// restore to previous state
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
achAccount: null,
});
});
});

test('another reviewer', () => {
Expand Down Expand Up @@ -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 ',
Expand All @@ -548,10 +586,10 @@ describe('libs/NextStepUtils', () => {
text: ' to ',
},
{
text: 'pay',
text: 'finish setting up',
},
{
text: ' %expenses.',
text: ' a business bank account.',
},
];
// mock the report as approved
Expand All @@ -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);
});
});
});
});
Expand Down