mirror of
https://github.com/grafana/grafana.git
synced 2025-08-06 20:59:35 +08:00
CloudMonitoring: add tests around experimental UI (#52487)
* CloudMonitoring: add tests around experimental UI I also reworked the annotation query editor UI a little bit to bring it inline with how AzureMonitor's query editor looks. Closes #44431
This commit is contained in:
@ -13,6 +13,7 @@ export const createMockDatasource = (overrides?: Partial<Datasource>) => {
|
|||||||
getProjects: jest.fn().mockResolvedValue([]),
|
getProjects: jest.fn().mockResolvedValue([]),
|
||||||
getDefaultProject: jest.fn().mockReturnValue('cloud-monitoring-default-project'),
|
getDefaultProject: jest.fn().mockReturnValue('cloud-monitoring-default-project'),
|
||||||
templateSrv,
|
templateSrv,
|
||||||
|
getSLOServices: jest.fn().mockResolvedValue([]),
|
||||||
...overrides,
|
...overrides,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@ import React, { useState } from 'react';
|
|||||||
import { useDebounce } from 'react-use';
|
import { useDebounce } from 'react-use';
|
||||||
|
|
||||||
import { QueryEditorProps, toOption } from '@grafana/data';
|
import { QueryEditorProps, toOption } from '@grafana/data';
|
||||||
import { EditorField, EditorRows, EditorRow } from '@grafana/experimental';
|
import { EditorField, EditorRows } from '@grafana/experimental';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
import { Input } from '@grafana/ui';
|
import { Input } from '@grafana/ui';
|
||||||
|
|
||||||
@ -92,18 +92,12 @@ export const AnnotationQueryEditor = (props: Props) => {
|
|||||||
datasource={datasource}
|
datasource={datasource}
|
||||||
query={metricQuery}
|
query={metricQuery}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<EditorRow>
|
|
||||||
<EditorField label="Title" htmlFor="annotation-query-title">
|
<EditorField label="Title" htmlFor="annotation-query-title">
|
||||||
<Input id="annotation-query-title" value={title} onChange={handleTitleChange} />
|
<Input id="annotation-query-title" value={title} onChange={handleTitleChange} />
|
||||||
</EditorField>
|
</EditorField>
|
||||||
</EditorRow>
|
|
||||||
|
|
||||||
<EditorRow>
|
|
||||||
<EditorField label="Text" htmlFor="annotation-query-text">
|
<EditorField label="Text" htmlFor="annotation-query-text">
|
||||||
<Input id="annotation-query-text" value={text} onChange={handleTextChange} />
|
<Input id="annotation-query-text" value={text} onChange={handleTextChange} />
|
||||||
</EditorField>
|
</EditorField>
|
||||||
</EditorRow>
|
|
||||||
</>
|
</>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
@ -0,0 +1,40 @@
|
|||||||
|
import { render, screen, act } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
|
import { TemplateSrvMock } from 'app/features/templating/template_srv.mock';
|
||||||
|
|
||||||
|
import { createMockDatasource } from '../../__mocks__/cloudMonitoringDatasource';
|
||||||
|
import { createMockMetricQuery } from '../../__mocks__/cloudMonitoringQuery';
|
||||||
|
|
||||||
|
import { MetricQueryEditor, Props } from './MetricQueryEditor';
|
||||||
|
|
||||||
|
jest.mock('@grafana/runtime', () => ({
|
||||||
|
...jest.requireActual('@grafana/runtime'),
|
||||||
|
getTemplateSrv: () => new TemplateSrvMock({}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const props: Props = {
|
||||||
|
onChange: jest.fn(),
|
||||||
|
refId: 'refId',
|
||||||
|
customMetaData: {},
|
||||||
|
onRunQuery: jest.fn(),
|
||||||
|
datasource: createMockDatasource(),
|
||||||
|
variableOptionGroup: { options: [] },
|
||||||
|
query: createMockMetricQuery(),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Cloud monitoring: Metric Query Editor', () => {
|
||||||
|
it('shoud render Project selector', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
const originalValue = config.featureToggles.cloudMonitoringExperimentalUI;
|
||||||
|
config.featureToggles.cloudMonitoringExperimentalUI = true;
|
||||||
|
|
||||||
|
render(<MetricQueryEditor {...props} />);
|
||||||
|
|
||||||
|
expect(screen.getByLabelText('Project')).toBeInTheDocument();
|
||||||
|
|
||||||
|
config.featureToggles.cloudMonitoringExperimentalUI = originalValue;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -0,0 +1,40 @@
|
|||||||
|
import { render, screen, act } from '@testing-library/react';
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
import { config } from '@grafana/runtime';
|
||||||
|
import { TemplateSrvMock } from 'app/features/templating/template_srv.mock';
|
||||||
|
|
||||||
|
import { createMockDatasource } from '../../__mocks__/cloudMonitoringDatasource';
|
||||||
|
import { createMockSLOQuery } from '../../__mocks__/cloudMonitoringQuery';
|
||||||
|
|
||||||
|
import { SLOQueryEditor, Props } from './SLOQueryEditor';
|
||||||
|
|
||||||
|
jest.mock('@grafana/runtime', () => ({
|
||||||
|
...jest.requireActual('@grafana/runtime'),
|
||||||
|
getTemplateSrv: () => new TemplateSrvMock({}),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const props: Props = {
|
||||||
|
onChange: jest.fn(),
|
||||||
|
refId: 'refId',
|
||||||
|
customMetaData: {},
|
||||||
|
onRunQuery: jest.fn(),
|
||||||
|
datasource: createMockDatasource(),
|
||||||
|
variableOptionGroup: { options: [] },
|
||||||
|
query: createMockSLOQuery(),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Cloud monitoring: SLO Query Editor', () => {
|
||||||
|
it('shoud render Service selector', async () => {
|
||||||
|
await act(async () => {
|
||||||
|
const originalValue = config.featureToggles.cloudMonitoringExperimentalUI;
|
||||||
|
config.featureToggles.cloudMonitoringExperimentalUI = true;
|
||||||
|
|
||||||
|
render(<SLOQueryEditor {...props} />);
|
||||||
|
|
||||||
|
expect(screen.getByLabelText('Service')).toBeInTheDocument();
|
||||||
|
|
||||||
|
config.featureToggles.cloudMonitoringExperimentalUI = originalValue;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
Reference in New Issue
Block a user