Skip to content

Commit

Permalink
Merge pull request #53816 from truph01/fix/53659
Browse files Browse the repository at this point in the history
fix: Hmm it's not here in RHP is displayed after deleting a workspace
  • Loading branch information
grgia authored Jan 22, 2025
2 parents 9018751 + fbb349b commit 55f4684
Showing 1 changed file with 48 additions and 1 deletion.
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 = '[email protected]';
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);
});
});
});

0 comments on commit 55f4684

Please sign in to comment.