Skip to content

Commit 1d8ae1c

Browse files
committed
Fix navigating on create workspace button and adjust jest tests
1 parent 11184c8 commit 1d8ae1c

3 files changed

Lines changed: 46 additions & 15 deletions

File tree

src/pages/home/GettingStartedSection/hooks/useGettingStartedItems.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import useLocalize from '@hooks/useLocalize';
33
import useOnyx from '@hooks/useOnyx';
44
import useResponsiveLayout from '@hooks/useResponsiveLayout';
55
import {hasCompanyCardFeeds} from '@libs/CardUtils';
6+
import Navigation from '@libs/Navigation/Navigation';
67
import {hasAccountingConnections, hasCustomCategories, hasNonDefaultRules, isPaidGroupPolicy, isPendingDeletePolicy} from '@libs/PolicyUtils';
78
import isWithinGettingStartedPeriod from '@pages/home/GettingStartedSection/utils/isWithinGettingStartedPeriod';
89
import {enablePolicyCategories} from '@userActions/Policy/Category';
@@ -67,7 +68,7 @@ function useGettingStartedItems(): UseGettingStartedItemsResult {
6768
key: 'createWorkspace',
6869
label: translate('homePage.gettingStartedSection.createWorkspace'),
6970
isComplete: true,
70-
route: shouldUseNarrowLayout ? ROUTES.WORKSPACE_INITIAL.getRoute(activePolicyID) : ROUTES.WORKSPACE_OVERVIEW.getRoute(activePolicyID),
71+
route: shouldUseNarrowLayout ? ROUTES.WORKSPACE_INITIAL.getRoute(activePolicyID, Navigation.getActiveRoute()) : ROUTES.WORKSPACE_OVERVIEW.getRoute(activePolicyID),
7172
});
7273

7374
const isDirectConnect = !!reportedIntegration && DIRECT_CONNECT_INTEGRATIONS.has(reportedIntegration);

tests/unit/hooks/useGettingStartedItems.test.ts

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ jest.mock('@hooks/useLocalize', () =>
1919
})),
2020
);
2121

22+
jest.mock('@hooks/useResponsiveLayout', () => jest.fn(() => ({shouldUseNarrowLayout: false})));
23+
24+
jest.mock('@userActions/Policy/Category', () => ({enablePolicyCategories: jest.fn()}));
25+
jest.mock('@userActions/Policy/Policy', () => ({enableCompanyCards: jest.fn(), enablePolicyConnections: jest.fn(), enablePolicyRules: jest.fn()}));
26+
2227
const POLICY_ID = '1';
2328

