mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
CloudWatch: Fix test on metric stat editor statistic field (#67064)
This commit is contained in:
parent
b992bdb62d
commit
d120c05608
@ -1,6 +1,7 @@
|
|||||||
import { of } from 'rxjs';
|
import { of } from 'rxjs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
CustomVariableModel,
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
DataSourcePluginMeta,
|
DataSourcePluginMeta,
|
||||||
PluginMetaInfo,
|
PluginMetaInfo,
|
||||||
@ -11,7 +12,6 @@ import { getBackendSrv, setBackendSrv } from '@grafana/runtime';
|
|||||||
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||||
import { initialCustomVariableModelState } from 'app/features/variables/custom/reducer';
|
import { initialCustomVariableModelState } from 'app/features/variables/custom/reducer';
|
||||||
import { CustomVariableModel } from 'app/features/variables/types';
|
|
||||||
|
|
||||||
import { CloudWatchDatasource } from '../datasource';
|
import { CloudWatchDatasource } from '../datasource';
|
||||||
import { CloudWatchJsonData } from '../types';
|
import { CloudWatchJsonData } from '../types';
|
||||||
@ -256,3 +256,11 @@ export const accountIdVariable: CustomVariableModel = {
|
|||||||
options: [{ value: 'templatedRegion', text: 'templatedRegion', selected: true }],
|
options: [{ value: 'templatedRegion', text: 'templatedRegion', selected: true }],
|
||||||
multi: false,
|
multi: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const statisticVariable: CustomVariableModel = {
|
||||||
|
...initialCustomVariableModelState,
|
||||||
|
id: 'statistic',
|
||||||
|
name: 'statistic',
|
||||||
|
current: { value: 'some stat', text: 'some stat', selected: true },
|
||||||
|
multi: false,
|
||||||
|
};
|
||||||
|
@ -6,13 +6,13 @@ import selectEvent from 'react-select-event';
|
|||||||
import { config } from '@grafana/runtime';
|
import { config } from '@grafana/runtime';
|
||||||
|
|
||||||
import { MetricStatEditor } from '..';
|
import { MetricStatEditor } from '..';
|
||||||
import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource';
|
import { setupMockedDataSource, statisticVariable } from '../../__mocks__/CloudWatchDataSource';
|
||||||
import { validMetricSearchBuilderQuery } from '../../__mocks__/queries';
|
import { validMetricSearchBuilderQuery } from '../../__mocks__/queries';
|
||||||
import { MetricStat } from '../../types';
|
import { MetricStat } from '../../types';
|
||||||
|
|
||||||
const originalFeatureToggleValue = config.featureToggles.cloudWatchCrossAccountQuerying;
|
const originalFeatureToggleValue = config.featureToggles.cloudWatchCrossAccountQuerying;
|
||||||
const ds = setupMockedDataSource({
|
const ds = setupMockedDataSource({
|
||||||
variables: [],
|
variables: [statisticVariable],
|
||||||
});
|
});
|
||||||
|
|
||||||
ds.datasource.resources.getNamespaces = jest.fn().mockResolvedValue([]);
|
ds.datasource.resources.getNamespaces = jest.fn().mockResolvedValue([]);
|
||||||
@ -40,9 +40,8 @@ describe('MetricStatEditor', () => {
|
|||||||
config.featureToggles.cloudWatchCrossAccountQuerying = originalFeatureToggleValue;
|
config.featureToggles.cloudWatchCrossAccountQuerying = originalFeatureToggleValue;
|
||||||
});
|
});
|
||||||
describe('statistics field', () => {
|
describe('statistics field', () => {
|
||||||
test.each([['Average', 'p23.23', 'p34', '$statistic']])('should accept valid values', async (statistic) => {
|
test.each(['Average', 'p23.23', 'p34', '$statistic'])('should accept valid values', async (statistic) => {
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
props.datasource.getVariables = jest.fn().mockReturnValue(['$statistic']);
|
|
||||||
|
|
||||||
render(<MetricStatEditor {...props} onChange={onChange} />);
|
render(<MetricStatEditor {...props} onChange={onChange} />);
|
||||||
|
|
||||||
@ -54,7 +53,7 @@ describe('MetricStatEditor', () => {
|
|||||||
expect(onChange).toHaveBeenCalledWith({ ...props.metricStat, statistic });
|
expect(onChange).toHaveBeenCalledWith({ ...props.metricStat, statistic });
|
||||||
});
|
});
|
||||||
|
|
||||||
test.each([['CustomStat', 'p23,23', '$statistic']])('should not accept invalid values', async (statistic) => {
|
test.each(['CustomStat', 'p23,23', '$someUnknownValue'])('should not accept invalid values', async (statistic) => {
|
||||||
const onChange = jest.fn();
|
const onChange = jest.fn();
|
||||||
|
|
||||||
render(<MetricStatEditor {...props} onChange={onChange} />);
|
render(<MetricStatEditor {...props} onChange={onChange} />);
|
||||||
|
@ -117,7 +117,7 @@ export function MetricStatEditor({
|
|||||||
!statistic ||
|
!statistic ||
|
||||||
(!standardStatistics.includes(statistic) &&
|
(!standardStatistics.includes(statistic) &&
|
||||||
!/^p\d{2}(?:\.\d{1,2})?$/.test(statistic) &&
|
!/^p\d{2}(?:\.\d{1,2})?$/.test(statistic) &&
|
||||||
!statistic.startsWith('$'))
|
!datasource.templateSrv.containsTemplate(statistic))
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user