Skip to content

Commit

Permalink
test: add vrt for tooltip value formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
rshen91 committed Dec 27, 2021
1 parent 9cc4031 commit d41cb16
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions integration/tests/goal_stories.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ describe('Goal stories', () => {
'http://localhost:9001/?path=/story/goal-alpha--gauge-with-target&knob-angleStart (n * π/8)=11&knob-angleEnd (n * π/8)=-3',
);
});

it('should show custom value formatter in tooltip', async () => {
await common.expectChartWithMouseAtUrlToMatchScreenshot(
'http://localhost:9001/?path=/story/goal-alpha--gauge-with-target&knob-test tooltip value formatter=true',
{ right: 245, bottom: 120 },
);
});
});

eachTheme.describe((_, params) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const getTooltipInfoSelector = createCustomCachedSelector(
if (!spec) {
return EMPTY_TOOLTIP;
}
const { valueFormatter } = spec;
const { valueFormatter, id } = spec;

const tooltipInfo: TooltipInfo = {
header: null,
values: [],
Expand All @@ -43,8 +44,8 @@ export const getTooltipInfoSelector = createCustomCachedSelector(
isHighlighted: false,
isVisible: true,
seriesIdentifier: {
specId: spec.id,
key: spec.id,
specId: id,
key: id,
},
value,
formattedValue: valueFormatter ? valueFormatter(value) : `${value}`,
Expand Down
4 changes: 3 additions & 1 deletion storybook/stories/goal/2_gauge_with_target.story.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ export const Example = () => {
}) *
(Math.PI / 8);

const useValueFormatter = boolean('test tooltip value formatter', false);

return (
<Chart>
<Settings baseTheme={useBaseTheme()} />
Expand All @@ -74,7 +76,7 @@ export const Example = () => {
centralMinor=""
angleStart={angleStart}
angleEnd={angleEnd}
valueFormatter={(d: any) => `${d}`}
valueFormatter={useValueFormatter ? (d: any) => `Testing ${d}` : undefined}
/>
</Chart>
);
Expand Down

0 comments on commit d41cb16

Please sign in to comment.