2022-04-22 08:33:13 -05:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
2021-07-13 03:51:34 -05:00
|
|
|
import React from 'react';
|
2022-06-09 04:10:48 -05:00
|
|
|
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-07-13 03:51:34 -05:00
|
|
|
import { toDataFrame, FieldType } from '@grafana/data';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2021-07-13 03:51:34 -05:00
|
|
|
import { Props, ConfigFromQueryTransformerEditor } from './ConfigFromQueryTransformerEditor';
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
jest.clearAllMocks();
|
|
|
|
});
|
|
|
|
|
|
|
|
const input = toDataFrame({
|
|
|
|
fields: [
|
|
|
|
{ name: 'Name', type: FieldType.string, values: ['Temperature', 'Pressure'] },
|
|
|
|
{ name: 'Value', type: FieldType.number, values: [10, 200] },
|
|
|
|
{ name: 'Unit', type: FieldType.string, values: ['degree', 'pressurebar'] },
|
|
|
|
{ name: 'Miiin', type: FieldType.number, values: [3, 100] },
|
|
|
|
{ name: 'max', type: FieldType.string, values: [15, 200] },
|
|
|
|
],
|
|
|
|
refId: 'A',
|
|
|
|
});
|
|
|
|
|
|
|
|
const mockOnChange = jest.fn();
|
|
|
|
|
|
|
|
const props: Props = {
|
|
|
|
input: [input],
|
|
|
|
onChange: mockOnChange,
|
|
|
|
options: {
|
|
|
|
mappings: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
const setup = (testProps?: Partial<Props>) => {
|
|
|
|
const editorProps = { ...props, ...testProps };
|
|
|
|
return render(<ConfigFromQueryTransformerEditor {...editorProps} />);
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('ConfigFromQueryTransformerEditor', () => {
|
|
|
|
it('Should be able to select config frame by refId', async () => {
|
|
|
|
setup();
|
|
|
|
|
2022-01-12 03:19:10 -06:00
|
|
|
let select = (await screen.findByText('Config query')).nextSibling!.firstChild!;
|
2021-07-13 03:51:34 -05:00
|
|
|
await fireEvent.keyDown(select, { keyCode: 40 });
|
2021-07-14 08:04:23 -05:00
|
|
|
await selectOptionInTest(select as HTMLElement, 'A');
|
2021-07-13 03:51:34 -05:00
|
|
|
|
|
|
|
expect(mockOnChange).toHaveBeenCalledWith(
|
|
|
|
expect.objectContaining({
|
|
|
|
configRefId: 'A',
|
|
|
|
})
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|