The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/core/components/Select/MetricSelect.test.tsx

50 lines
1.6 KiB

import { shallow } from 'enzyme';
import React from 'react';
import { LegacyForms } from '@grafana/ui';
import { MetricSelect } from './MetricSelect';
const { Select } = LegacyForms;
describe('MetricSelect', () => {
describe('When receive props', () => {
it('should pass correct set of props to Select component', () => {
const props: any = {
placeholder: 'Select Reducer',
className: 'width-15',
options: [],
variables: [],
};
const wrapper = shallow(<MetricSelect {...props} />);
expect(wrapper.find(Select).props()).toMatchObject({
className: 'width-15',
isMulti: false,
isClearable: false,
backspaceRemovesValue: false,
isSearchable: true,
maxMenuHeight: 500,
placeholder: 'Select Reducer',
});
});
it('should pass callbacks correctly to the Select component', () => {
const spyOnChange = jest.fn();
const props: any = {
onChange: spyOnChange,
options: [],
variables: [],
};
const wrapper = shallow(<MetricSelect {...props} />);
const select = wrapper.find(Select);
select.props().onChange({ value: 'foo' }, { action: 'select-option', option: undefined });
expect(select.props().noOptionsMessage).toBeDefined();
// @ts-ignore typescript doesn't understand that noOptionsMessage can't be undefined here
const noOptionsMessage = select.props().noOptionsMessage();
expect(noOptionsMessage).toEqual('No options found');
expect(spyOnChange).toHaveBeenCalledWith('foo');
});
});
});