Skip to content

Commit 2ac3b4e

Browse files
Merge pull request Expensify#65663 from nkdengineer/fix/64179
Report - New report can be created on an archived workspace via QAB
2 parents ad0faf5 + 74dba25 commit 2ac3b4e

2 files changed

Lines changed: 107 additions & 1 deletion

File tree

src/libs/QuickActionUtils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import type {Policy, Report} from '@src/types/onyx';
66
import type {QuickActionName} from '@src/types/onyx/QuickAction';
77
import type QuickAction from '@src/types/onyx/QuickAction';
88
import getIconForAction from './getIconForAction';
9+
import {shouldShowPolicy} from './PolicyUtils';
910
import {canCreateRequest} from './ReportUtils';
1011

1112
const getQuickActionIcon = (action: QuickActionName): React.FC<SvgProps> => {
@@ -100,7 +101,7 @@ const isQuickActionAllowed = (quickAction: QuickAction, quickActionReport: Repor
100101
return !!quickActionPolicy?.arePerDiemRatesEnabled;
101102
}
102103
if (quickAction?.action === CONST.QUICK_ACTIONS.CREATE_REPORT) {
103-
return !!quickActionPolicy;
104+
return shouldShowPolicy(quickActionPolicy, false, undefined) && !!quickActionPolicy?.isPolicyExpenseChatEnabled;
104105
}
105106
return true;
106107
};

tests/unit/QuickActionUtilsTest.ts

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
// eslint-disable-next-line no-restricted-syntax
2+
import * as PolicyUtils from '@libs/PolicyUtils';
3+
import {isQuickActionAllowed} from '@libs/QuickActionUtils';
4+
import CONST from '@src/CONST';
5+
import type {Policy} from '@src/types/onyx';
6+
7+
// Mock the PolicyUtils module
8+
jest.mock('@libs/PolicyUtils');
9+
10+
const mockedPolicyUtils = PolicyUtils as jest.Mocked<typeof PolicyUtils>;
11+
12+
describe('QuickActionUtils', () => {
13+
describe('isQuickActionAllowed', () => {
14+
describe('CREATE_REPORT action', () => {
15+
const createReportAction = {
16+
action: CONST.QUICK_ACTIONS.CREATE_REPORT,
17+
targetAccountID: 123,
18+
isFirstQuickAction: false,
19+
};
20+
21+
beforeEach(() => {
22+
jest.clearAllMocks();
23+
});
24+
25+
it('should return true when shouldShowPolicy returns true and isPolicyExpenseChatEnabled is true', () => {
26+
const policy: Partial<Policy> = {
27+
id: 'policy123',
28+
isPolicyExpenseChatEnabled: true,
29+
};
30+
31+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(true);
32+
33+
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
34+
35+
expect(result).toBe(true);
36+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
37+
});
38+
39+
it('should return false when shouldShowPolicy returns false even if isPolicyExpenseChatEnabled is true', () => {
40+
const policy: Partial<Policy> = {
41+
id: 'policy123',
42+
isPolicyExpenseChatEnabled: true,
43+
};
44+
45+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(false);
46+
47+
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
48+
49+
expect(result).toBe(false);
50+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
51+
});
52+
53+
it('should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is false', () => {
54+
const policy: Partial<Policy> = {
55+
id: 'policy123',
56+
isPolicyExpenseChatEnabled: false,
57+
};
58+
59+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(true);
60+
61+
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
62+
63+
expect(result).toBe(false);
64+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
65+
});
66+
67+
it('should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is undefined', () => {
68+
const policy: Partial<Policy> = {
69+
id: 'policy123',
70+
// isPolicyExpenseChatEnabled is undefined
71+
};
72+
73+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(true);
74+
75+
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
76+
77+
expect(result).toBe(false);
78+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
79+
});
80+
81+
it('should return false when policy is undefined', () => {
82+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(false);
83+
84+
const result = isQuickActionAllowed(createReportAction, undefined, undefined);
85+
86+
expect(result).toBe(false);
87+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(undefined, false, undefined);
88+
});
89+
90+
it('should return false when both conditions are false', () => {
91+
const policy: Partial<Policy> = {
92+
id: 'policy123',
93+
isPolicyExpenseChatEnabled: false,
94+
};
95+
96+
mockedPolicyUtils.shouldShowPolicy.mockReturnValue(false);
97+
98+
const result = isQuickActionAllowed(createReportAction, undefined, policy as Policy);
99+
100+
expect(result).toBe(false);
101+
expect(mockedPolicyUtils.shouldShowPolicy).toHaveBeenCalledWith(policy, false, undefined);
102+
});
103+
});
104+
});
105+
});

0 commit comments

Comments
 (0)