Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/hooks/useIsBlockedToAddFeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function useIsBlockedToAddFeed(policyID?: string) {
}, [cardFeeds?.settings?.oAuthAccountDetails, addNewCard?.data?.plaidConnectedFeed, prevOAuthDetails]);

return {
isBlockedToAddNewFeeds: isCollect && Object.entries(companyFeeds)?.length >= 1 && !isNewFeedConnected,
isBlockedToAddNewFeeds: isCollect && Object.entries(companyFeeds)?.length >= 1 && !isNewFeedConnected && !isLoading,
Comment thread
narefyev91 marked this conversation as resolved.
Comment thread
narefyev91 marked this conversation as resolved.
Comment thread
narefyev91 marked this conversation as resolved.
isAllFeedsResultLoading: isCollect && (isLoading || isAllFeedsResultLoading),
};
}
Expand Down
90 changes: 90 additions & 0 deletions tests/unit/hooks/useIsBlockedToAddFeed.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,94 @@ describe('useIsBlockedToAddFeed', () => {
const {result} = renderHook(() => useIsBlockedToAddFeed(mockPolicyID));
expect(result.current.isBlockedToAddNewFeeds).toBe(false);
});

it('should return isBlockedToAddNewFeeds as false when data is still loading', () => {
(useCardFeeds as jest.Mock).mockReturnValue([
{
isLoading: true, // Key: data is loading
settings: {
companyCards: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'plaid.ins_19': {
asrEnabled: false,
country: 'US',
forceReimbursable: 'force_no',
liabilityType: 'corporate',
preferredPolicy: '135CA2196CD21C88',
reportTitleFormat: '',
shouldApplyCashbackToBill: true,
statementPeriodEndDay: 'LAST_DAY_OF_MONTH',
uploadLayoutSettings: [],
},
},
companyCardNicknames: {},
oAuthAccountDetails: {},
},
},
{status: 'loading'}, // allFeedsResult is loading
]);
const {result} = renderHook(() => useIsBlockedToAddFeed(mockPolicyID));
// Should not block while loading, even if feeds exist
expect(result.current.isBlockedToAddNewFeeds).toBe(false);
// But isAllFeedsResultLoading should be true
expect(result.current.isAllFeedsResultLoading).toBe(true);
});

it('should transition from not blocked (loading) to blocked (loaded) when data finishes loading', async () => {
// Initial state: loading with existing feed
(useCardFeeds as jest.Mock).mockReturnValue([
{
isLoading: true,
settings: {
companyCards: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'plaid.ins_19': {
asrEnabled: false,
country: 'US',
forceReimbursable: 'force_no',
liabilityType: 'corporate',
preferredPolicy: '135CA2196CD21C88',
reportTitleFormat: '',
shouldApplyCashbackToBill: true,
statementPeriodEndDay: 'LAST_DAY_OF_MONTH',
uploadLayoutSettings: [],
},
},
companyCardNicknames: {},
oAuthAccountDetails: {},
},
},
{status: 'loading'},
]);
const {result, rerender} = renderHook(() => useIsBlockedToAddFeed(mockPolicyID));
expect(result.current.isBlockedToAddNewFeeds).toBe(false);

// After loading completes
(useCardFeeds as jest.Mock).mockReturnValue([
{
isLoading: false,
settings: {
companyCards: {
// eslint-disable-next-line @typescript-eslint/naming-convention
'plaid.ins_19': {
asrEnabled: false,
country: 'US',
forceReimbursable: 'force_no',
liabilityType: 'corporate',
preferredPolicy: '135CA2196CD21C88',
reportTitleFormat: '',
shouldApplyCashbackToBill: true,
statementPeriodEndDay: 'LAST_DAY_OF_MONTH',
uploadLayoutSettings: [],
},
},
companyCardNicknames: {},
oAuthAccountDetails: {},
},
},
{status: 'loaded'},
]);
rerender('plaid.ins_19');
expect(result.current.isBlockedToAddNewFeeds).toBe(true);
});
});
Loading