123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138 |
- import { hiddenReducerTypes, ThresholdMapper } from './ThresholdMapper';
- import alertDef from './alertDef';
- const visibleReducerTypes = alertDef.reducerTypes
- .filter(({ value }) => hiddenReducerTypes.indexOf(value) === -1)
- .map(({ value }) => value);
- describe('ThresholdMapper', () => {
- describe('with greater than evaluator', () => {
- it('can map query conditions to thresholds', () => {
- const panel: any = {
- type: 'graph',
- options: { alertThresholds: true },
- alert: {
- conditions: [
- {
- type: 'query',
- evaluator: { type: 'gt', params: [100] },
- },
- ],
- },
- };
- const updated = ThresholdMapper.alertToGraphThresholds(panel);
- expect(updated).toBe(true);
- expect(panel.thresholds[0].op).toBe('gt');
- expect(panel.thresholds[0].value).toBe(100);
- });
- });
- describe('with outside range evaluator', () => {
- it('can map query conditions to thresholds', () => {
- const panel: any = {
- type: 'graph',
- options: { alertThresholds: true },
- alert: {
- conditions: [
- {
- type: 'query',
- evaluator: { type: 'outside_range', params: [100, 200] },
- },
- ],
- },
- };
- const updated = ThresholdMapper.alertToGraphThresholds(panel);
- expect(updated).toBe(true);
- expect(panel.thresholds[0].op).toBe('lt');
- expect(panel.thresholds[0].value).toBe(100);
- expect(panel.thresholds[1].op).toBe('gt');
- expect(panel.thresholds[1].value).toBe(200);
- });
- });
- describe('with inside range evaluator', () => {
- it('can map query conditions to thresholds', () => {
- const panel: any = {
- type: 'graph',
- options: { alertThresholds: true },
- alert: {
- conditions: [
- {
- type: 'query',
- evaluator: { type: 'within_range', params: [100, 200] },
- },
- ],
- },
- };
- const updated = ThresholdMapper.alertToGraphThresholds(panel);
- expect(updated).toBe(true);
- expect(panel.thresholds[0].op).toBe('gt');
- expect(panel.thresholds[0].value).toBe(100);
- expect(panel.thresholds[1].op).toBe('lt');
- expect(panel.thresholds[1].value).toBe(200);
- });
- });
- visibleReducerTypes.forEach((type) => {
- describe(`with {${type}} reducer`, () => {
- it('visible should be true', () => {
- const panel = getPanel({ reducerType: type });
- const updated = ThresholdMapper.alertToGraphThresholds(panel);
- expect(updated).toBe(true);
- expect(panel.thresholds[0]).toEqual({
- value: 100,
- op: 'gt',
- fill: true,
- line: true,
- colorMode: 'critical',
- visible: true,
- });
- });
- });
- });
- hiddenReducerTypes.forEach((type) => {
- describe(`with {${type}} reducer`, () => {
- it('visible should be false', () => {
- const panel = getPanel({ reducerType: type });
- const updated = ThresholdMapper.alertToGraphThresholds(panel);
- expect(updated).toBe(true);
- expect(panel.thresholds[0]).toEqual({
- value: 100,
- op: 'gt',
- fill: true,
- line: true,
- colorMode: 'critical',
- visible: false,
- });
- });
- });
- });
- });
- function getPanel({ reducerType }: { reducerType?: string } = {}) {
- const panel: any = {
- type: 'graph',
- options: { alertThreshold: true },
- alert: {
- conditions: [
- {
- type: 'query',
- evaluator: { type: 'gt', params: [100] },
- reducer: { type: reducerType },
- },
- ],
- },
- };
- return panel;
- }
|