-
Notifications
You must be signed in to change notification settings - Fork 4k
Expense - Thread header shows "workspace rules" link in HTML tags #75457 #75497
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
Closed
Closed
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| import {render, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import DisplayNames from '@components/DisplayNames'; | ||
|
|
||
| jest.mock('@hooks/useLocalize', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| default: () => ({ | ||
| translate: jest.fn((key: string): string => { | ||
| if (key === 'common.hidden') { | ||
| return 'hidden'; | ||
| } | ||
| return key; | ||
| }), | ||
| }), | ||
| })); | ||
|
|
||
| jest.mock('@libs/Parser', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| default: { | ||
| htmlToText: jest.fn((html: string) => { | ||
| // Simulate stripTag behavior: remove anything that looks like HTML tags | ||
| return html.replaceAll(/(<([^>]+)>)/gi, ''); | ||
| }), | ||
| }, | ||
| })); | ||
|
|
||
| jest.mock('@libs/StringUtils', () => ({ | ||
| // eslint-disable-next-line @typescript-eslint/naming-convention | ||
| __esModule: true, | ||
| default: { | ||
| lineBreaksToSpaces: jest.fn((text: string) => text), | ||
| }, | ||
| })); | ||
|
|
||
| describe('DisplayNames - Thread Header HTML Parsing', () => { | ||
| afterEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should parse HTML when shouldParseHtml is true (for thread headers)', () => { | ||
| const htmlTitle = 'approved via <a href="https://example.com">workspace rules</a>'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={htmlTitle} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml | ||
| />, | ||
| ); | ||
|
|
||
| // With shouldParseHtml = true, HTML tags should be stripped | ||
| expect(screen.getByText('approved via workspace rules')).toBeTruthy(); | ||
| expect(screen.queryByText(htmlTitle)).toBeNull(); | ||
| }); | ||
|
|
||
| it('should NOT parse HTML when shouldParseHtml is false (for group chats)', () => { | ||
| const titleWithBrackets = 'Test <Company>'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={titleWithBrackets} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml={false} | ||
| />, | ||
| ); | ||
|
|
||
| // With shouldParseHtml = false, angle brackets should be preserved | ||
| expect(screen.getByText('Test <Company>')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should parse mention-user tags when shouldParseHtml is true', () => { | ||
| const htmlWithMention = 'changed the approver to <mention-user accountID="12345">@John Doe</mention-user>'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={htmlWithMention} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml | ||
| />, | ||
| ); | ||
|
|
||
| // mention-user tags should be stripped | ||
| expect(screen.getByText('changed the approver to @John Doe')).toBeTruthy(); | ||
| expect(screen.queryByText(htmlWithMention)).toBeNull(); | ||
| }); | ||
|
|
||
| it('should parse integration sync failed message HTML', () => { | ||
| const integrationHTML = 'there was a problem syncing. Please fix the issue in <a href="https://example.com/settings">workspace settings</a>.'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={integrationHTML} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml | ||
| />, | ||
| ); | ||
|
|
||
| // HTML link should be stripped | ||
| expect(screen.getByText('there was a problem syncing. Please fix the issue in workspace settings.')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should parse multiple automatic workflow HTML messages', () => { | ||
| const testCases = [ | ||
| { | ||
| html: 'approved via <a href="https://example.com">workspace rules</a>', | ||
| expected: 'approved via workspace rules', | ||
| }, | ||
| { | ||
| html: 'paid $100.00 with bank account 1234 via <a href="https://example.com">workspace rules</a>', | ||
| expected: 'paid $100.00 with bank account 1234 via workspace rules', | ||
| }, | ||
| { | ||
| html: 'paid with Expensify via <a href="https://example.com">workspace rules</a>', | ||
| expected: 'paid with Expensify via workspace rules', | ||
| }, | ||
| ]; | ||
|
|
||
| testCases.forEach(({html, expected}) => { | ||
| const {unmount} = render( | ||
| <DisplayNames | ||
| fullTitle={html} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml | ||
| />, | ||
| ); | ||
|
|
||
| expect(screen.getByText(expected)).toBeTruthy(); | ||
| unmount(); | ||
| }); | ||
| }); | ||
|
|
||
| it('should default to shouldParseHtml=false to preserve group chat names', () => { | ||
| const groupChatName = 'Engineering <Team>'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={groupChatName} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| // Not passing shouldParseHtml, should default to false | ||
| />, | ||
| ); | ||
|
|
||
| // Angle brackets should be preserved with default behavior | ||
| expect(screen.getByText('Engineering <Team>')).toBeTruthy(); | ||
| }); | ||
|
|
||
| it('should show "hidden" when title becomes empty after HTML parsing', () => { | ||
| const onlyTagsTitle = '<div></div>'; | ||
| render( | ||
| <DisplayNames | ||
| fullTitle={onlyTagsTitle} | ||
| numberOfLines={1} | ||
| tooltipEnabled={false} | ||
| shouldParseHtml | ||
| />, | ||
| ); | ||
|
|
||
| // After parsing, only tags remain which get stripped to empty string | ||
| expect(screen.getByText('hidden')).toBeTruthy(); | ||
| }); | ||
| }); |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have DisplayNamesShouldParseHTMLTest, so if any cases are not covered, please add them there and don't duplicate. Also, please refrain from adding comments if the code explains itself.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QichenZhu I am hitting a blocker running the end to end tests due to the process of adding the mock accounts to test properly for the regression I am going to need to come back to this tomorrow fresh after my day job I can resume 11/19/25 16:00. I will update the branch with your requested revisions when I get back to this Note: We should be to solve #75470 in this PR as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay will do,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's urgent, mind if I take over to speed things up?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QichenZhu I would be very grateful for your assistance.