Skip to content

Commit

Permalink
updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
FitseTLT committed Nov 22, 2024
1 parent 40bde04 commit 128de7f
Showing 1 changed file with 39 additions and 2 deletions.
41 changes: 39 additions & 2 deletions tests/unit/useIndicatorStatusTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
role: isAdmin ? 'admin' : 'user',
customUnits:
status === CONST.INDICATOR_STATUS.HAS_CUSTOM_UNITS_ERROR
? {
Expand All @@ -28,6 +29,7 @@ const getMockForStatus = (status: IndicatorStatus) =>
id: '2',
name: 'Workspace 2',
owner: '[email protected]',
role: isAdmin ? 'admin' : 'user',
errors:
status === CONST.INDICATOR_STATUS.HAS_POLICY_ERRORS
? {
Expand All @@ -39,6 +41,7 @@ const getMockForStatus = (status: IndicatorStatus) =>
id: '3',
name: 'Workspace 3',
owner: '[email protected]',
role: isAdmin ? 'admin' : 'user',
employeeList: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'[email protected]': {
Expand All @@ -56,6 +59,7 @@ const getMockForStatus = (status: IndicatorStatus) =>
id: '4',
name: 'Workspace 4',
owner: '[email protected]',
role: isAdmin ? 'admin' : 'auditor',
connections:
status === CONST.INDICATOR_STATUS.HAS_SYNC_ERRORS
? {
Expand Down Expand Up @@ -132,7 +136,7 @@ type TestCase = {
name: string;
indicatorColor: string;
status: IndicatorStatus;
policyIDWithErrors: string | undefined;
policyIDWithErrors?: string;
};

const TEST_CASES: TestCase[] = [
Expand Down Expand Up @@ -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({
Expand All @@ -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);
});
});
});

0 comments on commit 128de7f

Please sign in to comment.