2429
function buildPolicy(overrides: Partial<Policy> = {}): Policy {
@@ -349,10 +354,10 @@ describe('useGettingStartedItems', () => {
349354
});
350355

351356
describe('row 3 - Link company cards', () => {
352-
it('should be shown when company cards feature is enabled on the workspace', async () => {
357+
it('should always be shown', async () => {
353358
await setupManageTeamScenario({
354359
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
355-
policy: {areCompanyCardsEnabled: true},
360+
policy: {areCompanyCardsEnabled: false},
356361
});
357362

358363
const {result} = renderHook(() => useGettingStartedItems());
@@ -361,7 +366,19 @@ describe('useGettingStartedItems', () => {
361366
expect(companyCardsItem).toBeDefined();
362367
});
363368

364-
it('should be hidden when company cards feature is not enabled on the workspace', async () => {
369+
it('should have isFeatureEnabled=true when company cards feature is enabled', async () => {
370+
await setupManageTeamScenario({
371+
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
372+
policy: {areCompanyCardsEnabled: true},
373+
});
374+
375+
const {result} = renderHook(() => useGettingStartedItems());
376+
377+
const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards');
378+
expect(companyCardsItem?.isFeatureEnabled).toBe(true);
379+
});
380+
381+
it('should have isFeatureEnabled=false when company cards feature is not enabled', async () => {
365382
await setupManageTeamScenario({
366383
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
367384
policy: {areCompanyCardsEnabled: false},
@@ -370,7 +387,7 @@ describe('useGettingStartedItems', () => {
370387
const {result} = renderHook(() => useGettingStartedItems());
371388

372389
const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards');
373-
expect(companyCardsItem).toBeUndefined();
390+
expect(companyCardsItem?.isFeatureEnabled).toBe(false);
374391
});
375392

376393
it('should navigate to workspace company cards route', async () => {
@@ -399,10 +416,10 @@ describe('useGettingStartedItems', () => {
399416
});
400417

401418
describe('row 4 - Set up spend rules', () => {
402-
it('should be shown when rules feature is enabled on the workspace', async () => {
419+
it('should always be shown', async () => {
403420
await setupManageTeamScenario({
404421
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
405-
policy: {areRulesEnabled: true},
422+
policy: {areRulesEnabled: false},
406423
});
407424

408425
const {result} = renderHook(() => useGettingStartedItems());
@@ -411,7 +428,19 @@ describe('useGettingStartedItems', () => {
411428
expect(rulesItem).toBeDefined();
412429
});
413430

414-
it('should be hidden when rules feature is not enabled on the workspace', async () => {
431+
it('should have isFeatureEnabled=true when rules feature is enabled', async () => {
432+
await setupManageTeamScenario({
433+
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
434+
policy: {areRulesEnabled: true},
435+
});
436+
437+
const {result} = renderHook(() => useGettingStartedItems());
438+
439+
const rulesItem = result.current.items.find((item) => item.key === 'setupRules');
440+
expect(rulesItem?.isFeatureEnabled).toBe(true);
441+
});
442+
443+
it('should have isFeatureEnabled=false when rules feature is not enabled', async () => {
415444
await setupManageTeamScenario({
416445
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
417446
policy: {areRulesEnabled: false},
@@ -420,7 +449,7 @@ describe('useGettingStartedItems', () => {
420449
const {result} = renderHook(() => useGettingStartedItems());
421450

422451
const rulesItem = result.current.items.find((item) => item.key === 'setupRules');
423-
expect(rulesItem).toBeUndefined();
452+
expect(rulesItem?.isFeatureEnabled).toBe(false);
424453
});
425454

426455
it('should navigate to workspace rules route', async () => {
@@ -511,7 +540,7 @@ describe('useGettingStartedItems', () => {
511540
expect(keys).toEqual(['createWorkspace', 'customizeCategories', 'linkCompanyCards', 'setupRules']);
512541
});
513542

514-
it('should only contain createWorkspace and accounting row when no optional features are enabled', async () => {
543+
it('should always contain all four rows even when optional features are disabled', async () => {
515544
await setupManageTeamScenario({
516545
accounting: CONST.POLICY.CONNECTIONS.NAME.QBO,
517546
policy: {areCompanyCardsEnabled: false, areRulesEnabled: false},
@@ -520,7 +549,7 @@ describe('useGettingStartedItems', () => {
520549
const {result} = renderHook(() => useGettingStartedItems());
521550

522551
const keys = result.current.items.map((item) => item.key);
523-
expect(keys).toEqual(['createWorkspace', 'connectAccounting']);
552+
expect(keys).toEqual(['createWorkspace', 'connectAccounting', 'linkCompanyCards', 'setupRules']);
524553
});
525554
});
526555

tests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const TEST_POLICY_ID = 'ABC123';
1212

1313
jest.mock('@libs/Navigation/Navigation', () => ({
1414
navigate: jest.fn(),
15+
setNavigationActionToMicrotaskQueue: jest.fn((callback: () => void) => callback()),
1516
}));
1617

1718
jest.mock('@hooks/useLocalize', () =>
@@ -195,12 +196,12 @@ describe('GettingStartedSection', () => {
195196
expect(screen.getByText('homePage.gettingStartedSection.linkCompanyCards')).toBeTruthy();
196197
});
197198

198-
it('hides "Link company cards" row when company cards feature is disabled', async () => {
199+
it('always shows "Link company cards" row even when company cards feature is disabled', async () => {
199200
await setManageTeamUserState({areCompanyCardsEnabled: false});
200201

201202
renderGettingStartedSection();
202203

203-
expect(screen.queryByText('homePage.gettingStartedSection.linkCompanyCards')).toBeNull();
204+
expect(screen.getByText('homePage.gettingStartedSection.linkCompanyCards')).toBeTruthy();
204205
});
205206

206207
it('shows "Set up spend rules" row when rules feature is enabled', async () => {
@@ -211,12 +212,12 @@ describe('GettingStartedSection', () => {
211212
expect(screen.getByText('homePage.gettingStartedSection.setupRules')).toBeTruthy();
212213
});
213214

214-
it('hides "Set up spend rules" row when rules feature is disabled', async () => {
215+
it('always shows "Set up spend rules" row even when rules feature is disabled', async () => {
215216
await setManageTeamUserState({areRulesEnabled: false});
216217

217218
renderGettingStartedSection();
218219

219-
expect(screen.queryByText('homePage.gettingStartedSection.setupRules')).toBeNull();
220+
expect(screen.getByText('homePage.gettingStartedSection.setupRules')).toBeTruthy();
220221
});
221222

222223
it('renders rows in the expected order: workspace, accounting, cards, rules', async () => {

0 commit comments

Comments
 (0)