forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request Expensify#55216 from Shahidullah-Muffakir/fix/55032
Add tooltip for the inactive tab in the create expense page when the tab title is hidden
- Loading branch information
Showing
2 changed files
with
102 additions
and
19 deletions.
There are no files selected for viewing
This file contains 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 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,77 @@ | ||
import {render} from '@testing-library/react-native'; | ||
import React from 'react'; | ||
import TabSelectorItem from '@components/TabSelector/TabSelectorItem'; | ||
import Tooltip from '@components/Tooltip'; | ||
|
||
// Mock the Tooltip component since it uses portals which aren't supported in RNTL | ||
jest.mock('@components/Tooltip'); | ||
|
||
describe('TabSelectorItem Component', () => { | ||
const title = 'Test Tab'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
it('should show tooltip for inactive tab with hidden label', () => { | ||
// Given an inactive tab with a hidden label | ||
render( | ||
<TabSelectorItem | ||
title={title} | ||
shouldShowLabelWhenInactive={false} | ||
isActive={false} | ||
/>, | ||
); | ||
|
||
// Then the tooltip should be rendered with correct content because the label is hidden | ||
expect(Tooltip).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
shouldRender: true, | ||
text: title, | ||
}), | ||
expect.any(Object), | ||
); | ||
}); | ||
|
||
it('should not show tooltip for active tab', () => { | ||
// Given an active tab | ||
render( | ||
<TabSelectorItem | ||
title={title} | ||
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: title, | ||
}), | ||
expect.any(Object), | ||
); | ||
}); | ||
|
||
it('should not show tooltip when label is visible', () => { | ||
// Given an inactive tab with visible label | ||
render( | ||
<TabSelectorItem | ||
title={title} | ||
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: title, | ||
}), | ||
expect.any(Object), | ||
); | ||
}); | ||
}); |