diff --git a/tests/unit/hooks/useGettingStartedItems.test.ts b/tests/unit/hooks/useGettingStartedItems.test.ts index b65ef75e9fc6..dc58f3b14ba9 100644 --- a/tests/unit/hooks/useGettingStartedItems.test.ts +++ b/tests/unit/hooks/useGettingStartedItems.test.ts @@ -1,4 +1,4 @@ -import {renderHook} from '@testing-library/react-native'; +import {renderHook, waitFor} from '@testing-library/react-native'; import Onyx from 'react-native-onyx'; import useGettingStartedItems from '@pages/home/GettingStartedSection/hooks/useGettingStartedItems'; import CONST from '@src/CONST'; @@ -26,6 +26,13 @@ jest.mock('@userActions/Policy/Policy', () => ({enableCompanyCards: jest.fn(), e const POLICY_ID = '1'; +// Trial dates relative to today so the 60-day Getting Started window check +// (isWithinGettingStartedPeriod) doesn't drift out of bounds as wall time +// passes. The previously-hardcoded values passed at landing time but started +// failing 60+ days later when the trial cutoff swept past them. +const RECENT_TRIAL_START = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T').at(0) ?? ''; +const FUTURE_TRIAL_END = new Date(Date.now() + 23 * 24 * 60 * 60 * 1000).toISOString().split('T').at(0) ?? ''; + function buildPolicy(overrides: Partial = {}): Policy { return { ...createRandomPolicy(1, CONST.POLICY.TYPE.TEAM, 'Test Workspace'), @@ -80,11 +87,12 @@ describe('useGettingStartedItems', () => { await Onyx.merge(ONYXKEYS.NVP_ACTIVE_POLICY_ID, POLICY_ID); const policy = buildPolicy(); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); expect(result.current.items).toEqual([]); @@ -95,11 +103,12 @@ describe('useGettingStartedItems', () => { await Onyx.merge(ONYXKEYS.NVP_ACTIVE_POLICY_ID, POLICY_ID); const policy = buildPolicy(); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); }); @@ -108,6 +117,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(true); expect(result.current.items.length).toBeGreaterThan(0); @@ -118,14 +128,16 @@ describe('useGettingStartedItems', () => { await Onyx.merge(ONYXKEYS.NVP_ACTIVE_POLICY_ID, POLICY_ID); const policy = buildPolicy(); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await Onyx.merge(ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION, CONST.POLICY.CONNECTIONS.NAME.QBO as never); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); - - expect(result.current.shouldShowSection).toBe(true); + // The hook reads ONBOARDING_PURPOSE_SELECTED via a separate useOnyx + // subscription whose callback can land a tick after the others; poll + // with waitFor instead of relying on a single batched-updates flush. + await waitFor(() => expect(result.current.shouldShowSection).toBe(true)); }); it('should be hidden after 60 days from NVP_FIRST_DAY_FREE_TRIAL', async () => { @@ -138,6 +150,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); }); @@ -152,6 +165,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(true); }); @@ -166,6 +180,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); }); @@ -179,6 +194,7 @@ describe('useGettingStartedItems', () => { await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); }); @@ -189,6 +205,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const createWorkspaceItem = result.current.items.find((item) => item.key === 'createWorkspace'); expect(createWorkspaceItem).toBeDefined(); @@ -198,6 +215,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const createWorkspaceItem = result.current.items.find((item) => item.key === 'createWorkspace'); expect(createWorkspaceItem?.isComplete).toBe(true); @@ -207,6 +225,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.items.at(0)?.key).toBe('createWorkspace'); }); @@ -215,6 +234,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const createWorkspaceItem = result.current.items.find((item) => item.key === 'createWorkspace'); expect(createWorkspaceItem?.route).toBe(ROUTES.WORKSPACE_OVERVIEW.getRoute(POLICY_ID)); @@ -234,6 +254,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: key, policy: {areConnectionsEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem).toBeDefined(); @@ -244,6 +265,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO, policy: {areConnectionsEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.route).toBe(ROUTES.WORKSPACE_ACCOUNTING.getRoute(POLICY_ID)); @@ -256,6 +278,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.isComplete).toBe(false); @@ -277,6 +300,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.isComplete).toBe(true); @@ -298,6 +322,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.isComplete).toBe(false); @@ -319,6 +344,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.isComplete).toBe(true); @@ -328,6 +354,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO, policy: {areConnectionsEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem).toBeUndefined(); @@ -348,6 +375,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem).toBeDefined(); @@ -358,6 +386,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem).toBeDefined(); @@ -367,6 +396,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: CONST.POLICY.CONNECTIONS.NAME.QBO, policy: {areConnectionsEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem?.isFeatureEnabled).toBe(true); @@ -388,6 +418,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem).toBeDefined(); @@ -402,6 +433,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting, policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem).toBeDefined(); @@ -411,6 +443,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem?.isFeatureEnabled).toBe(true); @@ -420,6 +453,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: false}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem).toBeDefined(); @@ -430,6 +464,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem?.route).toBe(ROUTES.WORKSPACE_CATEGORIES.getRoute(POLICY_ID)); @@ -439,6 +474,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const connectItem = result.current.items.find((item) => item.key === 'connectAccounting'); expect(connectItem).toBeUndefined(); @@ -448,6 +484,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem?.isComplete).toBe(false); @@ -472,6 +509,7 @@ describe('useGettingStartedItems', () => { await setupManageTeamScenario({accounting: 'none', policy: {areCategoriesEnabled: true}}); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const categoriesItem = result.current.items.find((item) => item.key === 'customizeCategories'); expect(categoriesItem?.isComplete).toBe(true); @@ -486,6 +524,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards'); expect(companyCardsItem).toBeDefined(); @@ -498,6 +537,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards'); expect(companyCardsItem?.isFeatureEnabled).toBe(true); @@ -510,6 +550,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards'); expect(companyCardsItem?.isFeatureEnabled).toBe(false); @@ -522,6 +563,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards'); expect(companyCardsItem?.route).toBe(ROUTES.WORKSPACE_COMPANY_CARDS.getRoute(POLICY_ID)); @@ -534,6 +576,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const companyCardsItem = result.current.items.find((item) => item.key === 'linkCompanyCards'); expect(companyCardsItem?.isComplete).toBe(false); @@ -548,6 +591,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem).toBeDefined(); @@ -560,6 +604,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem).toBeUndefined(); @@ -572,6 +617,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem).toBeUndefined(); @@ -584,6 +630,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem?.route).toBe(ROUTES.WORKSPACE_RULES.getRoute(POLICY_ID)); @@ -596,6 +643,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem?.isComplete).toBe(false); @@ -619,6 +667,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem?.isComplete).toBe(true); @@ -634,6 +683,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const rulesItem = result.current.items.find((item) => item.key === 'setupRules'); expect(rulesItem?.isComplete).toBe(true); @@ -648,6 +698,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const keys = result.current.items.map((item) => item.key); expect(keys).toEqual(['createWorkspace', 'connectAccounting', 'linkCompanyCards', 'setupRules']); @@ -660,6 +711,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const keys = result.current.items.map((item) => item.key); expect(keys).toEqual(['createWorkspace', 'customizeCategories', 'linkCompanyCards', 'setupRules']); @@ -672,6 +724,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); const keys = result.current.items.map((item) => item.key); expect(keys).toEqual(['createWorkspace', 'connectAccounting', 'linkCompanyCards']); @@ -681,11 +734,12 @@ describe('useGettingStartedItems', () => { describe('edge cases', () => { it('should be hidden when active policy ID is missing', async () => { await Onyx.merge(ONYXKEYS.NVP_INTRO_SELECTED, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); expect(result.current.items).toEqual([]); @@ -698,6 +752,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); expect(result.current.items).toEqual([]); @@ -706,11 +761,12 @@ describe('useGettingStartedItems', () => { it('should be hidden when policy data does not exist', async () => { await Onyx.merge(ONYXKEYS.NVP_INTRO_SELECTED, {choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM}); await Onyx.merge(ONYXKEYS.NVP_ACTIVE_POLICY_ID, 'nonexistent-policy'); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); expect(result.current.items).toEqual([]); @@ -723,6 +779,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(false); expect(result.current.items).toEqual([]); @@ -735,6 +792,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(true); expect(result.current.items.length).toBeGreaterThan(0); @@ -747,6 +805,7 @@ describe('useGettingStartedItems', () => { }); const {result} = renderHook(() => useGettingStartedItems()); + await waitForBatchedUpdates(); expect(result.current.shouldShowSection).toBe(true); expect(result.current.items.length).toBeGreaterThan(0); @@ -758,14 +817,16 @@ describe('useGettingStartedItems', () => { await Onyx.merge(ONYXKEYS.NVP_ACTIVE_POLICY_ID, POLICY_ID); const policy = buildPolicy(); await Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${POLICY_ID}`, policy); - await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); - await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, '2026-04-01'); + await Onyx.merge(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); + await Onyx.merge(ONYXKEYS.NVP_LAST_DAY_FREE_TRIAL, FUTURE_TRIAL_END); await Onyx.merge(ONYXKEYS.ONBOARDING_USER_REPORTED_INTEGRATION, CONST.POLICY.CONNECTIONS.NAME.QBO as never); await waitForBatchedUpdates(); const {result} = renderHook(() => useGettingStartedItems()); - - expect(result.current.shouldShowSection).toBe(true); + // Same reasoning as the ONBOARDING_PURPOSE_SELECTED fallback test above: + // poll until the hook's dependent useOnyx chain settles instead of + // relying on a single flush. + await waitFor(() => expect(result.current.shouldShowSection).toBe(true)); }); }); }); diff --git a/tests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx b/tests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx index 84d7d63c8796..7321d955ebe1 100644 --- a/tests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx +++ b/tests/unit/pages/home/GettingStartedSection/GettingStartedSectionTest.tsx @@ -10,6 +10,12 @@ import waitForBatchedUpdates from '../../../../utils/waitForBatchedUpdates'; const TEST_POLICY_ID = 'ABC123'; +// Trial dates relative to today so the 60-day Getting Started window check +// (isWithinGettingStartedPeriod) doesn't drift out of bounds as wall time +// passes. Previously-hardcoded values passed at landing time but started +// failing 60+ days later when the trial cutoff swept past them. +const RECENT_TRIAL_START = new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString().split('T').at(0) ?? ''; + jest.mock('@libs/Navigation/Navigation', () => ({ navigate: jest.fn(), setNavigationActionToMicrotaskQueue: jest.fn((callback: () => void) => callback()), @@ -51,7 +57,7 @@ async function setManageTeamUserState(overrides?: { hasConfiguredRules?: boolean; trialStartDate?: string; }) { - const trialStart = overrides?.trialStartDate ?? '2026-03-01'; + const trialStart = overrides?.trialStartDate ?? RECENT_TRIAL_START; await Onyx.set(ONYXKEYS.NVP_INTRO_SELECTED, { choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, @@ -101,10 +107,11 @@ describe('GettingStartedSection', () => { choice: CONST.ONBOARDING_CHOICES.PERSONAL_SPEND, }); await Onyx.set(ONYXKEYS.NVP_ACTIVE_POLICY_ID, TEST_POLICY_ID); - await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); + await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); await waitForBatchedUpdates(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.queryByText('homePage.gettingStartedSection.title')).toBeNull(); }); @@ -115,6 +122,7 @@ describe('GettingStartedSection', () => { }); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.queryByText('homePage.gettingStartedSection.title')).toBeNull(); }); @@ -124,7 +132,7 @@ describe('GettingStartedSection', () => { choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, }); await Onyx.set(ONYXKEYS.NVP_ACTIVE_POLICY_ID, TEST_POLICY_ID); - await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); + await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); await Onyx.set( `${ONYXKEYS.COLLECTION.POLICY}${TEST_POLICY_ID}` as never, { @@ -139,6 +147,7 @@ describe('GettingStartedSection', () => { await waitForBatchedUpdates(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.queryByText('homePage.gettingStartedSection.title')).toBeNull(); }); @@ -148,7 +157,7 @@ describe('GettingStartedSection', () => { choice: CONST.ONBOARDING_CHOICES.MANAGE_TEAM, }); await Onyx.set(ONYXKEYS.NVP_ACTIVE_POLICY_ID, TEST_POLICY_ID); - await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); + await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); await Onyx.set( `${ONYXKEYS.COLLECTION.POLICY}${TEST_POLICY_ID}` as never, { @@ -163,6 +172,7 @@ describe('GettingStartedSection', () => { await waitForBatchedUpdates(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.queryByText('homePage.gettingStartedSection.title')).toBeNull(); }); @@ -171,6 +181,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.title')).toBeTruthy(); }); @@ -178,7 +189,7 @@ describe('GettingStartedSection', () => { it('renders when manage-team intent is set via fallback ONBOARDING_PURPOSE_SELECTED', async () => { await Onyx.set(ONYXKEYS.ONBOARDING_PURPOSE_SELECTED, CONST.ONBOARDING_CHOICES.MANAGE_TEAM as never); await Onyx.set(ONYXKEYS.NVP_ACTIVE_POLICY_ID, TEST_POLICY_ID); - await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, '2026-03-01'); + await Onyx.set(ONYXKEYS.NVP_FIRST_DAY_FREE_TRIAL, RECENT_TRIAL_START); await Onyx.set( `${ONYXKEYS.COLLECTION.POLICY}${TEST_POLICY_ID}` as never, { @@ -193,6 +204,7 @@ describe('GettingStartedSection', () => { await waitForBatchedUpdates(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.title')).toBeTruthy(); }); @@ -203,6 +215,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.title')).toBeTruthy(); }); @@ -213,6 +226,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState(); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.createWorkspace')).toBeTruthy(); }); @@ -221,6 +235,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'quickbooksOnline', areAccountingEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText(/homePage\.gettingStartedSection\.connectAccounting/)).toBeTruthy(); }); @@ -229,6 +244,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'xero', areAccountingEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText(/homePage\.gettingStartedSection\.connectAccounting/)).toBeTruthy(); }); @@ -237,6 +253,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'other', areCategoriesEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.customizeCategories')).toBeTruthy(); expect(screen.queryByText(/homePage\.gettingStartedSection\.connectAccounting/)).toBeNull(); @@ -246,6 +263,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'none', areCategoriesEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.customizeCategories')).toBeTruthy(); }); @@ -254,6 +272,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areCompanyCardsEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.linkCompanyCards')).toBeTruthy(); }); @@ -262,6 +281,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areCompanyCardsEnabled: false}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.linkCompanyCards')).toBeTruthy(); }); @@ -270,6 +290,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areRulesEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText('homePage.gettingStartedSection.setupRules')).toBeTruthy(); }); @@ -278,6 +299,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areRulesEnabled: false}); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.queryByText('homePage.gettingStartedSection.setupRules')).toBeNull(); }); @@ -291,6 +313,7 @@ describe('GettingStartedSection', () => { }); renderGettingStartedSection(); + await waitForBatchedUpdates(); const allRows = screen.getAllByText(/homePage\.gettingStartedSection\./); const rowTexts = allRows.map((el) => (el.props as {children: string}).children); @@ -310,6 +333,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState(); renderGettingStartedSection(); + await waitForBatchedUpdates(); const createRow = screen.getByText('homePage.gettingStartedSection.createWorkspace'); const parentRow = createRow.parent; @@ -324,6 +348,7 @@ describe('GettingStartedSection', () => { }); renderGettingStartedSection(); + await waitForBatchedUpdates(); expect(screen.getByText(/homePage\.gettingStartedSection\.connectAccounting/)).toBeTruthy(); }); @@ -334,6 +359,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState(); renderGettingStartedSection(); + await waitForBatchedUpdates(); const row = screen.getByText('homePage.gettingStartedSection.createWorkspace'); fireEvent.press(row); @@ -345,6 +371,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'quickbooksOnline', areAccountingEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); const row = screen.getByText(/homePage\.gettingStartedSection\.connectAccounting/); fireEvent.press(row); @@ -356,6 +383,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({integration: 'other', areCategoriesEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); const row = screen.getByText('homePage.gettingStartedSection.customizeCategories'); fireEvent.press(row); @@ -367,6 +395,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areCompanyCardsEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); const row = screen.getByText('homePage.gettingStartedSection.linkCompanyCards'); fireEvent.press(row); @@ -378,6 +407,7 @@ describe('GettingStartedSection', () => { await setManageTeamUserState({areRulesEnabled: true}); renderGettingStartedSection(); + await waitForBatchedUpdates(); const row = screen.getByText('homePage.gettingStartedSection.setupRules'); fireEvent.press(row);