mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* refactor(selectoptiontest): move helper function out of grafana/ui so testing-lib isn't in bundle * test(selectoptionintest): update import location of helper function * test(amroutes): put back missing selectOptionInTest helper * test(selectoptionintest): clean up remaining file imports / exports * test(queryeditor): fix failing import * refactor(grafana-ui): reuse selectOptionInTest in SelectBase test
54 lines
1.5 KiB
TypeScript
54 lines
1.5 KiB
TypeScript
import { fireEvent, render, screen } from '@testing-library/react';
|
|
import React from 'react';
|
|
import { selectOptionInTest } from 'test/helpers/selectOptionInTest';
|
|
|
|
import { toDataFrame, FieldType } from '@grafana/data';
|
|
|
|
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();
|
|
|
|
let select = (await screen.findByText('Config query')).nextSibling!.firstChild!;
|
|
await fireEvent.keyDown(select, { keyCode: 40 });
|
|
await selectOptionInTest(select as HTMLElement, 'A');
|
|
|
|
expect(mockOnChange).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
configRefId: 'A',
|
|
})
|
|
);
|
|
});
|
|
});
|