mirror of
https://github.com/grafana/grafana.git
synced 2025-08-01 16:48:12 +08:00
Azure: Fix time management field (#107993)
* Fix mode setting * Update selector * Add tests * Fix condition
This commit is contained in:
@ -131,7 +131,7 @@ export const LogsQueryBuilder: React.FC<LogsQueryBuilderProps> = (props) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<span data-testid={selectors.components.queryEditor.logsQueryEditor.container.input}>
|
<span data-testid={selectors.components.queryEditor.logsQueryBuilder.container.input}>
|
||||||
<EditorRows>
|
<EditorRows>
|
||||||
{schema && tables.length === 0 && (
|
{schema && tables.length === 0 && (
|
||||||
<Alert
|
<Alert
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { render, screen, waitFor } from '@testing-library/react';
|
import { render, screen, waitFor, cleanup } from '@testing-library/react';
|
||||||
|
|
||||||
import { CoreApp } from '@grafana/data';
|
import { CoreApp } from '@grafana/data';
|
||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
@ -39,6 +39,15 @@ jest.mock('@grafana/runtime', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
describe('Azure Monitor QueryEditor', () => {
|
describe('Azure Monitor QueryEditor', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
config.featureToggles = {};
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(() => {
|
||||||
|
cleanup();
|
||||||
|
jest.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('renders the Metrics query editor when the query type is Metrics', async () => {
|
it('renders the Metrics query editor when the query type is Metrics', async () => {
|
||||||
const mockDatasource = createMockDatasource();
|
const mockDatasource = createMockDatasource();
|
||||||
const mockQuery = {
|
const mockQuery = {
|
||||||
@ -67,6 +76,65 @@ describe('Azure Monitor QueryEditor', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('renders the Logs code editor when there is an existing query and the builder is enabled', async () => {
|
||||||
|
config.featureToggles.azureMonitorLogsBuilderEditor = true;
|
||||||
|
const mockDatasource = createMockDatasource();
|
||||||
|
const mockQuery = {
|
||||||
|
...createMockQuery(),
|
||||||
|
queryType: AzureQueryType.LogAnalytics,
|
||||||
|
};
|
||||||
|
|
||||||
|
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input)
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input)
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the Logs code editor when there is no existing query and the builder is disabled', async () => {
|
||||||
|
config.featureToggles.azureMonitorLogsBuilderEditor = false;
|
||||||
|
const mockDatasource = createMockDatasource();
|
||||||
|
const mockQuery = {
|
||||||
|
...createMockQuery(),
|
||||||
|
queryType: AzureQueryType.LogAnalytics,
|
||||||
|
};
|
||||||
|
delete mockQuery.azureLogAnalytics?.query;
|
||||||
|
|
||||||
|
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input)
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input)
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('renders the Logs builder when there is no existing query and the builder is enabled', async () => {
|
||||||
|
config.featureToggles.azureMonitorLogsBuilderEditor = true;
|
||||||
|
const mockDatasource = createMockDatasource();
|
||||||
|
const mockQuery = {
|
||||||
|
...createMockQuery(),
|
||||||
|
queryType: AzureQueryType.LogAnalytics,
|
||||||
|
};
|
||||||
|
delete mockQuery.azureLogAnalytics?.query;
|
||||||
|
|
||||||
|
render(<QueryEditor query={mockQuery} datasource={mockDatasource} onChange={() => {}} onRunQuery={() => {}} />);
|
||||||
|
await waitFor(() => {
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryEditor.container.input)
|
||||||
|
).toBeInTheDocument();
|
||||||
|
expect(
|
||||||
|
screen.queryByTestId(selectors.components.queryEditor.logsQueryBuilder.container.input)
|
||||||
|
).not.toBeInTheDocument();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('renders the ARG query editor when the query type is ARG', async () => {
|
it('renders the ARG query editor when the query type is ARG', async () => {
|
||||||
const mockDatasource = createMockDatasource();
|
const mockDatasource = createMockDatasource();
|
||||||
const mockQuery = {
|
const mockQuery = {
|
||||||
|
@ -64,7 +64,13 @@ export const QueryHeader = ({
|
|||||||
...query,
|
...query,
|
||||||
azureLogAnalytics: {
|
azureLogAnalytics: {
|
||||||
...query.azureLogAnalytics,
|
...query.azureLogAnalytics,
|
||||||
mode: LogsEditorMode.Builder,
|
// Builder mode is default unless there is an existing Log Analytics query
|
||||||
|
// that was not created with the builder
|
||||||
|
mode:
|
||||||
|
(query.azureLogAnalytics?.builderQuery === undefined && query.azureLogAnalytics?.query !== undefined) ||
|
||||||
|
!config.featureToggles.azureMonitorLogsBuilderEditor
|
||||||
|
? LogsEditorMode.Raw
|
||||||
|
: LogsEditorMode.Builder,
|
||||||
dashboardTime: true,
|
dashboardTime: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
@ -80,6 +80,9 @@ export const components = {
|
|||||||
button: 'data-testid run-query',
|
button: 'data-testid run-query',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
logsQueryBuilder: {
|
||||||
|
container: { input: 'data-testid azure-monitor-logs-query-builder' },
|
||||||
|
},
|
||||||
argsQueryEditor: {
|
argsQueryEditor: {
|
||||||
container: {
|
container: {
|
||||||
input: 'data-testid azure-monitor-arg-query-editor',
|
input: 'data-testid azure-monitor-arg-query-editor',
|
||||||
|
Reference in New Issue
Block a user