mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki Monaco Editor: add component tests (#56658)
* feat(loki-monaco-editor): add component tests * feat(loki-monaco-editor): rename test case * Chore: add missing export
This commit is contained in:
parent
811f6054c8
commit
1b7e31cd27
@ -0,0 +1,36 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import LokiLanguageProvider from '../../LanguageProvider';
|
||||
import { createLokiDatasource } from '../../mocks';
|
||||
|
||||
import { MonacoQueryFieldWrapper, Props } from './MonacoQueryFieldWrapper';
|
||||
|
||||
function renderComponent({
|
||||
initialValue = '',
|
||||
onChange = jest.fn(),
|
||||
onRunQuery = jest.fn(),
|
||||
runQueryOnBlur = false,
|
||||
}: Partial<Props> = {}) {
|
||||
const datasource = createLokiDatasource();
|
||||
const languageProvider = new LokiLanguageProvider(datasource);
|
||||
|
||||
render(
|
||||
<MonacoQueryFieldWrapper
|
||||
languageProvider={languageProvider}
|
||||
history={[]}
|
||||
initialValue={initialValue}
|
||||
onChange={onChange}
|
||||
onRunQuery={onRunQuery}
|
||||
runQueryOnBlur={runQueryOnBlur}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
describe('MonacoFieldWrapper', () => {
|
||||
test('Renders with no errors', async () => {
|
||||
renderComponent();
|
||||
|
||||
expect(await screen.findByText('Loading...')).toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -0,0 +1,31 @@
|
||||
import { render, screen } from '@testing-library/react';
|
||||
import React from 'react';
|
||||
|
||||
import LokiLanguageProvider from '../../LanguageProvider';
|
||||
import { createLokiDatasource } from '../../mocks';
|
||||
|
||||
import MonacoQueryField from './MonacoQueryField';
|
||||
import { Props } from './MonacoQueryFieldProps';
|
||||
|
||||
function renderComponent({ initialValue = '', onRunQuery = jest.fn(), onBlur = jest.fn() }: Partial<Props> = {}) {
|
||||
const datasource = createLokiDatasource();
|
||||
const languageProvider = new LokiLanguageProvider(datasource);
|
||||
|
||||
render(
|
||||
<MonacoQueryField
|
||||
languageProvider={languageProvider}
|
||||
initialValue={initialValue}
|
||||
history={[]}
|
||||
onRunQuery={onRunQuery}
|
||||
onBlur={onBlur}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
describe('MonacoQueryField', () => {
|
||||
test('Renders with no errors', async () => {
|
||||
renderComponent();
|
||||
|
||||
expect(await screen.findByText('Loading...')).toBeInTheDocument();
|
||||
});
|
||||
});
|
@ -3,7 +3,7 @@ import React, { useRef } from 'react';
|
||||
import { MonacoQueryFieldLazy } from './MonacoQueryFieldLazy';
|
||||
import { Props as MonacoProps } from './MonacoQueryFieldProps';
|
||||
|
||||
type Props = Omit<MonacoProps, 'onRunQuery' | 'onBlur'> & {
|
||||
export type Props = Omit<MonacoProps, 'onRunQuery' | 'onBlur'> & {
|
||||
onChange: (query: string) => void;
|
||||
onRunQuery: () => void;
|
||||
runQueryOnBlur: boolean;
|
||||
|
Loading…
Reference in New Issue
Block a user