Repository navigation
[NO QA] Write Unit Tests for Dynamic Routing Logic (BATCH-6) #81505
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
Merged
mjasikowski
merged 41 commits into
Expensify:main
from
software-mansion-labs:collectioneur/dynamic-routes-batch-6
Feb 24, 2026
Merged
Changes from all commits
Commits
Show all changes
41 commits
Select commit
Hold shift + click to select a range
51e1ef7
add first dynamic route + page to the app
collectioneur 3546a82
add warnings
collectioneur 962c1d5
fix Log import path
collectioneur fc957d2
add another helper function splitPathAndQuery
collectioneur 28b620d
add test for useDynamicBackPath
collectioneur 6c10f7b
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur 8fb4c10
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur d884620
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur 8ebe861
add test for getPathFromState
collectioneur 46b560f
add tests for other dynamic routes functions
collectioneur 177d5b5
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur f8cbf81
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur 9007535
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur 70073f5
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur 656851e
fix bug when hook returns back path with trailing slash
collectioneur 367ade2
Merge branch 'collectioneur/dynamic-routes-batch-4' into collectioneu…
collectioneur 03e6ab9
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur c85f89a
remove unnecessary type assertion
collectioneur c9b7d1f
add splitPathAndQuery tests
collectioneur 2f9f5ba
Merge branch main into collectioneur/dynamic-routes-batch-6
collectioneur e10a268
remove Route type
collectioneur 155587e
add additional guards for getMatchingFullScreenRoute
collectioneur 119ac48
remove eslint disable
collectioneur 90dd078
Adjust useDynamicBackPath to use useRootNavigationState
WojtekBoman cb49b29
Handle case when state is undefined in useDynamicPath
WojtekBoman 178655f
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
WojtekBoman 926f01a
Add splitPathAndQuery
WojtekBoman 3c175e2
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
WojtekBoman 2e70a45
Add dynamic routes config
WojtekBoman 2671fd8
Merge branch 'dynamic-routes/fixed-batch-4' into collectioneur/dynami…
collectioneur 781700d
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur 3e3aca6
fix imports and fix test useDynamicBackPath
collectioneur 74dd154
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur e597284
fix prettier
collectioneur 4de4eb9
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur 29d7815
fix prettier
collectioneur 898e2d1
add getMatchingFullScreenRoute tests
collectioneur dbc641d
Merge branch 'main' into collectioneur/dynamic-routes-batch-6
collectioneur cb16295
small dynamic routes adjustments
collectioneur f13fbc1
Merge branch 'main' into collectioneur/dynamic-routes-batch-5
collectioneur a068424
Merge branch 'collectioneur/dynamic-routes-batch-5' into collectioneu…
collectioneur 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
Some comments aren't visible on the classic Files Changed page.
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
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
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
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
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
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 was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| import createDynamicRoute from '@libs/Navigation/helpers/createDynamicRoute'; | ||
| import Navigation from '@libs/Navigation/Navigation'; | ||
| import type {DynamicRouteSuffix} from '@src/ROUTES'; | ||
|
|
||
| jest.mock('@libs/Navigation/Navigation', () => ({ | ||
| getActiveRoute: jest.fn(), | ||
| })); | ||
|
|
||
| jest.mock('@src/ROUTES', () => ({ | ||
| DYNAMIC_ROUTES: { | ||
| VERIFY_ACCOUNT: {path: 'verify-account'}, | ||
| CUSTOM_FLOW: {path: 'custom-flow'}, | ||
| DETAILS: {path: 'details'}, | ||
| INVITE: {path: 'invite'}, | ||
| FILTERS: {path: 'filters'}, | ||
| }, | ||
| })); | ||
|
|
||
| describe('createDynamicRoute', () => { | ||
| const mockGetActiveRoute = Navigation.getActiveRoute as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should append suffix to a simple path', () => { | ||
| const activeRoute = 'settings/profile'; | ||
| const suffix = 'verify-account'; | ||
| const expectedPath = 'settings/profile/verify-account'; | ||
|
|
||
| mockGetActiveRoute.mockReturnValue(activeRoute); | ||
|
|
||
| const result = createDynamicRoute(suffix); | ||
|
|
||
| expect(result).toBe(expectedPath); | ||
| expect(mockGetActiveRoute).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should append suffix and preserve query parameters at the end', () => { | ||
| const activeRoute = 'report/123?sortBy=date'; | ||
| const suffix = 'details'; | ||
| const expectedPath = 'report/123/details?sortBy=date'; | ||
|
|
||
| mockGetActiveRoute.mockReturnValue(activeRoute); | ||
|
|
||
| const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix); | ||
|
|
||
| expect(result).toBe(expectedPath); | ||
| }); | ||
|
|
||
| it('should throw an error if the suffix is invalid', () => { | ||
| const suffix = 'invalid-suffix'; | ||
|
|
||
| expect(() => createDynamicRoute(suffix as unknown as DynamicRouteSuffix)).toThrow(`The route name ${suffix} is not supported in createDynamicRoute`); | ||
| expect(mockGetActiveRoute).not.toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('should handle paths with trailing slashes if splitPathAndQuery normalizes them', () => { | ||
| const activeRoute = 'workspace/100/'; | ||
| const suffix = 'invite'; | ||
| const expectedPath = 'workspace/100/invite'; | ||
|
|
||
| mockGetActiveRoute.mockReturnValue(activeRoute); | ||
|
|
||
| const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix); | ||
|
|
||
| expect(result).toBe(expectedPath); | ||
| }); | ||
|
|
||
| it('should correctly construct path when multiple query parameters exist', () => { | ||
| const activeRoute = 'search?q=test&type=expense'; | ||
| const suffix = 'filters'; | ||
| const expectedPath = 'search/filters?q=test&type=expense'; | ||
|
|
||
| mockGetActiveRoute.mockReturnValue(activeRoute); | ||
|
|
||
| const result = createDynamicRoute(suffix as unknown as DynamicRouteSuffix); | ||
|
|
||
| expect(result).toBe(expectedPath); | ||
| }); | ||
| }); |
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,39 @@ | ||
| import getLastSuffixFromPath from '@libs/Navigation/helpers/getLastSuffixFromPath'; | ||
|
|
||
| jest.mock('@libs/Log', () => ({ | ||
| warn: jest.fn(), | ||
| })); | ||
|
|
||
| describe('getLastSuffixFromPath', () => { | ||
| it('should extract correct suffix from standard path', () => { | ||
| const path = 'settings/profile/verify-account'; | ||
| const expected = 'verify-account'; | ||
| const result = getLastSuffixFromPath(path); | ||
|
|
||
| expect(result).toBe(expected); | ||
| }); | ||
|
|
||
| it('should handle path that is just the suffix', () => { | ||
| const path = 'verify-account'; | ||
| const expected = 'verify-account'; | ||
| const result = getLastSuffixFromPath(path); | ||
|
|
||
| expect(result).toBe(expected); | ||
| }); | ||
|
|
||
| it('should ignore query params', () => { | ||
| const path = 'settings/profile/verify-account?sortBy=date'; | ||
| const expected = 'verify-account'; | ||
| const result = getLastSuffixFromPath(path); | ||
|
|
||
| expect(result).toBe(expected); | ||
| }); | ||
|
|
||
| it('should handle trailing slashes', () => { | ||
| const path = 'settings/profile/verify-account/'; | ||
| const expected = 'verify-account'; | ||
| const result = getLastSuffixFromPath(path); | ||
|
|
||
| expect(result).toBe(expected); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.