The open and composable observability and data visualization platform. Visualize metrics, logs, and traces from multiple sources like Prometheus, Loki, Elasticsearch, InfluxDB, Postgres and many more.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 
grafana/public/app/features/transformers/utils.test.ts

65 lines
2.1 KiB

import { config } from '@grafana/runtime';
import { numberOrVariableValidator } from './utils';
describe('validator', () => {
it('validates a positive number', () => {
expect(numberOrVariableValidator(1)).toBe(true);
});
it('validates a negative number', () => {
expect(numberOrVariableValidator(-1)).toBe(true);
});
it('validates zero', () => {
expect(numberOrVariableValidator(0)).toBe(true);
});
it('validates a float', () => {
expect(numberOrVariableValidator(1.2)).toBe(true);
});
it('validates a negative float', () => {
expect(numberOrVariableValidator(1.2)).toBe(true);
});
it('validates a string that is a positive integer', () => {
expect(numberOrVariableValidator('1')).toBe(true);
});
it('validats a string that is a negative integer', () => {
expect(numberOrVariableValidator('-1')).toBe(true);
});
it('validats a string that is zero', () => {
expect(numberOrVariableValidator('0')).toBe(true);
});
it('validats a string that is a float', () => {
expect(numberOrVariableValidator('1.2')).toBe(true);
});
it('validats a string that is a negative float', () => {
expect(numberOrVariableValidator('-1.2')).toBe(true);
});
it('fails a string that is not a number', () => {
expect(numberOrVariableValidator('foo')).toBe(false);
});
it('validates a string that has a variable', () => {
config.featureToggles.transformationsVariableSupport = true;
expect(numberOrVariableValidator('$foo')).toBe(true);
config.featureToggles.transformationsVariableSupport = false;
});
it('fails a string that has a variable if the feature flag is disabled', () => {
config.featureToggles.transformationsVariableSupport = false;
expect(numberOrVariableValidator('$foo')).toBe(false);
config.featureToggles.transformationsVariableSupport = true;
});
it('fails a string that has multiple variables', () => {
config.featureToggles.transformationsVariableSupport = true;
expect(numberOrVariableValidator('$foo$asd')).toBe(false);
config.featureToggles.transformationsVariableSupport = false;
});
});