Skip to content

Commit bc698ea

Browse files
committed
Refactor imports to use named exports for consistency and clarity
1 parent 0ce0a09 commit bc698ea

22 files changed

+473
-438
lines changed

tests/actions/OnyxUpdateManagerTest.ts

+16-10
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,21 @@ import type {OnyxEntry} from 'react-native-onyx';
22
import Onyx from 'react-native-onyx';
33
import OnyxUtils from 'react-native-onyx/dist/OnyxUtils';
44
import type {AppActionsMock} from '@libs/actions/__mocks__/App';
5+
6+
/* eslint-disable-next-line no-restricted-syntax */
57
import * as AppImport from '@libs/actions/App';
68
import applyOnyxUpdatesReliably from '@libs/actions/applyOnyxUpdatesReliably';
7-
import * as OnyxUpdateManagerExports from '@libs/actions/OnyxUpdateManager';
9+
import {queryPromise, resetDeferralLogicVariables} from '@libs/actions/OnyxUpdateManager';
810
import type {DeferredUpdatesDictionary} from '@libs/actions/OnyxUpdateManager/types';
11+
12+
/* eslint-disable-next-line no-restricted-syntax */
913
import * as OnyxUpdateManagerUtilsImport from '@libs/actions/OnyxUpdateManager/utils';
1014
import type {OnyxUpdateManagerUtilsMock} from '@libs/actions/OnyxUpdateManager/utils/__mocks__';
1115
import type {ApplyUpdatesMock} from '@libs/actions/OnyxUpdateManager/utils/__mocks__/applyUpdates';
16+
17+
/* eslint-disable-next-line no-restricted-syntax */
1218
import * as ApplyUpdatesImport from '@libs/actions/OnyxUpdateManager/utils/applyUpdates';
13-
import * as SequentialQueue from '@libs/Network/SequentialQueue';
19+
import {isPaused, isRunning} from '@libs/Network/SequentialQueue';
1420
import CONST from '@src/CONST';
1521
import OnyxUpdateManager from '@src/libs/actions/OnyxUpdateManager';
1622
import ONYXKEYS from '@src/ONYXKEYS';
@@ -142,7 +148,7 @@ describe('actions/OnyxUpdateManager', () => {
142148

143149
OnyxUpdateManagerUtils.mockValues.beforeValidateAndApplyDeferredUpdates = undefined;
144150
App.mockValues.missingOnyxUpdatesToBeApplied = undefined;
145-
OnyxUpdateManagerExports.resetDeferralLogicVariables();
151+
resetDeferralLogicVariables();
146152
});
147153

