Repository navigation
fix(pr3620-followup): Codex post-merge round — useCallback, FK index, reminder suppression #3640
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 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a7420a1
fix(pr3620): address Codex round — useCallback, FK index, reminder su…
ogabasseyy ec6536e
fix(pr3640): address review round 2 — concurrent index, split tests, …
ogabasseyy 2424306
fix(pr3640): address review round 3 — effect sync, exact index shape
ogabasseyy 10434df
fix(pr3640): address review round 4 — retain on activation, reconcile…
ogabasseyy e97f5f2
fix(pr3640): address review round 5 — persist-while-suppressed, recon…
ogabasseyy b2a4eff
fix(pr3640): address review round 6 — activation split, mutex-free fetch
ogabasseyy fefa83a
fix(pr3640): address review round 7 — reconcile-all-paths, gating, pa…
ogabasseyy 022b54a
fix(pr3640): retirement runs even when arming is impossible
ogabasseyy 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
97 changes: 97 additions & 0 deletions
97
apps/mobile-storefront/components/ui/use-address-prediction-select.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,97 @@ | ||
| import { describe, expect, it, jest } from '@jest/globals'; | ||
| import { act, renderHook } from '@testing-library/react-native'; | ||
| import type { MutableRefObject } from 'react'; | ||
| import type { PlacePrediction } from './AddressAutocomplete.types'; | ||
|
|
||
| const mockFetchPlaceDetails = jest.fn<() => Promise<{ ok: true }>>(); | ||
| const mockApplyPlaceSelection = jest.fn<() => void>(); | ||
|
|
||
| jest.mock('./AddressAutocomplete.api', () => ({ | ||
| fetchPlaceDetails: mockFetchPlaceDetails, | ||
| })); | ||
| jest.mock('./apply-place-selection', () => ({ | ||
| applyPlaceSelection: mockApplyPlaceSelection, | ||
| })); | ||
|
|
||
| // Deferred require: the mocks above must initialize before the hook module | ||
| // loads, otherwise the mock factories capture uninitialized bindings. | ||
| const { usePredictionSelectHandler } = | ||
| require('./use-address-prediction-select') as typeof import('./use-address-prediction-select'); | ||
|
|
||
| function setup() { | ||
| const isMountedRef = { current: true } as MutableRefObject<boolean>; | ||
| const latestQueryRef = { current: '' } as MutableRefObject<string>; | ||
| return { | ||
| isMountedRef, | ||
| latestQueryRef, | ||
| onChangeText: jest.fn(), | ||
| onSelect: jest.fn(), | ||
| setInternalValue: jest.fn(), | ||
| setIsLoading: jest.fn(), | ||
| setPredictions: jest.fn(), | ||
| setSessionToken: jest.fn(), | ||
| }; | ||
| } | ||
|
|
||
| const prediction = { | ||
| mainText: '221B Baker Street', | ||
| placeId: 'place-1', | ||
| secondaryText: 'London', | ||
| } as PlacePrediction; | ||
|
|
||
| describe('usePredictionSelectHandler identity', () => { | ||
| it('keeps a stable handler across unrelated re-renders', () => { | ||
| const deps = setup(); | ||
| const { result, rerender } = renderHook( | ||
| ({ sessionToken }: { sessionToken: string }) => | ||
| usePredictionSelectHandler({ ...deps, sessionToken }), | ||
| { initialProps: { sessionToken: 'session-a' } } | ||
| ); | ||
| const first = result.current; | ||
|
|
||
| // Unrelated re-render (new props object, same values): the | ||
| // suggestions-portal effect depends on this identity, so it must not | ||
| // tear down and restart portal tracking. | ||
| rerender({ sessionToken: 'session-a' }); | ||
|
|
||
| expect(result.current).toBe(first); | ||
| }); | ||
|
|
||
| it('keeps the same handler when the session token changes', () => { | ||
| const deps = setup(); | ||
| const { result, rerender } = renderHook( | ||
| ({ sessionToken }: { sessionToken: string }) => | ||
| usePredictionSelectHandler({ ...deps, sessionToken }), | ||
| { initialProps: { sessionToken: 'session-a' } } | ||
| ); | ||
| const first = result.current; | ||
|
|
||
| rerender({ sessionToken: 'session-b' }); | ||
|
|
||
| expect(result.current).toBe(first); | ||
| }); | ||
|
|
||
| it('invokes the latest session token after a token change', async () => { | ||
| mockFetchPlaceDetails.mockResolvedValue({ ok: true }); | ||
| const deps = setup(); | ||
| const { result, rerender } = renderHook( | ||
| ({ sessionToken }: { sessionToken: string }) => | ||
| usePredictionSelectHandler({ ...deps, sessionToken }), | ||
| { initialProps: { sessionToken: 'session-a' } } | ||
| ); | ||
|
|
||
| rerender({ sessionToken: 'session-b' }); | ||
|
|
||
| await act(async () => { | ||
| await result.current(prediction); | ||
| }); | ||
|
|
||
| expect(mockFetchPlaceDetails).toHaveBeenCalledWith({ | ||
| prediction, | ||
| sessionToken: 'session-b', | ||
| }); | ||
| expect(mockApplyPlaceSelection).toHaveBeenCalledWith( | ||
| expect.objectContaining({ details: { ok: true } }) | ||
| ); | ||
| }); | ||
| }); |
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
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.