Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion tests/unit/PolicyUtilsTest.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
/* eslint-disable @typescript-eslint/naming-convention */
import Onyx from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import DateUtils from '@libs/DateUtils';
import {getActivePolicies, getRateDisplayValue, getSubmitToAccountID, getUnitRateValue} from '@libs/PolicyUtils';
import {getActivePolicies, getRateDisplayValue, getSubmitToAccountID, getUnitRateValue, shouldShowPolicy} from '@libs/PolicyUtils';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, Policy, PolicyEmployeeList, Report, Transaction} from '@src/types/onyx';
import createCollection from '../utils/collections/createCollection';
import createRandomPolicy from '../utils/collections/policies';
import createRandomReport from '../utils/collections/reports';
import createRandomTransaction from '../utils/collections/transaction';
import * as TestHelper from '../utils/TestHelper';
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatchedUpdates';

const CARLOS_EMAIL = 'cmartins@expensifail.com';
const CARLOS_ACCOUNT_ID = 1;
function toLocaleDigitMock(dot: string): string {
return dot;
}
Expand Down Expand Up @@ -427,4 +432,46 @@ describe('PolicyUtils', () => {
});
});
});
describe('shouldShowPolicy', () => {
beforeAll(() => {
Onyx.init({
keys: ONYXKEYS,
initialKeyStates: {
[ONYXKEYS.SESSION]: {accountID: CARLOS_ACCOUNT_ID, email: CARLOS_EMAIL},
},
});
});

beforeEach(() => {
global.fetch = TestHelper.getGlobalFetchMock();
return Onyx.clear().then(waitForBatchedUpdates);
});
it('should return false', () => {
// Given an archived paid policy.
const policy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.CORPORATE),
role: '',
};
const result = shouldShowPolicy(policy as OnyxEntry<Policy>, false, CARLOS_EMAIL);
// The result should be false since it is an archived paid policy.
expect(result).toBe(false);
});
it('should return true', () => {
// Given a paid policy.
const policy = {...createRandomPolicy(1, CONST.POLICY.TYPE.CORPORATE), pendingAction: null};
const result = shouldShowPolicy(policy as OnyxEntry<Policy>, false, CARLOS_EMAIL);
// The result should be true, since it is an active paid policy.
expect(result).toBe(true);
});
it('should returnfalse', () => {
// Given a control workspace which is pending delete.
const policy = {
...createRandomPolicy(1, CONST.POLICY.TYPE.CORPORATE),
pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
};
const result = shouldShowPolicy(policy as OnyxEntry<Policy>, false, CARLOS_EMAIL);
// The result should be false since it is a policy which is pending deletion.
expect(result).toEqual(false);
});
});
});