grafana/public/app/plugins/datasource/opentsdb/components/MetricSection.test.tsx
Brendan O'Handley 82d8015469
OpenTSDB: Convert the OpenTSDB Query Editor from Angular to React (#54677)
* add query editor to module

* add metric section, add tests, update query type

* remove use of any for betterer

* fix test

* add tooltip for alias

* run runQuery on select change, fix metric select loading

* add downsample row, differentiate for tsdb version

* add tests for mteric section and downsample section

* add filter section react component and tests

* add tag section and tests

* add rate section and tests

* remove angular code

* fix styling

* remove comments

* remove unused code
2022-10-03 17:00:46 -04:00

69 lines
1.7 KiB
TypeScript

import { fireEvent, render, screen } from '@testing-library/react';
import React from 'react';
import { OpenTsdbQuery } from '../types';
import { MetricSection, MetricSectionProps, testIds } from './MetricSection';
const onRunQuery = jest.fn();
const onChange = jest.fn();
const setup = (propOverrides?: Object) => {
const suggestMetrics = jest.fn();
const query: OpenTsdbQuery = {
metric: 'cpu',
refId: 'A',
aggregator: 'avg',
alias: 'alias',
};
const props: MetricSectionProps = {
query,
onChange: onChange,
onRunQuery: onRunQuery,
suggestMetrics: suggestMetrics,
aggregators: ['avg'],
};
Object.assign(props, propOverrides);
return render(<MetricSection {...props} />);
};
describe('MetricSection', () => {
it('should render metrics section', () => {
setup();
expect(screen.getByTestId(testIds.section)).toBeInTheDocument();
});
beforeEach(() => {
jest.clearAllMocks();
});
describe('metric aggregator', () => {
it('should render metrics select', () => {
setup();
expect(screen.getByText('cpu')).toBeInTheDocument();
});
});
describe('metric aggregator', () => {
it('should render the metrics aggregator', () => {
setup();
expect(screen.getByText('avg')).toBeInTheDocument();
});
});
describe('metric alias', () => {
it('should render the alias input', () => {
setup();
expect(screen.getByTestId('metric-alias')).toBeInTheDocument();
});
it('should fire OnRunQuery on blur', () => {
setup();
const alias = screen.getByTestId('metric-alias');
fireEvent.click(alias);
fireEvent.blur(alias);
expect(onRunQuery).toHaveBeenCalled();
});
});
});