From e7efb7238544a3b44ad1fa18d9f5185d0b344267 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Mon, 18 Nov 2024 19:55:18 +0300 Subject: [PATCH 1/3] avoid showing rbr for non-admin --- src/hooks/useIndicatorStatus.ts | 8 +-- src/libs/PolicyUtils.ts | 49 ++++++++++--------- src/libs/WorkspacesSettingsUtils.ts | 28 ++++++----- src/pages/workspace/WorkspaceInitialPage.tsx | 6 +-- src/pages/workspace/WorkspacesListPage.tsx | 13 ++--- .../accounting/PolicyAccountingPage.tsx | 2 +- .../categories/WorkspaceCategoriesPage.tsx | 2 +- .../WorkspaceReportFieldsPage.tsx | 2 +- .../workspace/tags/WorkspaceTagsPage.tsx | 2 +- .../workspace/taxes/WorkspaceTaxesPage.tsx | 2 +- 10 files changed, 62 insertions(+), 52 deletions(-) diff --git a/src/hooks/useIndicatorStatus.ts b/src/hooks/useIndicatorStatus.ts index 7fcd81112a9b..695dd031aa88 100644 --- a/src/hooks/useIndicatorStatus.ts +++ b/src/hooks/useIndicatorStatus.ts @@ -35,11 +35,11 @@ function useIndicatorStatus(): IndicatorStatusResult { const cleanPolicies = useMemo(() => Object.fromEntries(Object.entries(policies ?? {}).filter(([, policy]) => policy?.id)), [policies]); const policyErrors = { - [CONST.INDICATOR_STATUS.HAS_POLICY_ERRORS]: Object.values(cleanPolicies).find(PolicyUtils.hasPolicyError), - [CONST.INDICATOR_STATUS.HAS_CUSTOM_UNITS_ERROR]: Object.values(cleanPolicies).find(PolicyUtils.hasCustomUnitsError), - [CONST.INDICATOR_STATUS.HAS_EMPLOYEE_LIST_ERROR]: Object.values(cleanPolicies).find(PolicyUtils.hasEmployeeListError), + [CONST.INDICATOR_STATUS.HAS_POLICY_ERRORS]: Object.values(cleanPolicies).find(PolicyUtils.shouldShowPolicyError), + [CONST.INDICATOR_STATUS.HAS_CUSTOM_UNITS_ERROR]: Object.values(cleanPolicies).find(PolicyUtils.shouldShowCustomUnitsError), + [CONST.INDICATOR_STATUS.HAS_EMPLOYEE_LIST_ERROR]: Object.values(cleanPolicies).find(PolicyUtils.shouldShowEmployeeListError), [CONST.INDICATOR_STATUS.HAS_SYNC_ERRORS]: Object.values(cleanPolicies).find((cleanPolicy) => - PolicyUtils.hasSyncError( + PolicyUtils.shouldShowSyncError( cleanPolicy, isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy), ), diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 4592500e9250..cbb3dd537d64 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -74,18 +74,26 @@ function getActivePolicies(policies: OnyxCollection | null): Policy[] { ); } +/** + * Checks if the current user is an admin of the policy. + */ +const isPolicyAdmin = (policy: OnyxInputOrEntry, currentUserLogin?: string): boolean => getPolicyRole(policy, currentUserLogin) === CONST.POLICY.ROLE.ADMIN; + /** * Checks if we have any errors stored within the policy?.employeeList. Determines whether we should show a red brick road error or not. */ -function hasEmployeeListError(policy: OnyxEntry): boolean { +function shouldShowEmployeeListError(policy: OnyxEntry): boolean { return Object.values(policy?.employeeList ?? {}).some((employee) => Object.keys(employee?.errors ?? {}).length > 0); } /** * Check if the policy has any tax rate errors. */ -function hasTaxRateError(policy: OnyxEntry): boolean { - return Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0 || Object.values(taxRate?.errorFields ?? {}).some(Boolean)); +function shouldShowTaxRateError(policy: OnyxEntry): boolean { + return ( + isPolicyAdmin(policy) && + Object.values(policy?.taxRates?.taxes ?? {}).some((taxRate) => Object.keys(taxRate?.errors ?? {}).length > 0 || Object.values(taxRate?.errorFields ?? {}).some(Boolean)) + ); } /** @@ -98,29 +106,29 @@ function hasPolicyCategoriesError(policyCategories: OnyxEntry) /** * Checks if the policy had a sync error. */ -function hasSyncError(policy: OnyxEntry, isSyncInProgress: boolean): boolean { - return (Object.keys(policy?.connections ?? {}) as ConnectionName[]).some((connection) => !!hasSynchronizationErrorMessage(policy, connection, isSyncInProgress)); +function shouldShowSyncError(policy: OnyxEntry, isSyncInProgress: boolean): boolean { + return isPolicyAdmin(policy) && (Object.keys(policy?.connections ?? {}) as ConnectionName[]).some((connection) => !!hasSynchronizationErrorMessage(policy, connection, isSyncInProgress)); } /** * Check if the policy has any error fields. */ -function hasPolicyErrorFields(policy: OnyxEntry): boolean { - return Object.values(policy?.errorFields ?? {}).some((fieldErrors) => Object.keys(fieldErrors ?? {}).length > 0); +function shouldShowPolicyErrorFields(policy: OnyxEntry): boolean { + return isPolicyAdmin(policy) && Object.values(policy?.errorFields ?? {}).some((fieldErrors) => Object.keys(fieldErrors ?? {}).length > 0); } /** * Check if the policy has any errors, and if it doesn't, then check if it has any error fields. */ -function hasPolicyError(policy: OnyxEntry): boolean { - return Object.keys(policy?.errors ?? {}).length > 0 ? true : hasPolicyErrorFields(policy); +function shouldShowPolicyError(policy: OnyxEntry): boolean { + return Object.keys(policy?.errors ?? {}).length > 0 ? isPolicyAdmin(policy) : shouldShowPolicyErrorFields(policy); } /** * Checks if we have any errors stored within the policy custom units. */ -function hasCustomUnitsError(policy: OnyxEntry): boolean { - return Object.keys(policy?.customUnits?.errors ?? {}).length > 0; +function shouldShowCustomUnitsError(policy: OnyxEntry): boolean { + return isPolicyAdmin(policy) && Object.keys(policy?.customUnits?.errors ?? {}).length > 0; } function getNumericValue(value: number | string, toLocaleDigit: (arg: string) => string): number | string { @@ -178,7 +186,7 @@ function getUnitRateValue(toLocaleDigit: (arg: string) => string, customUnitRate * Get the brick road indicator status for a policy. The policy has an error status if there is a policy member error, a custom unit error or a field error. */ function getPolicyBrickRoadIndicatorStatus(policy: OnyxEntry, isConnectionInProgress: boolean): ValueOf | undefined { - if (hasEmployeeListError(policy) || hasCustomUnitsError(policy) || hasPolicyErrorFields(policy) || hasSyncError(policy, isConnectionInProgress)) { + if (shouldShowEmployeeListError(policy) || shouldShowCustomUnitsError(policy) || shouldShowPolicyErrorFields(policy) || shouldShowSyncError(policy, isConnectionInProgress)) { return CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR; } return undefined; @@ -215,11 +223,6 @@ function isExpensifyTeam(email: string | undefined): boolean { */ const isUserPolicyAdmin = (policy: OnyxInputOrEntry, login?: string) => !!(policy && policy.employeeList && login && policy.employeeList[login]?.role === CONST.POLICY.ROLE.ADMIN); -/** - * Checks if the current user is an admin of the policy. - */ -const isPolicyAdmin = (policy: OnyxInputOrEntry, currentUserLogin?: string): boolean => getPolicyRole(policy, currentUserLogin) === CONST.POLICY.ROLE.ADMIN; - /** * Checks if the current user is of the role "user" on the policy. */ @@ -1135,15 +1138,15 @@ export { getRateDisplayValue, goBackFromInvalidPolicy, hasAccountingConnections, - hasSyncError, + shouldShowSyncError, hasPolicyFeedsError, - hasCustomUnitsError, - hasEmployeeListError, + shouldShowCustomUnitsError, + shouldShowEmployeeListError, hasIntegrationAutoSync, hasPolicyCategoriesError, - hasPolicyError, - hasPolicyErrorFields, - hasTaxRateError, + shouldShowPolicyError, + shouldShowPolicyErrorFields, + shouldShowTaxRateError, isControlOnAdvancedApprovalMode, isExpensifyTeam, isDeletedPolicyEmployee, diff --git a/src/libs/WorkspacesSettingsUtils.ts b/src/libs/WorkspacesSettingsUtils.ts index f1b79402f86f..ee0a70d3b7fe 100644 --- a/src/libs/WorkspacesSettingsUtils.ts +++ b/src/libs/WorkspacesSettingsUtils.ts @@ -10,7 +10,7 @@ import type {Beta, Policy, PriorityMode, ReimbursementAccount, Report, ReportAct import type {PolicyConnectionSyncProgress, Unit} from '@src/types/onyx/Policy'; import {isConnectionInProgress} from './actions/connections'; import * as CurrencyUtils from './CurrencyUtils'; -import {hasCustomUnitsError, hasEmployeeListError, hasPolicyError, hasSyncError, hasTaxRateError} from './PolicyUtils'; +import {isPolicyAdmin, shouldShowCustomUnitsError, shouldShowEmployeeListError, shouldShowPolicyError, shouldShowSyncError, shouldShowTaxRateError} from './PolicyUtils'; import * as ReportActionsUtils from './ReportActionsUtils'; import * as ReportUtils from './ReportUtils'; import SidebarUtils from './SidebarUtils'; @@ -102,25 +102,31 @@ function hasGlobalWorkspaceSettingsRBR(policies: OnyxCollection, allConn const cleanPolicies = Object.fromEntries(Object.entries(policies ?? {}).filter(([, policy]) => policy?.id)); const errorCheckingMethods: CheckingMethod[] = [ - () => Object.values(cleanPolicies).some(hasPolicyError), - () => Object.values(cleanPolicies).some(hasCustomUnitsError), - () => Object.values(cleanPolicies).some(hasTaxRateError), - () => Object.values(cleanPolicies).some(hasEmployeeListError), + () => Object.values(cleanPolicies).some(shouldShowPolicyError), + () => Object.values(cleanPolicies).some(shouldShowCustomUnitsError), + () => Object.values(cleanPolicies).some(shouldShowTaxRateError), + () => Object.values(cleanPolicies).some(shouldShowEmployeeListError), () => Object.values(cleanPolicies).some((cleanPolicy) => - hasSyncError(cleanPolicy, isConnectionInProgress(allConnectionProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy)), + shouldShowSyncError(cleanPolicy, isConnectionInProgress(allConnectionProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${cleanPolicy?.id}`], cleanPolicy)), ), - () => Object.keys(reimbursementAccount?.errors ?? {}).length > 0, + () => Object.values(cleanPolicies).some((cleanPolicy) => isPolicyAdmin(cleanPolicy) && Object.keys(reimbursementAccount?.errors ?? {}).length > 0), ]; return errorCheckingMethods.some((errorCheckingMethod) => errorCheckingMethod()); } function hasWorkspaceSettingsRBR(policy: Policy) { - const policyMemberError = hasEmployeeListError(policy); - const taxRateError = hasTaxRateError(policy); - - return Object.keys(reimbursementAccount?.errors ?? {}).length > 0 || hasPolicyError(policy) || hasCustomUnitsError(policy) || policyMemberError || taxRateError; + const policyMemberError = shouldShowEmployeeListError(policy); + const taxRateError = shouldShowTaxRateError(policy); + + return ( + (isPolicyAdmin(policy) && Object.keys(reimbursementAccount?.errors ?? {}).length > 0) || + shouldShowPolicyError(policy) || + shouldShowCustomUnitsError(policy) || + policyMemberError || + taxRateError + ); } function getChatTabBrickRoadReport( diff --git a/src/pages/workspace/WorkspaceInitialPage.tsx b/src/pages/workspace/WorkspaceInitialPage.tsx index c5098ed08be7..77f849f7ad5d 100644 --- a/src/pages/workspace/WorkspaceInitialPage.tsx +++ b/src/pages/workspace/WorkspaceInitialPage.tsx @@ -92,7 +92,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac const [cardsList] = useOnyx(`${ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST}${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${route.params?.policyID ?? '-1'}`); - const hasSyncError = PolicyUtils.hasSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy)); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isConnectionInProgress(connectionSyncProgress, policy)); const waitForNavigate = useWaitForNavigation(); const {singleExecution, isExecuting} = useSingleExecution(); const activeRoute = useNavigationState(getTopmostRouteName); @@ -151,7 +151,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac ReimbursementAccount.navigateToBankAccountRoute(policyID); }, [policyID, policyName]); - const hasMembersError = PolicyUtils.hasEmployeeListError(policy); + const hasMembersError = PolicyUtils.shouldShowEmployeeListError(policy); const hasPolicyCategoryError = PolicyUtils.hasPolicyCategoriesError(policyCategories); const hasGeneralSettingsError = !isEmptyObject(policy?.errorFields?.name ?? {}) || @@ -285,7 +285,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, route}: Workspac icon: Expensicons.Coins, action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_TAXES.getRoute(policyID)))), routeName: SCREENS.WORKSPACE.TAXES, - brickRoadIndicator: PolicyUtils.hasTaxRateError(policy) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, + brickRoadIndicator: PolicyUtils.shouldShowTaxRateError(policy) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined, }); } diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index db21700a0c47..16c96054a154 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -333,12 +333,13 @@ function WorkspacesListPage() { title: policy.name, icon: policy.avatarURL ? policy.avatarURL : ReportUtils.getDefaultWorkspaceAvatar(policy.name), action: () => Navigation.navigate(ROUTES.WORKSPACE_INITIAL.getRoute(policy.id)), - brickRoadIndicator: - reimbursementAccountBrickRoadIndicator ?? - PolicyUtils.getPolicyBrickRoadIndicatorStatus( - policy, - isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy.id}`], policy), - ), + brickRoadIndicator: !PolicyUtils.isPolicyAdmin(policy) + ? undefined + : reimbursementAccountBrickRoadIndicator ?? + PolicyUtils.getPolicyBrickRoadIndicatorStatus( + policy, + isConnectionInProgress(allConnectionSyncProgresses?.[`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy.id}`], policy), + ), pendingAction: policy.pendingAction, errors: policy.errors, dismissError: () => dismissWorkspaceError(policy.id, policy.pendingAction), diff --git a/src/pages/workspace/accounting/PolicyAccountingPage.tsx b/src/pages/workspace/accounting/PolicyAccountingPage.tsx index 878a2dcd6b22..5586bad6f179 100644 --- a/src/pages/workspace/accounting/PolicyAccountingPage.tsx +++ b/src/pages/workspace/accounting/PolicyAccountingPage.tsx @@ -97,7 +97,7 @@ function PolicyAccountingPage({policy}: PolicyAccountingPageProps) { connectedIntegration === connectionSyncProgress?.connectionName ? connectionSyncProgress : undefined, ); - const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isSyncInProgress); const hasUnsupportedNDIntegration = !isEmptyObject(policy?.connections) && PolicyUtils.hasUnsupportedIntegration(policy, accountingIntegrations); const tenants = useMemo(() => getXeroTenants(policy), [policy]); diff --git a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx index a7096eb7b30c..38d34be4fb5c 100644 --- a/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx +++ b/src/pages/workspace/categories/WorkspaceCategoriesPage.tsx @@ -79,7 +79,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) { const [policyCategories] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CATEGORIES}${policyId}`); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); - const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const isQuickSettingsFlow = !!backTo; diff --git a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx index a6b7dd8fa48a..900c52b60d26 100644 --- a/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx +++ b/src/pages/workspace/reportFields/WorkspaceReportFieldsPage.tsx @@ -84,7 +84,7 @@ function WorkspaceReportFieldsPage({ const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); - const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); diff --git a/src/pages/workspace/tags/WorkspaceTagsPage.tsx b/src/pages/workspace/tags/WorkspaceTagsPage.tsx index 570dab461c78..5e538ba90539 100644 --- a/src/pages/workspace/tags/WorkspaceTagsPage.tsx +++ b/src/pages/workspace/tags/WorkspaceTagsPage.tsx @@ -73,7 +73,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) { const {environmentURL} = useEnvironment(); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); - const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); const [policyTagLists, isMultiLevelTags] = useMemo(() => [PolicyUtils.getTagLists(policyTags), PolicyUtils.isMultiLevelTags(policyTags)], [policyTags]); diff --git a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx index 207ecfc30706..d6009efd3565 100644 --- a/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx +++ b/src/pages/workspace/taxes/WorkspaceTaxesPage.tsx @@ -65,7 +65,7 @@ function WorkspaceTaxesPage({ const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy); const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`); const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy); - const hasSyncError = PolicyUtils.hasSyncError(policy, isSyncInProgress); + const hasSyncError = PolicyUtils.shouldShowSyncError(policy, isSyncInProgress); const isConnectedToAccounting = Object.keys(policy?.connections ?? {}).length > 0; const currentConnectionName = PolicyUtils.getCurrentConnectionName(policy); From 128de7fcd2472708aef1a4ec7b2b8494e67ab421 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 23 Nov 2024 01:19:22 +0300 Subject: [PATCH 2/3] updated tests --- tests/unit/useIndicatorStatusTest.tsx | 41 +++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/tests/unit/useIndicatorStatusTest.tsx b/tests/unit/useIndicatorStatusTest.tsx index fad619419227..8ffa4ac337b4 100644 --- a/tests/unit/useIndicatorStatusTest.tsx +++ b/tests/unit/useIndicatorStatusTest.tsx @@ -9,12 +9,13 @@ import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; -const getMockForStatus = (status: IndicatorStatus) => +const getMockForStatus = (status: IndicatorStatus, isAdmin = true) => ({ [`${ONYXKEYS.COLLECTION.POLICY}1` as const]: { id: '1', name: 'Workspace 1', owner: 'johndoe12@expensify.com', + role: isAdmin ? 'admin' : 'user', customUnits: status === CONST.INDICATOR_STATUS.HAS_CUSTOM_UNITS_ERROR ? { @@ -28,6 +29,7 @@ const getMockForStatus = (status: IndicatorStatus) => id: '2', name: 'Workspace 2', owner: 'johndoe12@expensify.com', + role: isAdmin ? 'admin' : 'user', errors: status === CONST.INDICATOR_STATUS.HAS_POLICY_ERRORS ? { @@ -39,6 +41,7 @@ const getMockForStatus = (status: IndicatorStatus) => id: '3', name: 'Workspace 3', owner: 'johndoe12@expensify.com', + role: isAdmin ? 'admin' : 'user', employeeList: { // eslint-disable-next-line @typescript-eslint/naming-convention 'johndoe12@expensify.com': { @@ -56,6 +59,7 @@ const getMockForStatus = (status: IndicatorStatus) => id: '4', name: 'Workspace 4', owner: 'johndoe12@expensify.com', + role: isAdmin ? 'admin' : 'auditor', connections: status === CONST.INDICATOR_STATUS.HAS_SYNC_ERRORS ? { @@ -132,7 +136,7 @@ type TestCase = { name: string; indicatorColor: string; status: IndicatorStatus; - policyIDWithErrors: string | undefined; + policyIDWithErrors?: string; }; const TEST_CASES: TestCase[] = [ @@ -210,6 +214,29 @@ const TEST_CASES: TestCase[] = [ }, ]; +const TEST_CASES_NON_ADMIN: TestCase[] = [ + { + name: 'has custom units error but not an admin so no RBR', + indicatorColor: defaultTheme.success, + status: CONST.INDICATOR_STATUS.HAS_CUSTOM_UNITS_ERROR, + }, + { + name: 'has policy errors but not an admin so no RBR', + indicatorColor: defaultTheme.success, + status: CONST.INDICATOR_STATUS.HAS_POLICY_ERRORS, + }, + { + name: 'has employee list error but not an admin so no RBR', + indicatorColor: defaultTheme.success, + status: CONST.INDICATOR_STATUS.HAS_EMPLOYEE_LIST_ERROR, + }, + { + name: 'has sync errors but not an admin so no RBR', + indicatorColor: defaultTheme.success, + status: CONST.INDICATOR_STATUS.HAS_SYNC_ERRORS, + }, +]; + describe('useIndicatorStatusTest', () => { beforeAll(() => { Onyx.init({ @@ -236,4 +263,14 @@ describe('useIndicatorStatusTest', () => { expect(policyIDWithErrors).toBe(testCase.policyIDWithErrors); }); }); + describe.each(TEST_CASES_NON_ADMIN)('$name', (testCase) => { + beforeAll(() => { + return Onyx.multiSet(getMockForStatus(testCase.status, false)).then(waitForBatchedUpdates); + }); + it('returns correct indicatorColor', () => { + const {result} = renderHook(() => useIndicatorStatus()); + const {indicatorColor} = result.current; + expect(indicatorColor).toBe(testCase.indicatorColor); + }); + }); }); From 631f90851202468e199f6f53c9b4aa08f9963bc2 Mon Sep 17 00:00:00 2001 From: FitseTLT Date: Sat, 23 Nov 2024 01:27:35 +0300 Subject: [PATCH 3/3] updated shouldShowEmployeeListError --- src/libs/PolicyUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index e53c60ab3bb2..22d2adedc65d 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -83,7 +83,7 @@ const isPolicyAdmin = (policy: OnyxInputOrEntry | SearchPolicy, currentU * Checks if we have any errors stored within the policy?.employeeList. Determines whether we should show a red brick road error or not. */ function shouldShowEmployeeListError(policy: OnyxEntry): boolean { - return Object.values(policy?.employeeList ?? {}).some((employee) => Object.keys(employee?.errors ?? {}).length > 0); + return isPolicyAdmin(policy) && Object.values(policy?.employeeList ?? {}).some((employee) => Object.keys(employee?.errors ?? {}).length > 0); } /**