-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Add tooltip for the inactive tab in the create expense page when the tab title is hidden #55216
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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import {fireEvent, render, screen} from '@testing-library/react-native'; | ||
| import React from 'react'; | ||
| import TabSelectorItem from '@components/TabSelector/TabSelectorItem'; | ||
| import Tooltip from '@components/Tooltip'; | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| // Mock the Tooltip component since it uses portals which aren't supported in RNTL | ||
| jest.mock('@components/Tooltip', () => { | ||
| return jest.fn(({children, shouldRender, text}: {children: React.ReactNode; shouldRender: boolean; text: string}) => { | ||
| return ( | ||
| <> | ||
| {shouldRender && <div data-testid="tooltip">{text}</div>} | ||
| {children} | ||
| </> | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| describe('TabSelectorItem Component', () => { | ||
| const defaultProps = { | ||
| title: 'Test Tab', | ||
| icon: 'icon-home', | ||
| onPress: jest.fn(), | ||
| }; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unused parameters, we just use the
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also use it below as a |
||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| it('should show tooltip for inactive tab with hidden label', () => { | ||
| // Given an inactive tab with a hidden label | ||
| render( | ||
| <TabSelectorItem | ||
| title="Test Tab" | ||
| shouldShowLabelWhenInactive={false} | ||
| isActive={false} | ||
| />, | ||
| ); | ||
|
|
||
| // When hovering over the tab button | ||
| const button = screen.getByRole(CONST.ROLE.BUTTON, {name: defaultProps.title}); | ||
| fireEvent(button, 'hoverIn'); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the valuable feedback, updated. |
||
|
|
||
| // Then the tooltip should be rendered with correct content because the label is hidden | ||
| expect(Tooltip).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| shouldRender: true, | ||
| text: defaultProps.title, | ||
| }), | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
|
|
||
| it('should not show tooltip for active tab', () => { | ||
| // Given an active tab | ||
| render( | ||
| <TabSelectorItem | ||
| title="Test Tab" | ||
| shouldShowLabelWhenInactive={false} | ||
| isActive | ||
| />, | ||
| ); | ||
|
|
||
| // When hovering over the tab button | ||
| // Then the tooltip should not render because the tab is active | ||
| expect(Tooltip).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| shouldRender: false, | ||
| text: defaultProps.title, | ||
| }), | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
|
|
||
| it('should not show tooltip when label is visible', () => { | ||
| // Given an inactive tab with visible label | ||
| render( | ||
| <TabSelectorItem | ||
| title="Test Tab" | ||
| shouldShowLabelWhenInactive | ||
| isActive={false} | ||
| />, | ||
| ); | ||
|
|
||
| // When hovering over the tab button | ||
| // Then the tooltip should not render because the label is already visible | ||
| expect(Tooltip).toHaveBeenCalledWith( | ||
| expect.objectContaining({ | ||
| shouldRender: false, | ||
| text: defaultProps.title, | ||
| }), | ||
| expect.any(Object), | ||
| ); | ||
| }); | ||
| }); | ||
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.
Since we just test with
toHaveBeenCalledWith, I think we can simply mock with emptyjest.fn