Files
grafana/public/app/core/components/Select/MetricSelect.test.tsx
Ashley Harrison 47f8717149 React: Use new JSX transform (#88802)
* update eslint, tsconfig + esbuild to handle new jsx transform

* remove thing that breaks the new jsx transform

* remove react imports

* adjust grafana-icons build

* is this the correct syntax?

* try this

* well this was much easier than expected...

* change grafana-plugin-configs webpack config

* fixes

* fix lockfile

* fix 2 more violations

* use path.resolve instead of require.resolve

* remove react import

* fix react imports

* more fixes

* remove React import

* remove import React from docs

* remove another react import
2024-06-25 12:43:47 +01:00

52 lines
1.3 KiB
TypeScript

import { render, screen } from '@testing-library/react';
import { select, openMenu } from 'react-select-event';
import { MetricSelect, Props } from './MetricSelect';
const props: Props = {
isSearchable: false,
onChange: jest.fn(),
value: '',
placeholder: 'Select Reducer',
className: 'width-15',
options: [
{
label: 'foo',
value: 'foo',
},
{
label: 'bar',
value: 'bar',
},
],
variables: [],
};
describe('MetricSelect', () => {
it('passes the placeholder, options and onChange correctly to Select', async () => {
render(<MetricSelect {...props} />);
const metricSelect = screen.getByRole('combobox');
expect(metricSelect).toBeInTheDocument();
expect(screen.getByText('Select Reducer')).toBeInTheDocument();
await select(metricSelect, 'foo', {
container: document.body,
});
expect(props.onChange).toHaveBeenCalledWith('foo');
});
it('has the correct noOptionsMessage', () => {
const propsWithoutOptions = {
...props,
options: [],
};
render(<MetricSelect {...propsWithoutOptions} />);
const metricSelect = screen.getByRole('combobox');
expect(metricSelect).toBeInTheDocument();
openMenu(metricSelect);
expect(screen.getByText('No options found')).toBeInTheDocument();
});
});