From 97f1ed0b88bdda3b416fd8bfef39dba62f1f105a Mon Sep 17 00:00:00 2001 From: Ihor Yeromin Date: Fri, 29 Aug 2025 11:56:22 +0200 Subject: [PATCH] Tooltip Filter: Add test for Filter for value (#110308) chore(adhoc-filter): add tests --- .../VizTooltip/VizTooltipFooter.test.tsx | 59 ++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/packages/grafana-ui/src/components/VizTooltip/VizTooltipFooter.test.tsx b/packages/grafana-ui/src/components/VizTooltip/VizTooltipFooter.test.tsx index e560542843d..f23961ef5e4 100644 --- a/packages/grafana-ui/src/components/VizTooltip/VizTooltipFooter.test.tsx +++ b/packages/grafana-ui/src/components/VizTooltip/VizTooltipFooter.test.tsx @@ -4,7 +4,7 @@ import { MemoryRouter } from 'react-router-dom-v5-compat'; import { Field, FieldType, LinkModel } from '@grafana/data'; -import { VizTooltipFooter } from './VizTooltipFooter'; +import { VizTooltipFooter, AdHocFilterModel } from './VizTooltipFooter'; describe('VizTooltipFooter', () => { it('should fire onclick', async () => { @@ -32,4 +32,61 @@ describe('VizTooltipFooter', () => { await userEvent.click(screen.getByRole('link')); expect(onClick).toHaveBeenCalled(); }); + + it('should render ad hoc filter button and fire onclick', async () => { + const onFilterClick = jest.fn(); + const adHocFilter: AdHocFilterModel = { + key: 'testKey', + operator: '=', + value: 'testValue', + onClick: onFilterClick, + }; + + render( + + + + ); + + const filterButton = screen.getByRole('button', { name: /filter for 'testValue'/i }); + expect(filterButton).toBeInTheDocument(); + + await userEvent.click(filterButton); + expect(onFilterClick).toHaveBeenCalled(); + }); + + it('should not render ad hoc filter button when there are one-click links', () => { + const onFilterClick = jest.fn(); + const onClick = jest.fn(); + const field: Field = { + name: '', + type: FieldType.string, + values: [], + config: {}, + }; + + const oneClickLink: LinkModel = { + href: '#', + onClick, + title: 'One Click Link', + origin: field, + target: undefined, + oneClick: true, + }; + + const adHocFilter: AdHocFilterModel = { + key: 'testKey', + operator: '=', + value: 'testValue', + onClick: onFilterClick, + }; + + render( + + + + ); + + expect(screen.queryByRole('button', { name: /filter for 'testValue'/i })).not.toBeInTheDocument(); + }); });