-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Update search total amount footer logic #79178
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
19 commits
Select commit
Hold shift + click to select a range
333ac3e
Update search total amount footer logic
ShridharGoel e38609a
Update isSavedSearch
ShridharGoel 9b313a5
Use better logic
ShridharGoel 6e6a87e
Update tests
ShridharGoel 872ba8a
Fix lint
ShridharGoel f4c1a3d
Update
ShridharGoel 055960c
Merge branch 'main' of https://github.com/Expensify/App into issue78149
ShridharGoel d67aee2
Make branch match upstream/main
ShridharGoel ef6cffe
Update search total amount footer logic
ShridharGoel cb89510
revert the extra changes
ShridharGoel fb8f3e3
revert the older changes
ShridharGoel 8e1285b
Update search total amount footer logic
ShridharGoel 2fc2450
Merge main
ShridharGoel 51c39b8
Updates
ShridharGoel e875cde
Add tests
ShridharGoel 22a1208
Fix prettier
ShridharGoel 0156030
Lint fixes
ShridharGoel d5bc8c0
Merge main
ShridharGoel 15809e6
Ensure totals are fetched when needed
ShridharGoel 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
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,78 @@ | ||
| import {renderHook} from '@testing-library/react-native'; | ||
| import useSearchShouldCalculateTotals from '@hooks/useSearchShouldCalculateTotals'; | ||
| import CONST from '@src/CONST'; | ||
| import ONYXKEYS from '@src/ONYXKEYS'; | ||
|
|
||
| const onyxData: Record<string, unknown> = {}; | ||
|
|
||
| const mockUseOnyx = jest.fn( | ||
| ( | ||
| key: string, | ||
| options?: { | ||
| selector?: (value: unknown) => unknown; | ||
| }, | ||
| ) => { | ||
| const value = onyxData[key]; | ||
| const selectedValue = options?.selector ? options.selector(value as never) : value; | ||
| return [selectedValue]; | ||
| }, | ||
| ); | ||
|
|
||
| jest.mock('@hooks/useOnyx', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| default: (key: string, options?: {selector?: (value: unknown) => unknown}) => mockUseOnyx(key, options), | ||
| })); | ||
|
|
||
| describe('useSearchShouldCalculateTotals', () => { | ||
| beforeEach(() => { | ||
| onyxData[ONYXKEYS.SAVED_SEARCHES] = undefined; | ||
| mockUseOnyx.mockClear(); | ||
| }); | ||
|
|
||
| it('returns false when disabled', () => { | ||
| const {result} = renderHook(() => useSearchShouldCalculateTotals(CONST.SEARCH.SEARCH_KEYS.SUBMIT, 123, false)); | ||
|
|
||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('returns true for eligible suggested searches', () => { | ||
| const {result} = renderHook(() => useSearchShouldCalculateTotals(CONST.SEARCH.SEARCH_KEYS.SUBMIT, 123, true)); | ||
|
|
||
| expect(result.current).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false for non-eligible searches', () => { | ||
| const {result} = renderHook(() => useSearchShouldCalculateTotals(CONST.SEARCH.SEARCH_KEYS.EXPENSES, 123, true)); | ||
|
|
||
| expect(result.current).toBe(false); | ||
| }); | ||
|
|
||
| it('returns true for saved searches that match the hash', () => { | ||
| onyxData[ONYXKEYS.SAVED_SEARCHES] = { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| 456: { | ||
| name: 'My search', | ||
| query: 'type:expense', | ||
| }, | ||
| }; | ||
|
|
||
| const {result} = renderHook(() => useSearchShouldCalculateTotals(undefined, 456, true)); | ||
|
|
||
| expect(result.current).toBe(true); | ||
| }); | ||
|
|
||
| it('returns false when saved searches do not match the hash', () => { | ||
| onyxData[ONYXKEYS.SAVED_SEARCHES] = { | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| 456: { | ||
| name: 'My search', | ||
| query: 'type:expense', | ||
| }, | ||
| }; | ||
|
|
||
| const {result} = renderHook(() => useSearchShouldCalculateTotals(undefined, 789, true)); | ||
|
|
||
| expect(result.current).toBe(false); | ||
| }); | ||
| }); |
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.