-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #57913 from bernhardoj/fix/57457-expense-categorie…
…s-opened-several-times Fix multiple navigation to expense field page
- Loading branch information
Showing
3 changed files
with
58 additions
and
63 deletions.
There are no files selected for viewing
This file contains 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 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,18 @@ | ||
import {useCallback, useRef} from 'react'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
|
||
function useActiveRoute() { | ||
const currentReportRHPActiveRoute = useRef(''); | ||
|
||
const getReportRHPActiveRoute = useCallback(() => { | ||
if (!currentReportRHPActiveRoute.current) { | ||
currentReportRHPActiveRoute.current = Navigation.getReportRHPActiveRoute(); | ||
} | ||
|
||
return currentReportRHPActiveRoute.current; | ||
}, []); | ||
|
||
return {getReportRHPActiveRoute}; | ||
} | ||
|
||
export default useActiveRoute; |
This file contains 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,25 @@ | ||
import {renderHook} from '@testing-library/react-native'; | ||
import useActiveRoute from '@hooks/useActiveRoute'; | ||
import Navigation from '@libs/Navigation/Navigation'; | ||
import CONST from '@src/CONST'; | ||
import ROUTES from '@src/ROUTES'; | ||
|
||
describe('useActiveRoute', () => { | ||
it('should return the same active route', () => { | ||
// Given an active route | ||
const navigation = jest.spyOn(Navigation, 'getReportRHPActiveRoute'); | ||
const {result} = renderHook(() => useActiveRoute()); | ||
const expectedActiveRoute = ROUTES.SEARCH_REPORT.getRoute({reportID: '1'}); | ||
navigation.mockReturnValueOnce(expectedActiveRoute); | ||
|
||
const actualActiveRoute = result.current.getReportRHPActiveRoute(); | ||
expect(actualActiveRoute).toBe(expectedActiveRoute); | ||
|
||
// When getting the active route multiple times | ||
navigation.mockReturnValueOnce(ROUTES.MONEY_REQUEST_STEP_DESCRIPTION.getRoute(CONST.IOU.ACTION.CREATE, CONST.IOU.TYPE.CREATE, '1', '1')); | ||
const actualActiveRoute2 = result.current.getReportRHPActiveRoute(); | ||
|
||
// Then it should return the first active route value | ||
expect(actualActiveRoute2).toBe(expectedActiveRoute); | ||
}); | ||
}); |