-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Remove Onyx.connect() for the key: ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT #66740
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
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
2d4ff63
remove Onyx.connect
DylanDylann 6a7b568
add dependency
DylanDylann b85b7eb
make it cleaner
DylanDylann dabebea
Merge branch 'main' into refactor-IOUUtils
DylanDylann a02c2eb
add Uts
DylanDylann 79a9648
Merge branch 'main' into refactor-IOUUtils
DylanDylann ffe9e84
update --max-warnings
DylanDylann 53fe687
revert mobile-expensify
DylanDylann ca87b52
update --max-warnings
DylanDylann 92ab6cd
Merge branch 'main' into refactor-IOUUtils
DylanDylann 3d9d8e6
revert Mobile-Expensify
DylanDylann 1c7c64b
update to use custom hook
DylanDylann a844067
Merge branch 'main' into refactor-IOUUtils
DylanDylann 363fe15
update --max-warnings
DylanDylann c272d92
eslint failed
DylanDylann 8fd80b8
Merge branch 'main' into refactor-IOUUtils
DylanDylann 18ab48a
update --max-warnings
DylanDylann 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import DateUtils from '@libs/DateUtils'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import useOnyx from './useOnyx'; | ||
|
|
||
| function useIOUUtils() { | ||
| const [lastLocationPermissionPrompt] = useOnyx(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, {canBeMissing: true}); | ||
DylanDylann marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| function shouldStartLocationPermissionFlow() { | ||
| return ( | ||
| !lastLocationPermissionPrompt || | ||
| (DateUtils.isValidDateString(lastLocationPermissionPrompt ?? '') && | ||
| DateUtils.getDifferenceInDaysFromNow(new Date(lastLocationPermissionPrompt ?? '')) > CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS) | ||
| ); | ||
| } | ||
|
|
||
| return {shouldStartLocationPermissionFlow}; | ||
| } | ||
|
|
||
| export default useIOUUtils; | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import {renderHook} from '@testing-library/react-native'; | ||
| import Onyx from 'react-native-onyx'; | ||
| import CONST from '@src/CONST'; | ||
| import useIOUUtils from '@src/hooks/useIOUUtils'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
| import waitForBatchedUpdatesWithAct from '../utils/waitForBatchedUpdatesWithAct'; | ||
|
|
||
| describe('useIOUUtils', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({ | ||
| keys: ONYXKEYS, | ||
| }); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await Onyx.clear(); | ||
| }); | ||
|
|
||
| describe('shouldStartLocationPermissionFlow', () => { | ||
| const now = new Date(); | ||
| const daysAgo = (days: number) => { | ||
| const d = new Date(now); | ||
| d.setDate(d.getDate() - days); | ||
| return d.toISOString(); | ||
| }; | ||
|
|
||
| it('returns true when lastLocationPermissionPrompt is undefined', async () => { | ||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true when lastLocationPermissionPrompt is null', async () => { | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, null); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
| }); | ||
|
|
||
| it('returns true when lastLocationPermissionPrompt is empty string', async () => { | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, ''); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false when lastLocationPermissionPrompt is a valid date string within threshold', async () => { | ||
| const recentDate = daysAgo(CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS - 1); | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, recentDate); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(false); | ||
| }); | ||
|
|
||
| it('returns true when lastLocationPermissionPrompt is a valid date string outside threshold', async () => { | ||
| const oldDate = daysAgo(CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS + 1); | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, oldDate); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false when lastLocationPermissionPrompt is an invalid date string', async () => { | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, 'not-a-date'); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when lastLocationPermissionPrompt is exactly at threshold', async () => { | ||
| const thresholdDate = daysAgo(CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS); | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, thresholdDate); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(false); | ||
| }); | ||
|
|
||
| it('reacts to changes in lastLocationPermissionPrompt', async () => { | ||
| const {result} = renderHook(() => useIOUUtils()); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
|
|
||
| const recentDate = daysAgo(CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS - 1); | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, recentDate); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(false); | ||
|
|
||
| const oldDate = daysAgo(CONST.IOU.LOCATION_PERMISSION_PROMPT_THRESHOLD_DAYS + 1); | ||
| Onyx.set(ONYXKEYS.NVP_LAST_LOCATION_PERMISSION_PROMPT, oldDate); | ||
| await waitForBatchedUpdatesWithAct(); | ||
|
|
||
| expect(result.current.shouldStartLocationPermissionFlow()).toBe(true); | ||
| }); | ||
| }); | ||
| }); |
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.