-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename useRenderTooltipContent to getTooltipContentRenderer
- Loading branch information
Showing
8 changed files
with
105 additions
and
10 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
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
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
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
78 changes: 78 additions & 0 deletions
78
packages/polaris-viz/src/utilities/tests/getTooltipContentRenderer.test.tsx
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,78 @@ | ||
import {Fragment} from 'react'; | ||
|
||
import {mountWithProvider} from '../../test-utilities/mountWithProvider'; | ||
import {TooltipContent} from '../../components'; | ||
import type {RenderTooltipContentData} from '../../types'; | ||
import {getTooltipContentRenderer} from '../getTooltipContentRenderer'; | ||
|
||
describe('getTooltipContentRenderer()', () => { | ||
it('returns <TooltipContent />', () => { | ||
const renderTooltipContent = getTooltipContentRenderer({ | ||
theme: 'Default', | ||
data: [], | ||
}); | ||
|
||
const result = mountWithProvider( | ||
<Fragment>{renderTooltipContent(MOCK_TOOLTIP_DATA)}</Fragment>, | ||
); | ||
|
||
expect(result).toContainReactComponent(TooltipContent); | ||
}); | ||
|
||
it('returns null when no data is provided', () => { | ||
const renderTooltipContent = getTooltipContentRenderer({ | ||
theme: 'Default', | ||
data: [], | ||
}); | ||
|
||
expect( | ||
renderTooltipContent({ | ||
...MOCK_TOOLTIP_DATA, | ||
data: [ | ||
{ | ||
shape: 'Line', | ||
data: [], | ||
name: '', | ||
}, | ||
], | ||
}), | ||
).toBeNull(); | ||
}); | ||
|
||
it('returns a custom function when tooltipOptions.renderTooltipContent is provided', () => { | ||
const customRenderer = jest.fn(); | ||
|
||
const renderTooltipContent = getTooltipContentRenderer({ | ||
theme: 'Default', | ||
data: [], | ||
tooltipOptions: { | ||
renderTooltipContent: customRenderer, | ||
}, | ||
}); | ||
|
||
mountWithProvider( | ||
<Fragment>{renderTooltipContent(MOCK_TOOLTIP_DATA)}</Fragment>, | ||
); | ||
|
||
expect(customRenderer).toHaveBeenCalled(); | ||
}); | ||
}); | ||
|
||
const MOCK_TOOLTIP_DATA: RenderTooltipContentData = { | ||
data: [ | ||
{ | ||
shape: 'Line', | ||
data: [ | ||
{ | ||
key: 'Monday', | ||
value: 3, | ||
}, | ||
], | ||
name: '', | ||
}, | ||
], | ||
activeIndex: 0, | ||
dataSeries: [], | ||
theme: 'Default', | ||
title: '', | ||
}; |