22import * as PolicyUtils from '@libs/PolicyUtils' ;
33import { isQuickActionAllowed } from '@libs/QuickActionUtils' ;
44import CONST from '@src/CONST' ;
5- import type { Policy } from '@src/types/onyx' ;
5+ import type { Policy , Report } from '@src/types/onyx' ;
66
77// Mock the PolicyUtils module
88jest . mock ( '@libs/PolicyUtils' ) ;
@@ -22,21 +22,7 @@ describe('QuickActionUtils', () => {
2222 jest . clearAllMocks ( ) ;
2323 } ) ;
2424
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' , ( ) => {
25+ it ( 'should return false when shouldShowPolicy returns true and isPolicyExpenseChatEnabled is true' , ( ) => {
4026 const policy : Partial < Policy > = {
4127 id : 'policy123' ,
4228 isPolicyExpenseChatEnabled : true ,
@@ -47,7 +33,6 @@ describe('QuickActionUtils', () => {
4733 const result = isQuickActionAllowed ( createReportAction , undefined , policy as Policy ) ;
4834
4935 expect ( result ) . toBe ( false ) ;
50- expect ( mockedPolicyUtils . shouldShowPolicy ) . toHaveBeenCalledWith ( policy , false , undefined ) ;
5136 } ) ;
5237
5338 it ( 'should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is false' , ( ) => {
@@ -56,12 +41,11 @@ describe('QuickActionUtils', () => {
5641 isPolicyExpenseChatEnabled : false ,
5742 } ;
5843
59- mockedPolicyUtils . shouldShowPolicy . mockReturnValue ( true ) ;
44+ mockedPolicyUtils . shouldShowPolicy . mockReturnValue ( false ) ;
6045
6146 const result = isQuickActionAllowed ( createReportAction , undefined , policy as Policy ) ;
6247
6348 expect ( result ) . toBe ( false ) ;
64- expect ( mockedPolicyUtils . shouldShowPolicy ) . toHaveBeenCalledWith ( policy , false , undefined ) ;
6549 } ) ;
6650
6751 it ( 'should return false when shouldShowPolicy returns true but isPolicyExpenseChatEnabled is undefined' , ( ) => {
@@ -75,7 +59,6 @@ describe('QuickActionUtils', () => {
7559 const result = isQuickActionAllowed ( createReportAction , undefined , policy as Policy ) ;
7660
7761 expect ( result ) . toBe ( false ) ;
78- expect ( mockedPolicyUtils . shouldShowPolicy ) . toHaveBeenCalledWith ( policy , false , undefined ) ;
7962 } ) ;
8063
8164 it ( 'should return false when policy is undefined' , ( ) => {
@@ -84,7 +67,6 @@ describe('QuickActionUtils', () => {
8467 const result = isQuickActionAllowed ( createReportAction , undefined , undefined ) ;
8568
8669 expect ( result ) . toBe ( false ) ;
87- expect ( mockedPolicyUtils . shouldShowPolicy ) . toHaveBeenCalledWith ( undefined , false , undefined ) ;
8870 } ) ;
8971
9072 it ( 'should return false when both conditions are false' , ( ) => {
@@ -98,7 +80,36 @@ describe('QuickActionUtils', () => {
9880 const result = isQuickActionAllowed ( createReportAction , undefined , policy as Policy ) ;
9981
10082 expect ( result ) . toBe ( false ) ;
101- expect ( mockedPolicyUtils . shouldShowPolicy ) . toHaveBeenCalledWith ( policy , false , undefined ) ;
83+ } ) ;
84+ } ) ;
85+ describe ( 'Manager McTest restrictions' , ( ) => {
86+ const requestScanAction = {
87+ action : CONST . QUICK_ACTIONS . REQUEST_SCAN ,
88+ isFirstQuickAction : false ,
89+ } ;
90+
91+ // Given a report with Manager McTest
92+ const reportWithManagerMcTest : Report = {
93+ reportID : '1' ,
94+ participants : {
95+ [ CONST . ACCOUNT_ID . MANAGER_MCTEST ] : {
96+ notificationPreference : CONST . REPORT . NOTIFICATION_PREFERENCE . ALWAYS ,
97+ } ,
98+ } ,
99+ } ;
100+
101+ beforeEach ( ( ) => {
102+ jest . clearAllMocks ( ) ;
103+ } ) ;
104+
105+ it ( 'should return false when report contains Manager McTest' , ( ) => {
106+ mockedPolicyUtils . shouldShowPolicy . mockReturnValue ( false ) ;
107+
108+ // When the report contains Manager McTest
109+ const result = isQuickActionAllowed ( requestScanAction , reportWithManagerMcTest , undefined ) ;
110+
111+ // Then it should return false
112+ expect ( result ) . toBe ( false ) ;
102113 } ) ;
103114 } ) ;
104115 } ) ;
0 commit comments