-
Notifications
You must be signed in to change notification settings - Fork 4k
Replace getDisplayNameOrDefault with temporaryGetDisplayNameOrDefault - batch 10 #96554
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
mountiny
merged 2 commits into
Expensify:main
from
cretadn22:migrate-temporaryGetDisplayNameOrDefault-batch-10
Jul 24, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,33 @@ | ||
| import {getSortedPersonalDetails} from '@libs/SuggestionUtils'; | ||
|
|
||
| import {localeCompare} from '../utils/TestHelper'; | ||
| import {localeCompare, translateLocal} from '../utils/TestHelper'; | ||
|
|
||
| describe('SuggestionUtils', () => { | ||
| describe('getSortedPersonalDetails', () => { | ||
| it('Should sort using the weight if the weight is different', () => { | ||
| const first = {login: 'John Doe', weight: 1, accountID: 1}; | ||
| const second = {login: 'Jane Doe', weight: 2, accountID: 2}; | ||
| expect(getSortedPersonalDetails([second, first], localeCompare)).toEqual([first, second]); | ||
| expect(getSortedPersonalDetails([second, first], localeCompare, translateLocal)).toEqual([first, second]); | ||
| }); | ||
|
|
||
| it('Should sort using the displayName if the weight is the same', () => { | ||
| const first = {login: 'águero', weight: 2, accountID: 3}; | ||
| const second = {login: 'Bronn', weight: 2, accountID: 4}; | ||
| const third = {login: 'Carol', weight: 2, accountID: 5}; | ||
| expect(getSortedPersonalDetails([second, first, third], localeCompare)).toEqual([first, second, third]); | ||
| expect(getSortedPersonalDetails([third, second, first], localeCompare)).toEqual([first, second, third]); | ||
| expect(getSortedPersonalDetails([second, first, third], localeCompare, translateLocal)).toEqual([first, second, third]); | ||
| expect(getSortedPersonalDetails([third, second, first], localeCompare, translateLocal)).toEqual([first, second, third]); | ||
| }); | ||
|
|
||
| it('Should sort using the accountID if both the weight and displayName are the same', () => { | ||
| const first = {login: 'aguero', weight: 2, accountID: 6}; | ||
| const second = {login: 'aguero', weight: 2, accountID: 7}; | ||
| expect(getSortedPersonalDetails([second, first], localeCompare)).toEqual([first, second]); | ||
| expect(getSortedPersonalDetails([second, first], localeCompare, translateLocal)).toEqual([first, second]); | ||
| }); | ||
|
|
||
| it('Should sort using the displayName with different diacritics if the weight is the same', () => { | ||
| const first = {login: 'águero', weight: 2, accountID: 8}; | ||
| const second = {login: 'aguero', weight: 2, accountID: 8}; | ||
| expect(getSortedPersonalDetails([second, first], localeCompare)).toEqual([second, first]); | ||
| expect(getSortedPersonalDetails([second, first], localeCompare, translateLocal)).toEqual([second, first]); | ||
| }); | ||
| }); | ||
| }); |
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,53 @@ | ||
| import type {LocalizedTranslate} from '@components/LocaleContextProvider'; | ||
|
|
||
| import {getDisplayNameForParticipant} from '@libs/ReportUtils'; | ||
| import {getSortedPersonalDetails} from '@libs/SuggestionUtils'; | ||
|
|
||
| import type {PersonalDetails} from '@src/types/onyx'; | ||
|
|
||
| import {localeCompare, translateLocal} from '../utils/TestHelper'; | ||
|
|
||
| jest.mock('@libs/ReportUtils', () => { | ||
| // jest.requireActual is typed as returning `any`, so this assignment is unavoidably unsafe. | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment | ||
| const actual = jest.requireActual('@libs/ReportUtils'); | ||
|
cretadn22 marked this conversation as resolved.
|
||
| // Spreading the actual (untyped `any`) module into the mock makes the return intentionally unsafe. | ||
| // eslint-disable-next-line @typescript-eslint/no-unsafe-return | ||
| return { | ||
| ...actual, | ||
| __esModule: true, | ||
| getDisplayNameForParticipant: jest.fn(({accountID}: {accountID: number}) => `Name ${accountID}`), | ||
| }; | ||
| }); | ||
|
|
||
| const mockGetDisplayNameForParticipant = jest.mocked(getDisplayNameForParticipant); | ||
|
|
||
| describe('SuggestionUtils - getSortedPersonalDetails translate threading', () => { | ||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('passes the provided translate function to getDisplayNameForParticipant', () => { | ||
| const first = {login: 'first@test.com', weight: 2, accountID: 801} as PersonalDetails & {weight: number}; | ||
| const second = {login: 'second@test.com', weight: 2, accountID: 802} as PersonalDetails & {weight: number}; | ||
|
|
||
| getSortedPersonalDetails([second, first], localeCompare, translateLocal); | ||
|
|
||
| // The sort comparator resolves each display name via getDisplayNameForParticipant, which must receive the provided translate. | ||
| expect(mockGetDisplayNameForParticipant).toHaveBeenCalledWith(expect.objectContaining({translate: translateLocal})); | ||
| }); | ||
|
|
||
| it('sorts by the display name resolved through the provided translate function', () => { | ||
| // Same weight forces the comparator to fall back to display names, which come from the provided translate. | ||
| const alpha = {login: 'zzz@test.com', weight: 5, accountID: 811} as PersonalDetails & {weight: number}; | ||
| const beta = {login: 'aaa@test.com', weight: 5, accountID: 812} as PersonalDetails & {weight: number}; | ||
| // translate drives the resolved name: account 811 -> 'Aaa', account 812 -> 'Zzz'. | ||
| const translateWithNames: LocalizedTranslate = translateLocal; | ||
| mockGetDisplayNameForParticipant.mockImplementation(({accountID}) => (accountID === 811 ? 'Aaa' : 'Zzz')); | ||
|
|
||
| const sorted = getSortedPersonalDetails([beta, alpha], localeCompare, translateWithNames); | ||
|
|
||
| // Despite beta being passed first, account 811 ('Aaa') sorts ahead of account 812 ('Zzz'). | ||
| expect(sorted.map((detail) => detail.accountID)).toEqual([811, 812]); | ||
| }); | ||
| }); | ||
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.