mirror of https://github.com/grafana/grafana.git
Tooltip Filter: Add test for Filter for value (#110308)
chore(adhoc-filter): add tests
This commit is contained in:
parent
fd9d41fe4f
commit
97f1ed0b88
|
@ -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(
|
||||
<MemoryRouter>
|
||||
<VizTooltipFooter dataLinks={[]} adHocFilters={[adHocFilter]} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
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<Field> = {
|
||||
href: '#',
|
||||
onClick,
|
||||
title: 'One Click Link',
|
||||
origin: field,
|
||||
target: undefined,
|
||||
oneClick: true,
|
||||
};
|
||||
|
||||
const adHocFilter: AdHocFilterModel = {
|
||||
key: 'testKey',
|
||||
operator: '=',
|
||||
value: 'testValue',
|
||||
onClick: onFilterClick,
|
||||
};
|
||||
|
||||
render(
|
||||
<MemoryRouter>
|
||||
<VizTooltipFooter dataLinks={[oneClickLink]} adHocFilters={[adHocFilter]} />
|
||||
</MemoryRouter>
|
||||
);
|
||||
|
||||
expect(screen.queryByRole('button', { name: /filter for 'testValue'/i })).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue