-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Preserve deep-linked report route during onboarding guard redirect #86390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
MelvinBot
wants to merge
12
commits into
main
Choose a base branch
from
claude-preserveDeepLinkDuringOnboardingRedirect-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+209
−7
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
b5d5fe4
Preserve deep-linked report route during onboarding guard redirect
MelvinBot ed1c51f
Merge remote-tracking branch 'origin/main' into claude-preserveDeepLi…
MelvinBot 2e3e098
Merge remote-tracking branch 'origin/main' into claude-preserveDeepLi…
MelvinBot 0ff0fa0
Merge remote-tracking branch 'origin/main' into claude-preserveDeepLi…
MelvinBot 71716c7
Refactor redirect logic to only preserve routes for modal guard targets
MelvinBot 4b4ac60
Update unit test to match modal-only redirect preservation logic
MelvinBot a9d22dc
Fix: skip redirect when target is already the focused route
MelvinBot edfa6c7
Merge remote-tracking branch 'origin/claude-preserveDeepLinkDuringOnb…
MelvinBot 6e5d049
Revert "Fix: skip redirect when target is already the focused route"
MelvinBot c58257c
Remove HOME navigation fallback from navigateAfterOnboarding
MelvinBot 36a1718
Fix: use last fullscreen route instead of first for modal redirects
MelvinBot cb55ea1
Merge remote-tracking branch 'origin/main' into claude-preserveDeepLi…
MelvinBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
tests/unit/Navigation/guards/handleNavigationGuardRedirect.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| import type {StackNavigationState} from '@react-navigation/native'; | ||
| import type {ParamListBase} from '@react-navigation/routers'; | ||
| import RootStackRouter from '@libs/Navigation/AppNavigator/createRootStackNavigator/RootStackRouter'; | ||
| import {evaluateGuards} from '@libs/Navigation/guards'; | ||
| import getAdaptedStateFromPath from '@libs/Navigation/helpers/getAdaptedStateFromPath'; | ||
| import NAVIGATORS from '@src/NAVIGATORS'; | ||
| import SCREENS from '@src/SCREENS'; | ||
|
|
||
| jest.mock('@libs/Navigation/guards', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| createGuardContext: jest.fn(() => ({ | ||
| isAuthenticated: true, | ||
| isLoading: false, | ||
| currentUrl: '', | ||
| })), | ||
| evaluateGuards: jest.fn(() => ({type: 'ALLOW'})), | ||
| registerGuard: jest.fn(), | ||
| clearGuards: jest.fn(), | ||
| getRegisteredGuards: jest.fn(() => []), | ||
| })); | ||
|
|
||
| jest.mock('@libs/Navigation/helpers/getAdaptedStateFromPath', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| default: jest.fn(), | ||
| })); | ||
|
|
||
| const mockedEvaluateGuards = evaluateGuards as jest.Mock; | ||
| const mockedGetAdaptedStateFromPath = getAdaptedStateFromPath as jest.Mock; | ||
|
|
||
| const routeNames = [SCREENS.HOME, NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR, NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR]; | ||
|
|
||
| describe('handleNavigationGuards - REDIRECT stack preservation', () => { | ||
| const router = RootStackRouter({}); | ||
|
|
||
| const configOptions = { | ||
| routeNames, | ||
| routeParamList: {} as ParamListBase, | ||
| routeGetIdList: {} as Record<string, ((params: Record<string, unknown>) => string) | undefined>, | ||
| }; | ||
|
|
||
| const mockAction = { | ||
| type: 'NAVIGATE' as const, | ||
| payload: {name: SCREENS.HOME}, | ||
| }; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| mockedEvaluateGuards.mockReturnValue({type: 'ALLOW'}); | ||
| }); | ||
|
|
||
| it('should preserve existing fullscreen routes and append redirect target on top', () => { | ||
| // Given the current stack has a deep-linked report (a fullscreen route) | ||
| const state: StackNavigationState<ParamListBase> = { | ||
| key: 'root', | ||
| index: 0, | ||
| routeNames, | ||
| routes: [{key: 'report-1', name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, params: undefined}], | ||
| stale: false, | ||
| type: 'stack', | ||
| preloadedRoutes: [], | ||
| }; | ||
|
|
||
| // When the guard returns REDIRECT to onboarding and getAdaptedStateFromPath returns a state with Home + OnboardingModalNavigator | ||
| mockedEvaluateGuards.mockReturnValue({type: 'REDIRECT', route: 'onboarding/purpose'}); | ||
| mockedGetAdaptedStateFromPath.mockReturnValue({ | ||
| routes: [ | ||
| {name: SCREENS.HOME, key: 'home-1'}, | ||
| {name: NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR, key: 'onboarding-1'}, | ||
| ], | ||
| }); | ||
|
|
||
| const result = router.getStateForAction(state, mockAction, configOptions); | ||
|
|
||
| // Then the deep-linked report should be preserved and onboarding should be appended on top | ||
| expect(result).not.toBeNull(); | ||
| expect(result?.routes).toHaveLength(2); | ||
| expect(result?.routes[0].name).toBe(NAVIGATORS.REPORTS_SPLIT_NAVIGATOR); | ||
| expect(result?.routes[1].name).toBe(NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR); | ||
| expect(result?.index).toBe(1); | ||
| }); | ||
|
|
||
| it('should use the full redirect state when no existing fullscreen route is present', () => { | ||
| // Given a fresh app state with no fullscreen routes (e.g., only a non-fullscreen route) | ||
| const state: StackNavigationState<ParamListBase> = { | ||
| key: 'root', | ||
| index: 0, | ||
| routeNames: [...routeNames, 'SomeNonFullScreenRoute'], | ||
| routes: [{key: 'other-1', name: 'SomeNonFullScreenRoute', params: undefined}], | ||
| stale: false, | ||
| type: 'stack', | ||
| preloadedRoutes: [], | ||
| }; | ||
|
|
||
| // When the guard returns REDIRECT to onboarding | ||
| mockedEvaluateGuards.mockReturnValue({type: 'REDIRECT', route: 'onboarding/purpose'}); | ||
| mockedGetAdaptedStateFromPath.mockReturnValue({ | ||
| routes: [ | ||
| {name: SCREENS.HOME, key: 'home-1'}, | ||
| {name: NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR, key: 'onboarding-1'}, | ||
| ], | ||
| }); | ||
|
|
||
| const result = router.getStateForAction(state, mockAction, configOptions); | ||
|
|
||
| // Then the full redirect state (Home + Onboarding) should be used since there's no fullscreen route to preserve | ||
| expect(result).not.toBeNull(); | ||
| expect(result?.routes).toHaveLength(2); | ||
| expect(result?.routes[0].name).toBe(SCREENS.HOME); | ||
| expect(result?.routes[1].name).toBe(NAVIGATORS.ONBOARDING_MODAL_NAVIGATOR); | ||
| expect(result?.index).toBe(1); | ||
| }); | ||
|
|
||
| it('should use the full redirect state for non-modal redirects even when fullscreen routes exist', () => { | ||
| // Given the current stack has a deep-linked report (a fullscreen route) | ||
| const state: StackNavigationState<ParamListBase> = { | ||
| key: 'root', | ||
| index: 0, | ||
| routeNames, | ||
| routes: [{key: 'report-1', name: NAVIGATORS.REPORTS_SPLIT_NAVIGATOR, params: undefined}], | ||
| stale: false, | ||
| type: 'stack', | ||
| preloadedRoutes: [], | ||
| }; | ||
|
|
||
| // When the guard returns a non-modal REDIRECT (e.g., to SettingsSplitNavigator) | ||
| mockedEvaluateGuards.mockReturnValue({type: 'REDIRECT', route: 'settings'}); | ||
| mockedGetAdaptedStateFromPath.mockReturnValue({ | ||
| routes: [{name: NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR, key: 'settings-1'}], | ||
| }); | ||
|
|
||
| const result = router.getStateForAction(state, mockAction, configOptions); | ||
|
|
||
| // Then the full redirect state should be used (no route preservation for non-modal redirects) | ||
| expect(result).not.toBeNull(); | ||
| expect(result?.routes).toHaveLength(1); | ||
| expect(result?.routes[0].name).toBe(NAVIGATORS.SETTINGS_SPLIT_NAVIGATOR); | ||
| expect(result?.index).toBe(0); | ||
| }); | ||
|
|
||
| it('should not process redirect when guard allows navigation', () => { | ||
| // Given the guard allows navigation | ||
| const state: StackNavigationState<ParamListBase> = { | ||
| key: 'root', | ||
| index: 0, | ||
| routeNames, | ||
| routes: [{key: 'home-1', name: SCREENS.HOME, params: undefined}], | ||
| stale: false, | ||
| type: 'stack', | ||
| preloadedRoutes: [], | ||
| }; | ||
|
|
||
| mockedEvaluateGuards.mockReturnValue({type: 'ALLOW'}); | ||
|
|
||
| // Normal routing may error with minimal config — we only care that redirect logic was not triggered | ||
| try { | ||
| router.getStateForAction(state, mockAction, configOptions); | ||
| } catch { | ||
| // Expected: StackRouter needs full config for normal routing | ||
| } | ||
|
|
||
| // Then getAdaptedStateFromPath should NOT have been called (no redirect processing) | ||
| expect(mockedGetAdaptedStateFromPath).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should return unchanged state when guard blocks navigation', () => { | ||
| // Given the guard blocks navigation | ||
| const state: StackNavigationState<ParamListBase> = { | ||
| key: 'root', | ||
| index: 0, | ||
| routeNames, | ||
| routes: [{key: 'home-1', name: SCREENS.HOME, params: undefined}], | ||
| stale: false, | ||
| type: 'stack', | ||
| preloadedRoutes: [], | ||
| }; | ||
|
|
||
| mockedEvaluateGuards.mockReturnValue({type: 'BLOCK', reason: 'Test block'}); | ||
|
|
||
| const result = router.getStateForAction(state, mockAction, configOptions); | ||
|
|
||
| // Then the state should be returned unchanged | ||
| expect(result).toEqual(state); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to fix what I wrote here: #86390 (comment)
(I asked if it safe to remove it here)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But the comment above the code says:
So our guard code change will handle it. NO?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's for test drive modal guard, which doesn't exist anymore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand how the problem you explained here relates with the scope of this pr. Is there any specific circumstance that this code makes the expected result of this pr fail?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the 6th step
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But without this change I was able to land on the report. Are u saying for specific onboarding flow? For instance, the manage teams flow landed on the admin's room but I thought that was expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you test choosing Something else and complete the onboarding?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I couldn't test because of a new bug on main here