From 403c3ec0cb258cad9a5a494fa7985db218e3f55a Mon Sep 17 00:00:00 2001 From: "Situ Chandra Shil (via MelvinBot)" Date: Sun, 20 Sep 2026 05:35:14 +0000 Subject: [PATCH 1/3] Stop the settlement frequency page blocking itself after saving Daily Co-authored-by: Situ Chandra Shil --- .../WorkspaceSettlementFrequencyPage.tsx | 7 +- .../WorkspaceSettlementFrequencyPageTest.tsx | 191 ++++++++++++++++++ 2 files changed, 196 insertions(+), 2 deletions(-) create mode 100644 tests/ui/WorkspaceSettlementFrequencyPageTest.tsx diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx index 4ac4326bf6a5..6152d21294bb 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx @@ -42,6 +42,9 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP const shouldShowMonthlyOption = settings?.isMonthlySettlementAllowed ?? false; const selectedFrequency = settings?.monthlySettlementDate ? CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.MONTHLY : CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; + // This guard is only meant to keep the page from opening when there is nothing to choose. It is derived from live Onyx state, so saving + // Daily — which optimistically clears `monthlySettlementDate` — would otherwise flip it to true and drop the not-found page on top of the + // user's own successful change. A picked option proves the page was usable, so it is what releases the guard below. const isSettlementFrequencyBlocked = !shouldShowMonthlyOption && selectedFrequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; const [selectedFrequencyDraft, setSelectedFrequencyDraft] = useState>(); @@ -79,7 +82,7 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP return; } updateSettlementFrequencyUtil(defaultFundID, programKey, currentFrequency, settings?.monthlySettlementDate); - Navigation.goBack(); + Navigation.goBack(ROUTES.WORKSPACE_EXPENSIFY_CARD_SETTINGS.getRoute(policyID)); }; const confirmButtonOptions = { @@ -93,7 +96,7 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP { + // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment + const actualNav = jest.requireActual('@react-navigation/native'); + // eslint-disable-next-line @typescript-eslint/no-unsafe-return + return { + ...actualNav, + useIsFocused: () => true, + useRoute: () => ({ + key: 'test-route', + name: 'Workspace_ExpensifyCard_Settings_Frequency', + params: {policyID: 'policy123'}, // Must match POLICY_ID + }), + usePreventRemove: jest.fn(), + }; +}); + +jest.mock('@src/hooks/useResponsiveLayout'); + +// The default fund ID falls back to the workspace account ID when there is no last-selected feed. +jest.mock('@hooks/useWorkspaceAccountID', () => ({ + __esModule: true, + default: () => 424242, // Must match WORKSPACE_ACCOUNT_ID +})); + +jest.mock('@hooks/useScreenWrapperTransitionStatus', () => ({ + __esModule: true, + default: () => ({didScreenTransitionEnd: true}), +})); + +jest.mock('@libs/Navigation/Navigation', () => ({ + __esModule: true, + default: { + goBack: jest.fn(), + navigate: jest.fn(), + getActiveRoute: jest.fn(() => ''), + getActiveRouteWithoutParams: jest.fn(() => ''), + isNavigationReady: jest.fn(() => Promise.resolve()), + isTopmostRouteModalScreen: jest.fn(() => false), + }, +})); + +// Stand in for the real access gate so the test can drive `shouldBeBlocked` directly: the policy access checks it also runs +// are not what this page decides, but whether it blocks itself is. +jest.mock('@pages/workspace/AccessOrNotFoundWrapper', () => { + // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion + const ReactMock = require('react') as typeof React; + // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion + const {Text} = require('react-native') as {Text: React.ComponentType<{children?: React.ReactNode}>}; + + return ({children, shouldBeBlocked}: {children: React.ReactNode; shouldBeBlocked?: boolean}) => + shouldBeBlocked ? ReactMock.createElement(Text, null, 'Mocked not found page') : children; // Must match NOT_FOUND_TEXT +}); + +const cardSettingsKey = `${ONYXKEYS.COLLECTION.PRIVATE_EXPENSIFY_CARD_SETTINGS}${WORKSPACE_ACCOUNT_ID}` as const; + +// The page resolves its settings through the card program they are nested under, so the test data has to be nested the same way. +const programKey = CONST.EXPENSIFY_CARD.CARD_PROGRAM.CURRENT; + +// The day of the month the workspace already settles on, standing in for a frequency set in OldDot. +const existingSettlementDay = 10; + +const route: PlatformStackScreenProps['route'] = { + key: 'workspace-expensify-card-settings-frequency', + name: SCREENS.WORKSPACE.EXPENSIFY_CARD_SETTINGS_FREQUENCY, + params: {policyID: POLICY_ID}, +}; +// The screen does not read navigation; this inert test double only satisfies the navigator-provided prop. +// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion +const navigation = {} as PlatformStackScreenProps['navigation']; + +const renderWorkspaceSettlementFrequencyPage = () => + render( + + + , + ); + +OnyxUpdateManager(); +describe('WorkspaceSettlementFrequencyPage', () => { + beforeAll(() => { + Onyx.init({keys: ONYXKEYS}); + }); + + const mockFetch = TestHelper.setupGlobalFetchMock(); + + beforeEach(() => { + mockFetch.succeed(); + }); + + afterEach(async () => { + jest.clearAllMocks(); + await act(async () => { + await Onyx.clear(); + await waitForBatchedUpdatesWithAct(); + }); + }); + + it('does not block the page when the workspace settles monthly but is no longer eligible for monthly settlement', async () => { + // Given a workspace put on monthly settlement in OldDot, which bypasses the eligibility gate NewDot applies + await act(async () => { + await Onyx.merge(cardSettingsKey, { + [programKey]: {isMonthlySettlementAllowed: false, monthlySettlementDate: existingSettlementDay}, + }); + await waitForBatchedUpdatesWithAct(); + }); + + // When the settlement frequency page is opened + renderWorkspaceSettlementFrequencyPage(); + await waitForBatchedUpdatesWithAct(); + + // Then the page opens on the Daily option rather than the not-found page, because there is still a change to make + expect(screen.queryByText(NOT_FOUND_TEXT)).toBeNull(); + expect(screen.getByText('Daily')).toBeTruthy(); + }); + + it('keeps showing the page after saving Daily, when the optimistic update makes the workspace settle daily', async () => { + // Given the same workspace: settling monthly, with monthly no longer selectable + await act(async () => { + await Onyx.merge(cardSettingsKey, { + [programKey]: {isMonthlySettlementAllowed: false, monthlySettlementDate: existingSettlementDay}, + }); + await waitForBatchedUpdatesWithAct(); + }); + + renderWorkspaceSettlementFrequencyPage(); + await waitForBatchedUpdatesWithAct(); + + // When Daily is picked and saved, which optimistically clears `monthlySettlementDate` while the page is still mounted + fireEvent.press(screen.getByText('Daily')); + await waitForBatchedUpdatesWithAct(); + fireEvent.press(screen.getByText('Save')); + await waitForBatchedUpdatesWithAct(); + + // Then the page does not block itself over the user's own successful change. Blocking here is what dropped the + // not-found page on top of the selection and sent the back button to the workspace overview. + expect(screen.queryByText(NOT_FOUND_TEXT)).toBeNull(); + }); + + it('blocks the page when the workspace already settles daily and monthly is not selectable', async () => { + // Given a workspace that settles daily and cannot switch to monthly, so the page has nothing to offer + await act(async () => { + await Onyx.merge(cardSettingsKey, { + [programKey]: {isMonthlySettlementAllowed: false}, + }); + await waitForBatchedUpdatesWithAct(); + }); + + // When the settlement frequency page is opened + renderWorkspaceSettlementFrequencyPage(); + await waitForBatchedUpdatesWithAct(); + + // Then it is still blocked - the fix must not open a page with a single, already-selected option + expect(screen.getByText(NOT_FOUND_TEXT)).toBeTruthy(); + }); +}); From f2980cfbd6b407085caa00b7cd128d09f78a0b8f Mon Sep 17 00:00:00 2001 From: "Situ Chandra Shil (via MelvinBot)" Date: Sun, 20 Sep 2026 06:15:24 +0000 Subject: [PATCH 2/3] Remove unnecessary comment above isSettlementFrequencyBlocked Co-authored-by: Situ Chandra Shil --- .../expensifyCard/WorkspaceSettlementFrequencyPage.tsx | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx index 6152d21294bb..14985a1513d7 100644 --- a/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx +++ b/src/pages/workspace/expensifyCard/WorkspaceSettlementFrequencyPage.tsx @@ -42,9 +42,6 @@ function WorkspaceSettlementFrequencyPage({route}: WorkspaceSettlementFrequencyP const shouldShowMonthlyOption = settings?.isMonthlySettlementAllowed ?? false; const selectedFrequency = settings?.monthlySettlementDate ? CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.MONTHLY : CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; - // This guard is only meant to keep the page from opening when there is nothing to choose. It is derived from live Onyx state, so saving - // Daily — which optimistically clears `monthlySettlementDate` — would otherwise flip it to true and drop the not-found page on top of the - // user's own successful change. A picked option proves the page was usable, so it is what releases the guard below. const isSettlementFrequencyBlocked = !shouldShowMonthlyOption && selectedFrequency === CONST.EXPENSIFY_CARD.FREQUENCY_SETTING.DAILY; const [selectedFrequencyDraft, setSelectedFrequencyDraft] = useState>(); From 2d0de26b1de974062de8859f8f471eb704a88e20 Mon Sep 17 00:00:00 2001 From: "Situ Chandra Shil (via MelvinBot)" Date: Sun, 20 Sep 2026 06:46:03 +0000 Subject: [PATCH 3/3] Split semicolon-joined comment into two sentences Co-authored-by: Situ Chandra Shil --- tests/ui/WorkspaceSettlementFrequencyPageTest.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/ui/WorkspaceSettlementFrequencyPageTest.tsx b/tests/ui/WorkspaceSettlementFrequencyPageTest.tsx index c7ab0aae1507..5a0d1fd990cc 100644 --- a/tests/ui/WorkspaceSettlementFrequencyPageTest.tsx +++ b/tests/ui/WorkspaceSettlementFrequencyPageTest.tsx @@ -97,7 +97,7 @@ const route: PlatformStackScreenProps['navigation'];