Repository navigation
Clear delete navigate back URL when the deleted expense screen unmounts #105220
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
David-2002065
wants to merge
12
commits into
Expensify:main
Choose a base branch
from
David-2002065:fix/103403-clear-delete-url-native
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.
+374
−21
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
13048d9
Clear delete navigate back URL when the deleted expense screen unmounts
David-2002065 8f27a00
Mock clearDeleteTransactionNavigateBackUrlAfterTransitions in SearchM…
David-2002065 349b726
Cancel a pending delete URL clear when a newer deletion sets the URL
David-2002065 67b98ba
Document the unmount clear in SearchMoneyRequestReportPage
David-2002065 8859381
Only clear the delete navigate back URL on unmount for transaction th…
David-2002065 592cf6b
Move the delete URL read out of the action into a hook
David-2002065 5fa19e0
Merge remote-tracking branch 'upstream/main' into fix/103403-clear-de…
David-2002065 0124f66
Merge remote-tracking branch 'upstream/main' into fix/103403-clear-de…
David-2002065 a6171a7
Move the delete navigate back URL to a RAM_ONLY key with a clearer name
David-2002065 fc6be12
Merge remote-tracking branch 'upstream/main' into fix/103403-clear-de…
David-2002065 6e8abda
Use connection.unsubscribe in the delete navigate back handler test
David-2002065 7042e80
Recheck the transaction thread when parent data loads and cancel the …
David-2002065 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
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
132 changes: 132 additions & 0 deletions
132
tests/unit/DeleteTransactionNavigateBackHandlerTest.tsx
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,132 @@ | ||
| import {render} from '@testing-library/react-native'; | ||
|
|
||
| import TransitionTracker from '@libs/Navigation/TransitionTracker'; | ||
|
|
||
| import DeleteTransactionNavigateBackHandler from '@pages/inbox/DeleteTransactionNavigateBackHandler'; | ||
|
|
||
| import {setDeleteTransactionNavigateBackUrl} from '@userActions/Report'; | ||
|
|
||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| import type * as Navigation from '@react-navigation/native'; | ||
|
|
||
| import Onyx from 'react-native-onyx'; | ||
|
|
||
| import waitForBatchedUpdates from '../utils/waitForBatchedUpdates'; | ||
|
|
||
| jest.mock('@react-navigation/native', () => ({ | ||
| ...jest.requireActual<typeof Navigation>('@react-navigation/native'), | ||
| useIsFocused: jest.fn(() => true), | ||
| })); | ||
|
|
||
| jest.mock('@libs/Navigation/TransitionTracker', () => ({ | ||
| runAfterTransitions: jest.fn(({callback}: {callback: () => void}) => { | ||
| callback(); | ||
| return {cancel: jest.fn()}; | ||
| }), | ||
| })); | ||
|
|
||
| const REPORT_URL = 'r/123'; | ||
| const NEXT_REPORT_URL = 'r/456'; | ||
| const DUPLICATES_REVIEW_URL = 'r/123/duplicates/review'; | ||
|
|
||
| async function flushClear() { | ||
| await waitForBatchedUpdates(); | ||
| await new Promise<void>((resolve) => { | ||
| requestAnimationFrame(() => resolve()); | ||
| }); | ||
| await waitForBatchedUpdates(); | ||
| } | ||
|
|
||
| async function getNavigateBackUrl() { | ||
| return new Promise<string | undefined>((resolve) => { | ||
| const connection = Onyx.connectWithoutView({ | ||
| key: ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, | ||
| callback: (value) => { | ||
| Onyx.disconnect(connection); | ||
| resolve(value); | ||
| }, | ||
| }); | ||
| }); | ||
| } | ||
|
|
||
| describe('DeleteTransactionNavigateBackHandler', () => { | ||
| beforeAll(() => { | ||
| Onyx.init({keys: ONYXKEYS}); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await Onyx.clear(); | ||
| await waitForBatchedUpdates(); | ||
| }); | ||
|
|
||
| it('clears the navigate back URL when the focused screen unmounts', async () => { | ||
| // Given a focused expense screen that was just deleted, so the URL is set while it is still focused | ||
| const {unmount} = render(<DeleteTransactionNavigateBackHandler />); | ||
| await Onyx.set(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, REPORT_URL); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // When the native stack pops it, it unmounts without ever rendering unfocused | ||
| unmount(); | ||
| await flushClear(); | ||
|
|
||
| // Then the URL is cleared so it does not leak into the next expense | ||
| expect(await getNavigateBackUrl()).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('keeps the navigate back URL while the screen stays focused', async () => { | ||
| // Given a focused expense screen with the URL set | ||
| render(<DeleteTransactionNavigateBackHandler />); | ||
| await Onyx.set(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, REPORT_URL); | ||
|
|
||
| // When nothing navigates away | ||
| await flushClear(); | ||
|
|
||
| // Then the URL stays, so the deleted expense does not flash Not Found before the pop | ||
| expect(await getNavigateBackUrl()).toBe(REPORT_URL); | ||
| }); | ||
|
|
||
| it('keeps the duplicates review URL when the screen unmounts', async () => { | ||
| // Given a focused screen whose URL points to duplicates review, which clears the URL by itself | ||
| const {unmount} = render(<DeleteTransactionNavigateBackHandler />); | ||
| await Onyx.set(ONYXKEYS.NVP_DELETE_TRANSACTION_NAVIGATE_BACK_URL, DUPLICATES_REVIEW_URL); | ||
| await waitForBatchedUpdates(); | ||
|
|
||
| // When the screen unmounts | ||
| unmount(); | ||
| await flushClear(); | ||
|
|
||
| // Then the URL is left for the duplicates review flow | ||
| expect(await getNavigateBackUrl()).toBe(DUPLICATES_REVIEW_URL); | ||
| }); | ||
|
|
||
| it('does not clear a newer deletion URL from a remount clear that is still waiting', async () => { | ||
| // Given a screen that remounts without a deletion, so its clear waits for a later transition | ||
| let pendingCallback: (() => void) | undefined; | ||
| let isCancelled = false; | ||
| jest.mocked(TransitionTracker.runAfterTransitions).mockImplementationOnce(({callback}) => { | ||
| pendingCallback = () => { | ||
| callback(); | ||
| }; | ||
| return { | ||
| cancel: () => { | ||
| isCancelled = true; | ||
| }, | ||
| }; | ||
| }); | ||
| const {unmount} = render(<DeleteTransactionNavigateBackHandler />); | ||
| unmount(); | ||
|
|
||
| // When the next expense is deleted before that transition finishes | ||
| setDeleteTransactionNavigateBackUrl(NEXT_REPORT_URL); | ||
| await waitForBatchedUpdates(); | ||
| if (!isCancelled) { | ||
| pendingCallback?.(); | ||
| } | ||
| await flushClear(); | ||
|
|
||
| // Then the stale clear is cancelled and the new URL stays until its own screen leaves | ||
| expect(isCancelled).toBe(true); | ||
| expect(await getNavigateBackUrl()).toBe(NEXT_REPORT_URL); | ||
| }); | ||
| }); |
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.