grafana/public/app/features/transformers/utils.test.ts
Oscar Kilhed 40cdb30336
Transformations: Add support for dashboard variable in limit, sort by, filter by value, heatmap and histogram (#75372)
* variables for filterforvalue

* use datalinkinput for basic matcher

* fix user select issue

* heatmap transformation variable interpolation

* clean code

* interpolate sort by

* add options interpolation in histogram transformation

* interpolation for limit

* Add suggestions UI to Filter by data value Transformation

Co-authored-by: oscarkilhed <oscar.kilhed@grafana.com>

* add validation for number/variable fields

* Add variables to add field from calculation

* Add validator to limit transformation

* Refactor validator

* Refactor suggestionInput styles

* Add variable support in heatmap calculate options to be in sync with tranform

* Refactor SuggestionsInput

* Fix histogram, limit and filter by value matchers

* clean up weird state ref

* Only interpolate when the feature toggle is set

* Add feature toggle to ui

* Fix number of variable test

* Fix issue with characters typed after opening suggestions still remains after selecting a suggestion

* Clean up from review

* Add more tests for numberOrVariableValidator

---------

Co-authored-by: Victor Marin <victor.marin@grafana.com>
2023-10-04 17:28:46 +03:00

66 lines
2.1 KiB
TypeScript

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;
});
});