@@ -11,35 +11,59 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1111jest . mock ( '@libs/TransactionUtils' , ( ) => {
1212 // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
1313 const CONST_MOCK = jest . requireActual ( '@src/CONST' ) . default as typeof CONST_TYPE ;
14- return {
15- isViolationDismissed : jest . fn ( ) ,
16- shouldShowViolation : jest . fn ( ) ,
17- mergeProhibitedViolations : ( transactionViolations : Array < { name : string ; type : string ; showInReview ?: boolean ; data ?: { prohibitedExpenseRule ?: string | string [ ] } } > ) => {
18- const prohibitedViolations = transactionViolations . filter ( ( violation ) => violation . name === CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ) ;
1914
20- if ( prohibitedViolations . length === 0 ) {
21- return transactionViolations ;
15+ const mergeProhibitedViolations = ( transactionViolations : Array < { name : string ; type : string ; showInReview ?: boolean ; data ?: { prohibitedExpenseRule ?: string | string [ ] } } > ) => {
16+ const prohibitedViolations = transactionViolations . filter ( ( violation ) => violation . name === CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ) ;
17+
18+ if ( prohibitedViolations . length === 0 ) {
19+ return transactionViolations ;
20+ }
21+
22+ const prohibitedExpenses = prohibitedViolations . flatMap ( ( violation ) => {
23+ const rule = violation . data ?. prohibitedExpenseRule ;
24+ if ( ! rule ) {
25+ return [ ] ;
2226 }
27+ return Array . isArray ( rule ) ? rule : [ rule ] ;
28+ } ) ;
2329
24- const prohibitedExpenses = prohibitedViolations . flatMap ( ( violation ) => {
25- const rule = violation . data ?. prohibitedExpenseRule ;
26- if ( ! rule ) {
27- return [ ] ;
28- }
29- return Array . isArray ( rule ) ? rule : [ rule ] ;
30- } ) ;
30+ const mergedProhibitedViolations = {
31+ name : CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ,
32+ data : {
33+ prohibitedExpenseRule : prohibitedExpenses ,
34+ } ,
35+ type : CONST_MOCK . VIOLATION_TYPES . VIOLATION ,
36+ showInReview : prohibitedViolations . some ( ( v ) => v . showInReview ) ,
37+ } ;
3138
32- const mergedProhibitedViolations = {
33- name : CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ,
34- data : {
35- prohibitedExpenseRule : prohibitedExpenses ,
36- } ,
37- type : CONST_MOCK . VIOLATION_TYPES . VIOLATION ,
38- showInReview : prohibitedViolations . some ( ( v ) => v . showInReview ) ,
39- } ;
39+ return [ ...transactionViolations . filter ( ( violation ) => violation . name !== CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ) , mergedProhibitedViolations ] ;
40+ } ;
4041
41- return [ ...transactionViolations . filter ( ( violation ) => violation . name !== CONST_MOCK . VIOLATIONS . PROHIBITED_EXPENSE ) , mergedProhibitedViolations ] ;
42- } ,
42+ const mockIsViolationDismissed = jest . fn ( ) ;
43+ const mockShouldShowViolation = jest . fn ( ) ;
44+
45+ const getVisibleTransactionViolations = (
46+ transaction : Transaction | undefined ,
47+ transactionViolations : TransactionViolations ,
48+ currentUserEmail : string ,
49+ currentUserAccountID : number ,
50+ iouReport : Report | undefined ,
51+ policy : Policy | undefined ,
52+ shouldShowRterForSettledReport = true ,
53+ ) =>
54+ mergeProhibitedViolations (
55+ transactionViolations . filter (
56+ ( violation ) =>
57+ ! mockIsViolationDismissed ( transaction , violation , currentUserEmail , currentUserAccountID , iouReport , policy ) &&
58+ mockShouldShowViolation ( iouReport , policy , violation . name , currentUserEmail , shouldShowRterForSettledReport , transaction ) ,
59+ ) ,
60+ ) ;
61+
62+ return {
63+ isViolationDismissed : mockIsViolationDismissed ,
64+ shouldShowViolation : mockShouldShowViolation ,
65+ mergeProhibitedViolations,
66+ getVisibleTransactionViolations,
4367 } ;
4468} ) ;
4569
0 commit comments