Skip to content

Commit 0ce0a09

Browse files
committed
Mock fileDownload utility in tests to isolate file reading functionality
1 parent cad3e6f commit 0ce0a09

File tree

79 files changed

+302
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+302
-0
lines changed

tests/actions/OnyxUpdateManagerTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ jest.mock('@hooks/useScreenWrapperTransitionStatus', () => ({
3434
}),
3535
}));
3636

37+
jest.mock('@libs/fileDownload/FileUtils', () => ({
38+
readFileAsync: jest.fn(),
39+
}));
40+
3741
const App = AppImport as AppActionsMock;
3842
const ApplyUpdates = ApplyUpdatesImport as ApplyUpdatesMock;
3943
const OnyxUpdateManagerUtils = OnyxUpdateManagerUtilsImport as OnyxUpdateManagerUtilsMock;

tests/actions/PolicyCategoryTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import * as TestHelper from '../utils/TestHelper';
99
import type {MockFetch} from '../utils/TestHelper';
1010
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1111

12+
jest.mock('@libs/fileDownload/FileUtils', () => ({
13+
readFileAsync: jest.fn(),
14+
}));
15+
1216
OnyxUpdateManager();
1317
describe('actions/PolicyCategory', () => {
1418
beforeAll(() => {

tests/actions/PolicyMemberTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import * as TestHelper from '../utils/TestHelper';
1515
import type {MockFetch} from '../utils/TestHelper';
1616
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1717

18+
jest.mock('@libs/fileDownload/FileUtils', () => ({
19+
readFileAsync: jest.fn(),
20+
}));
21+
1822
OnyxUpdateManager();
1923
describe('actions/PolicyMember', () => {
2024
beforeAll(() => {

tests/actions/PolicyProfileTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import * as TestHelper from '../utils/TestHelper';
99
import type {MockFetch} from '../utils/TestHelper';
1010
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1111

12+
jest.mock('@libs/fileDownload/FileUtils', () => ({
13+
readFileAsync: jest.fn(),
14+
}));
15+
1216
OnyxUpdateManager();
1317
describe('actions/PolicyProfile', () => {
1418
beforeAll(() => {

tests/actions/PolicyTagTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ import * as TestHelper from '../utils/TestHelper';
1010
import type {MockFetch} from '../utils/TestHelper';
1111
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1212

13+
jest.mock('@libs/fileDownload/FileUtils', () => ({
14+
readFileAsync: jest.fn(),
15+
}));
16+
1317
OnyxUpdateManager();
1418
describe('actions/Policy', () => {
1519
beforeAll(() => {

tests/actions/PolicyTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import * as TestHelper from '../utils/TestHelper';
1212
import type {MockFetch} from '../utils/TestHelper';
1313
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1414

15+
jest.mock('@libs/fileDownload/FileUtils', () => ({
16+
readFileAsync: jest.fn(),
17+
}));
18+
1519
const ESH_EMAIL = 'eshgupta1217@gmail.com';
1620
const ESH_ACCOUNT_ID = 1;
1721
const ESH_PARTICIPANT_ADMINS_ROOM: Participant = {notificationPreference: CONST.REPORT.NOTIFICATION_PREFERENCE.ALWAYS};

tests/actions/QueuedOnyxUpdatesTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ jest.mock('@src/CONFIG', () => ({
4848
IS_TEST_ENV: false,
4949
}));
5050

51+
jest.mock('@libs/fileDownload/FileUtils', () => ({
52+
readFileAsync: jest.fn(),
53+
}));
54+
5155
function getOnyxUpdateValue<T>(key: string): T | undefined {
5256
return queuedOnyxUpdates.find((item) => item.key === key)?.value as T | undefined;
5357
}

tests/actions/ReportFieldTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
2020
type PolicyReportFieldWithOfflineFeedback = Record<string, OnyxValueWithOfflineFeedback<PolicyReportField>>;
2121
type PolicyReportFieldWithoutOfflineFeedback = Record<string, PolicyReportField>;
2222

23+
jest.mock('@libs/fileDownload/FileUtils', () => ({
24+
readFileAsync: jest.fn(),
25+
}));
26+
2327
OnyxUpdateManager();
2428
describe('actions/ReportField', () => {
2529
function connectToFetchPolicy(policyID: string): Promise<OnyxEntry<PolicyType>> {

tests/actions/ReportTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ jest.mock('@hooks/useScreenWrapperTransitionStatus', () => ({
4040
didScreenTransitionEnd: true,
4141
}),
4242
}));
43+
jest.mock('@libs/fileDownload/FileUtils', () => ({
44+
readFileAsync: jest.fn(),
45+
}));
46+
4347
const originalXHR = HttpUtils.xhr;
4448
OnyxUpdateManager();
4549
describe('actions/Report', () => {

tests/actions/SessionTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ HttpUtils.xhr = jest.fn<typeof HttpUtils.xhr>();
2323
// Mocked to ensure push notifications are subscribed/unsubscribed as the session changes
2424
jest.mock('@libs/Notification/PushNotification');
2525

26+
jest.mock('@libs/fileDownload/FileUtils', () => ({
27+
readFileAsync: jest.fn(),
28+
}));
29+
2630
Onyx.init({
2731
keys: ONYXKEYS,
2832
});

tests/ui/GroupChatNameTests.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ let transitionEndCB: () => void;
4141

4242
jest.mock('@react-navigation/native');
4343

44+
jest.mock('@libs/fileDownload/FileUtils', () => ({
45+
readFileAsync: jest.fn(),
46+
}));
47+
4448
TestHelper.setupApp();
4549

4650
const REPORT_ID = '1';

tests/ui/LHNItemsPresence.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import wrapOnyxWithWaitForBatchedUpdates from '../utils/wrapOnyxWithWaitForBatch
2424
jest.mock('@libs/Permissions');
2525
jest.mock('@src/hooks/useActiveWorkspaceFromNavigationState');
2626
jest.mock('@src/hooks/useIsCurrentRouteHome');
27+
jest.mock('@libs/fileDownload/FileUtils', () => ({
28+
readFileAsync: jest.fn(),
29+
}));
2730

2831
type LazyLoadLHNTestUtils = {
2932
fakePersonalDetails: PersonalDetailsList;

tests/ui/PaginationTest.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ jest.mock('@react-navigation/native');
2525
jest.mock('../../src/libs/Notification/LocalNotification');
2626
jest.mock('../../src/components/Icon/Expensicons');
2727
jest.mock('../../src/components/ConfirmedRoute.tsx');
28+
jest.mock('@libs/fileDownload/FileUtils', () => ({
29+
readFileAsync: jest.fn(),
30+
}));
2831

2932
TestHelper.setupApp();
3033
const fetchMock = TestHelper.setupGlobalFetchMock();

tests/ui/ResizeScreenTests.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ jest.mock('@libs/getIsNarrowLayout', () => jest.fn());
2121
jest.mock('@pages/settings/InitialSettingsPage');
2222
jest.mock('@pages/settings/Profile/ProfilePage');
2323
jest.mock('@libs/Navigation/AppNavigator/createCustomBottomTabNavigator/BottomTabBar');
24+
jest.mock('@libs/fileDownload/FileUtils', () => ({
25+
readFileAsync: jest.fn(),
26+
}));
2427

2528
const DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE: ResponsiveLayoutResult = {
2629
shouldUseNarrowLayout: true,

tests/ui/SwitchToExpensifyClassicTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ jest.setTimeout(60000);
1818

1919
jest.mock('@react-navigation/native');
2020

21+
jest.mock('@libs/fileDownload/FileUtils', () => ({
22+
readFileAsync: jest.fn(),
23+
}));
24+
2125
TestHelper.setupApp();
2226
TestHelper.setupGlobalFetchMock();
2327

tests/ui/UnreadIndicatorsTest.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jest.mock('@react-navigation/native');
3636
jest.mock('../../src/libs/Notification/LocalNotification');
3737
jest.mock('../../src/components/Icon/Expensicons');
3838
jest.mock('../../src/components/ConfirmedRoute.tsx');
39+
jest.mock('@libs/fileDownload/FileUtils', () => ({
40+
readFileAsync: jest.fn(),
41+
}));
3942

4043
TestHelper.setupApp();
4144
TestHelper.setupGlobalFetchMock();

tests/ui/ValidateLoginPageTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ import CONST from '@src/CONST';
99
import ONYXKEYS from '@src/ONYXKEYS';
1010
import SCREENS from '@src/SCREENS';
1111

12+
jest.mock('@libs/fileDownload/FileUtils', () => ({
13+
readFileAsync: jest.fn(),
14+
}));
15+
1216
const RootStack = createResponsiveStackNavigator<PublicScreensParamList>();
1317

1418
const renderPage = (initialParams: PublicScreensParamList[typeof SCREENS.VALIDATE_LOGIN]) => {

tests/ui/WorkspaceCategoriesTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ import * as LHNTestUtils from '../utils/LHNTestUtils';
2020
import * as TestHelper from '../utils/TestHelper';
2121
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
2222

23+
jest.mock('@libs/fileDownload/FileUtils', () => ({
24+
readFileAsync: jest.fn(),
25+
}));
26+
2327
TestHelper.setupGlobalFetchMock();
2428

2529
const RootStack = createResponsiveStackNavigator<FullScreenNavigatorParamList>();

tests/ui/WorkspaceSwitcherTest.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ jest.mock('@react-navigation/native', () => {
2626
triggerTransitionEnd: jest.fn(),
2727
};
2828
});
29+
30+
jest.mock('@libs/fileDownload/FileUtils', () => ({
31+
readFileAsync: jest.fn(),
32+
}));
33+
2934
TestHelper.setupApp();
3035

3136
async function signInAndGetApp(): Promise<void> {

tests/ui/WorkspaceUpgradeTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import * as TestHelper from '../utils/TestHelper';
1616
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1717
import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct';
1818

19+
jest.mock('@libs/fileDownload/FileUtils', () => ({
20+
readFileAsync: jest.fn(),
21+
}));
22+
1923
TestHelper.setupGlobalFetchMock();
2024

2125
const RootStack = createResponsiveStackNavigator<SettingsNavigatorParamList>();

tests/ui/components/CheckboxWithLabel.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import CheckboxWithLabel from '@src/components/CheckboxWithLabel';
44
import type {CheckboxWithLabelProps} from '@src/components/CheckboxWithLabel';
55
import Text from '@src/components/Text';
66

7+
jest.mock('@libs/fileDownload/FileUtils', () => ({
8+
readFileAsync: jest.fn(),
9+
}));
10+
711
const LABEL = 'Agree to Terms';
812
describe('CheckboxWithLabel Component', () => {
913
const mockOnInputChange = jest.fn();

tests/ui/components/HeaderViewTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jest.mock('@react-navigation/native', () => {
1616
};
1717
});
1818

19+
jest.mock('@libs/fileDownload/FileUtils', () => ({
20+
readFileAsync: jest.fn(),
21+
}));
22+
1923
describe('HeaderView', () => {
2024
afterEach(() => {
2125
jest.clearAllMocks();

tests/ui/components/ProductTrainingContextProvider.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ jest.mock('@hooks/useResponsiveLayout', () => ({
1515
default: jest.fn(),
1616
}));
1717

18+
jest.mock('@libs/fileDownload/FileUtils', () => ({
19+
readFileAsync: jest.fn(),
20+
}));
21+
1822
const DEFAULT_USE_RESPONSIVE_LAYOUT_VALUE = {
1923
shouldUseNarrowLayout: true,
2024
isSmallScreenWidth: true,

tests/ui/components/ReportPreviewTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ jest.mock('@react-native-community/geolocation', () => ({
2323
setRNConfiguration: jest.fn(),
2424
}));
2525

26+
jest.mock('@libs/fileDownload/FileUtils', () => ({
27+
readFileAsync: jest.fn(),
28+
}));
29+
2630
describe('ReportPreview', () => {
2731
afterEach(() => {
2832
jest.clearAllMocks();

tests/unit/BaseSelectionListTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ jest.mock('@react-navigation/native', () => {
2424
};
2525
});
2626

27+
jest.mock('@libs/fileDownload/FileUtils', () => ({
28+
readFileAsync: jest.fn(),
29+
}));
30+
2731
describe('BaseSelectionList', () => {
2832
const onSelectRowMock = jest.fn();
2933

tests/unit/CalendarPickerTest.tsx

+4
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ jest.mock('../../src/hooks/useLocalize', () =>
3636
})),
3737
);
3838

39+
jest.mock('@libs/fileDownload/FileUtils', () => ({
40+
readFileAsync: jest.fn(),
41+
}));
42+
3943
describe('CalendarPicker', () => {
4044
test('renders calendar component', () => {
4145
render(<CalendarPicker />);

tests/unit/CardUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ import * as CardUtils from '@src/libs/CardUtils';
44
import type * as OnyxTypes from '@src/types/onyx';
55
import type {CompanyCardFeedWithNumber} from '@src/types/onyx/CardFeeds';
66

7+
jest.mock('@libs/fileDownload/FileUtils', () => ({
8+
readFileAsync: jest.fn(),
9+
}));
10+
711
const shortDate = '0924';
812
const shortDateSlashed = '09/24';
913
const shortDateHyphen = '09-24';

tests/unit/CardsSectionUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ jest.mock('@libs/SubscriptionUtils', () => ({
2929
getSubscriptionStatus: () => mockGetSubscriptionStatus() as BillingStatusResult,
3030
}));
3131

32+
jest.mock('@libs/fileDownload/FileUtils', () => ({
33+
readFileAsync: jest.fn(),
34+
}));
35+
3236
describe('getNextBillingDate', () => {
3337
beforeAll(() => {
3438
jest.useFakeTimers();

tests/unit/CategoryOptionListUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import * as CategoryOptionsListUtils from '@libs/CategoryOptionListUtils';
33
import type {PolicyCategories} from '@src/types/onyx';
44
import type {PendingAction} from '@src/types/onyx/OnyxCommon';
55

6+
jest.mock('@libs/fileDownload/FileUtils', () => ({
7+
readFileAsync: jest.fn(),
8+
}));
9+
610
describe('CategoryOptionListUtils', () => {
711
it('getCategoryListSections()', () => {
812
const search = 'Food';

tests/unit/CurrencyUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1212
// - update currencyList.json
1313
import currencyList from './currencyList.json';
1414

15+
jest.mock('@libs/fileDownload/FileUtils', () => ({
16+
readFileAsync: jest.fn(),
17+
}));
18+
1519
const currencyCodeList = Object.keys(currencyList);
1620
const AVAILABLE_LOCALES = [CONST.LOCALES.EN, CONST.LOCALES.ES];
1721

tests/unit/DateUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ import ONYXKEYS from '@src/ONYXKEYS';
88
import type {SelectedTimezone} from '@src/types/onyx/PersonalDetails';
99
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1010

11+
jest.mock('@libs/fileDownload/FileUtils', () => ({
12+
readFileAsync: jest.fn(),
13+
}));
14+
1115
const LOCALE = CONST.LOCALES.EN;
1216
const UTC = 'UTC';
1317
describe('DateUtils', () => {

tests/unit/DebugUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import createRandomReportAction from '../utils/collections/reportActions';
1313
import createRandomReport from '../utils/collections/reports';
1414
import createRandomTransaction from '../utils/collections/transaction';
1515

16+
jest.mock('@libs/fileDownload/FileUtils', () => ({
17+
readFileAsync: jest.fn(),
18+
}));
19+
1620
const MOCK_REPORT: Report = {
1721
...createRandomReport(0),
1822
};

tests/unit/DistanceRequestUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import DistanceRequestUtils from '@libs/DistanceRequestUtils';
22
import type {Unit} from '@src/types/onyx/Policy';
33

4+
jest.mock('@libs/fileDownload/FileUtils', () => ({
5+
readFileAsync: jest.fn(),
6+
}));
7+
48
describe('DistanceRequestUtils', () => {
59
describe('getDistanceRequestAmount', () => {
610
test.each([

tests/unit/EmojiTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import type {Emoji} from '@assets/emojis/types';
33
import {buildEmojisTrie} from '@libs/EmojiTrie';
44
import * as EmojiUtils from '@libs/EmojiUtils';
55

6+
jest.mock('@libs/fileDownload/FileUtils', () => ({
7+
readFileAsync: jest.fn(),
8+
}));
9+
610
describe('EmojiTest', () => {
711
beforeAll(async () => {
812
await importEmojiLocale('en');

tests/unit/ErrorUtilsTest.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import * as ErrorUtils from '@src/libs/ErrorUtils';
22
import type {Errors} from '@src/types/onyx/OnyxCommon';
33

4+
jest.mock('@libs/fileDownload/FileUtils', () => ({
5+
readFileAsync: jest.fn(),
6+
}));
7+
48
describe('ErrorUtils', () => {
59
test('should add a new error message for a given inputID', () => {
610
const errors: Errors = {};

tests/unit/FileUtilsTest.ts

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import * as FileUtils from '../../src/libs/fileDownload/FileUtils';
44

55
jest.useFakeTimers();
66

7+
jest.mock('@src/libs/prepareRequestPayload/index.native');
8+
79
describe('FileUtils', () => {
810
describe('splitExtensionFromFileName', () => {
911
it('should return correct file name and extension', () => {

0 commit comments

Comments
 (0)