|
|
|
@ -6,13 +6,13 @@ import selectEvent from 'react-select-event'; |
|
|
|
|
import { config } from '@grafana/runtime'; |
|
|
|
|
|
|
|
|
|
import { MetricStatEditor } from '..'; |
|
|
|
|
import { setupMockedDataSource } from '../../__mocks__/CloudWatchDataSource'; |
|
|
|
|
import { setupMockedDataSource, statisticVariable } from '../../__mocks__/CloudWatchDataSource'; |
|
|
|
|
import { validMetricSearchBuilderQuery } from '../../__mocks__/queries'; |
|
|
|
|
import { MetricStat } from '../../types'; |
|
|
|
|
|
|
|
|
|
const originalFeatureToggleValue = config.featureToggles.cloudWatchCrossAccountQuerying; |
|
|
|
|
const ds = setupMockedDataSource({ |
|
|
|
|
variables: [], |
|
|
|
|
variables: [statisticVariable], |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
ds.datasource.resources.getNamespaces = jest.fn().mockResolvedValue([]); |
|
|
|
@ -40,9 +40,8 @@ describe('MetricStatEditor', () => { |
|
|
|
|
config.featureToggles.cloudWatchCrossAccountQuerying = originalFeatureToggleValue; |
|
|
|
|
}); |
|
|
|
|
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(); |
|
|
|
|
props.datasource.getVariables = jest.fn().mockReturnValue(['$statistic']); |
|
|
|
|
|
|
|
|
|
render(<MetricStatEditor {...props} onChange={onChange} />); |
|
|
|
|
|
|
|
|
@ -54,7 +53,7 @@ describe('MetricStatEditor', () => { |
|
|
|
|
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(); |
|
|
|
|
|
|
|
|
|
render(<MetricStatEditor {...props} onChange={onChange} />); |
|
|
|
|