148154
it('should trigger Onyx update gap handling', async () => {
@@ -162,7 +168,7 @@ describe('actions/OnyxUpdateManager', () => {
162168
applyOnyxUpdatesReliably(mockUpdate4);
163169
applyOnyxUpdatesReliably(mockUpdate3);
164170

165-
return OnyxUpdateManagerExports.queryPromise.then(() => {
171+
return queryPromise.then(() => {
166172
const expectedResult: Record<string, Partial<OnyxTypes.ReportAction>> = {
167173
report2: {
168174
...exampleReportAction,
@@ -208,7 +214,7 @@ describe('actions/OnyxUpdateManager', () => {
208214
};
209215

210216
return firstGetMissingOnyxUpdatesCallFinished
211-
.then(() => OnyxUpdateManagerExports.queryPromise)
217+
.then(() => queryPromise)
212218
.then(() => {
213219
const expectedResult: Record<string, Partial<OnyxTypes.ReportAction>> = {
214220
report2: {
@@ -252,15 +258,15 @@ describe('actions/OnyxUpdateManager', () => {
252258
const assertAfterFirstGetMissingOnyxUpdates = () => {
253259
// While the fetching of missing udpates and the validation and application of the deferred updaes is running,
254260
// the SequentialQueue should be paused.
255-
expect(SequentialQueue.isPaused()).toBeTruthy();
261+
expect(isPaused()).toBeTruthy();
256262
expect(App.getMissingOnyxUpdates).toHaveBeenCalledTimes(1);
257263
expect(App.getMissingOnyxUpdates).toHaveBeenNthCalledWith(1, 1, 2);
258264
};
259265

260266
const assertAfterSecondGetMissingOnyxUpdates = () => {
261267
// The SequentialQueue should still be paused.
262-
expect(SequentialQueue.isPaused()).toBeTruthy();
263-
expect(SequentialQueue.isRunning()).toBeFalsy();
268+
expect(isPaused()).toBeTruthy();
269+
expect(isRunning()).toBeFalsy();
264270
expect(App.getMissingOnyxUpdates).toHaveBeenCalledTimes(2);
265271
expect(App.getMissingOnyxUpdates).toHaveBeenNthCalledWith(2, 3, 4);
266272
};
@@ -281,10 +287,10 @@ describe('actions/OnyxUpdateManager', () => {
281287
return Promise.resolve();
282288
};
283289

284-
return OnyxUpdateManagerExports.queryPromise.then(() => {
290+
return queryPromise.then(() => {
285291
// Once the OnyxUpdateManager has finished filling the gaps, the SequentialQueue should be unpaused again.
286292
// It must not necessarily be running, because it might not have been flushed yet.
287-
expect(SequentialQueue.isPaused()).toBeFalsy();
293+
expect(isPaused()).toBeFalsy();
288294
expect(App.getMissingOnyxUpdates).toHaveBeenCalledTimes(2);
289295
});
290296
});

tests/actions/PolicyTagTest.ts

+16-16
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import Onyx from 'react-native-onyx';
22
import OnyxUpdateManager from '@libs/actions/OnyxUpdateManager';
3-
import * as Tag from '@userActions/Policy/Tag';
3+
import {createPolicyTag, deletePolicyTags, renamePolicyTag, renamePolicyTaglist, setPolicyRequiresTag, setWorkspaceTagEnabled} from '@userActions/Policy/Tag';
44
import CONST from '@src/CONST';
55
import ONYXKEYS from '@src/ONYXKEYS';
66
import type {PolicyTags} from '@src/types/onyx';
77
import createRandomPolicy from '../utils/collections/policies';
88
import createRandomPolicyTags from '../utils/collections/policyTags';
9-
import * as TestHelper from '../utils/TestHelper';
9+
import {getGlobalFetchMock} from '../utils/TestHelper';
1010
import type {MockFetch} from '../utils/TestHelper';
1111
import waitForBatchedUpdates from '../utils/waitForBatchedUpdates';
1212

@@ -24,7 +24,7 @@ describe('actions/Policy', () => {
2424

2525
let mockFetch: MockFetch;
2626
beforeEach(() => {
27-
global.fetch = TestHelper.getGlobalFetchMock();
27+
global.fetch = getGlobalFetchMock();
2828
mockFetch = fetch as MockFetch;
2929
return Onyx.clear().then(waitForBatchedUpdates);
3030
});
@@ -38,7 +38,7 @@ describe('actions/Policy', () => {
3838

3939
return Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy)
4040
.then(() => {
41-
Tag.setPolicyRequiresTag(fakePolicy.id, true);
41+
setPolicyRequiresTag(fakePolicy.id, true);
4242
return waitForBatchedUpdates();
4343
})
4444
.then(
@@ -85,7 +85,7 @@ describe('actions/Policy', () => {
8585

8686
return Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy)
8787
.then(() => {
88-
Tag.setPolicyRequiresTag(fakePolicy.id, false);
88+
setPolicyRequiresTag(fakePolicy.id, false);
8989
return waitForBatchedUpdates();
9090
})
9191
.then(
@@ -133,7 +133,7 @@ describe('actions/Policy', () => {
133133
return Onyx.set(`${ONYXKEYS.COLLECTION.POLICY}${fakePolicy.id}`, fakePolicy)
134134
.then(() => {
135135
mockFetch?.fail?.();
136-
Tag.setPolicyRequiresTag(fakePolicy.id, false);
136+
setPolicyRequiresTag(fakePolicy.id, false);
137137
return waitForBatchedUpdates();
138138
})
139139

@@ -174,7 +174,7 @@ describe('actions/Policy', () => {
174174
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
175175
})
176176
.then(() => {
177-
Tag.renamePolicyTaglist(
177+
renamePolicyTaglist(
178178
fakePolicy.id,
179179
{
180180
oldName: oldTagListName,
@@ -242,7 +242,7 @@ describe('actions/Policy', () => {
242242
.then(() => {
243243
mockFetch?.fail?.();
244244

245-
Tag.renamePolicyTaglist(
245+
renamePolicyTaglist(
246246
fakePolicy.id,
247247
{
248248
oldName: oldTagListName,
@@ -292,7 +292,7 @@ describe('actions/Policy', () => {
292292
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
293293
})
294294
.then(() => {
295-
Tag.createPolicyTag(fakePolicy.id, newTagName);
295+
createPolicyTag(fakePolicy.id, newTagName);
296296
return waitForBatchedUpdates();
297297
})
298298
.then(
@@ -354,7 +354,7 @@ describe('actions/Policy', () => {
354354
.then(() => {
355355
mockFetch?.fail?.();
356356

357-
Tag.createPolicyTag(fakePolicy.id, newTagName);
357+
createPolicyTag(fakePolicy.id, newTagName);
358358
return waitForBatchedUpdates();
359359
})
360360
.then(mockFetch?.resume)
@@ -401,7 +401,7 @@ describe('actions/Policy', () => {
401401
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
402402
})
403403
.then(() => {
404-
Tag.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
404+
setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
405405
return waitForBatchedUpdates();
406406
})
407407
.then(
@@ -474,7 +474,7 @@ describe('actions/Policy', () => {
474474
.then(() => {
475475
mockFetch?.fail?.();
476476

477-
Tag.setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
477+
setWorkspaceTagEnabled(fakePolicy.id, tagsToUpdate, 0);
478478
return waitForBatchedUpdates();
479479
})
480480
.then(mockFetch?.resume)
@@ -520,7 +520,7 @@ describe('actions/Policy', () => {
520520
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
521521
})
522522
.then(() => {
523-
Tag.renamePolicyTag(
523+
renamePolicyTag(
524524
fakePolicy.id,
525525
{
526526
oldName: oldTagName ?? '',
@@ -590,7 +590,7 @@ describe('actions/Policy', () => {
590590
.then(() => {
591591
mockFetch?.fail?.();
592592

593-
Tag.renamePolicyTag(
593+
renamePolicyTag(
594594
fakePolicy.id,
595595
{
596596
oldName: oldTagName,
@@ -639,7 +639,7 @@ describe('actions/Policy', () => {
639639
Onyx.set(`${ONYXKEYS.COLLECTION.POLICY_TAGS}${fakePolicy.id}`, fakePolicyTags);
640640
})
641641
.then(() => {
642-
Tag.deletePolicyTags(fakePolicy.id, tagsToDelete);
642+
deletePolicyTags(fakePolicy.id, tagsToDelete);
643643
return waitForBatchedUpdates();
644644
})
645645
.then(
@@ -699,7 +699,7 @@ describe('actions/Policy', () => {
699699
.then(() => {
700700
mockFetch?.fail?.();
701701

702-
Tag.deletePolicyTags(fakePolicy.id, tagsToDelete);
702+
deletePolicyTags(fakePolicy.id, tagsToDelete);
703703
return waitForBatchedUpdates();
704704
})
705705
.then(mockFetch?.resume)

0 commit comments

Comments
 (0)