|
|
@@ -3,6 +3,7 @@ import { shallow } from 'enzyme';
|
|
|
|
|
|
import { Gauge, Props } from './Gauge';
|
|
|
import { TimeSeriesVMs } from '../../types/series';
|
|
|
+import { ValueMapping, MappingType } from '../../types';
|
|
|
|
|
|
jest.mock('jquery', () => ({
|
|
|
plot: jest.fn(),
|
|
|
@@ -68,3 +69,80 @@ describe('Get font color', () => {
|
|
|
expect(instance.getFontColor(6.5)).toEqual('#EAB839');
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+describe('Format value with value mappings', () => {
|
|
|
+ it('should return undefined with no valuemappings', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return undefined with no matching valuemappings', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [
|
|
|
+ { id: 0, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' },
|
|
|
+ { id: 1, operator: '', text: '1-9', type: MappingType.RangeToText, from: '1', to: '9' },
|
|
|
+ ];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result).toBeUndefined();
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return first matching mapping with lowest id', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [
|
|
|
+ { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
|
|
|
+ { id: 1, operator: '', text: 'tio', type: MappingType.ValueToText, value: '10' },
|
|
|
+ ];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result.text).toEqual('1-20');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return rangeToText mapping where value equals to', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [
|
|
|
+ { id: 0, operator: '', text: '1-10', type: MappingType.RangeToText, from: '1', to: '10' },
|
|
|
+ { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' },
|
|
|
+ ];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result.text).toEqual('1-10');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return rangeToText mapping where value equals from', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [
|
|
|
+ { id: 0, operator: '', text: '10-20', type: MappingType.RangeToText, from: '10', to: '20' },
|
|
|
+ { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' },
|
|
|
+ ];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result.text).toEqual('10-20');
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should return rangeToText mapping where value is between from and to', () => {
|
|
|
+ const valueMappings: ValueMapping[] = [
|
|
|
+ { id: 0, operator: '', text: '1-20', type: MappingType.RangeToText, from: '1', to: '20' },
|
|
|
+ { id: 1, operator: '', text: 'elva', type: MappingType.ValueToText, value: '11' },
|
|
|
+ ];
|
|
|
+ const value = 10;
|
|
|
+ const { instance } = setup({ valueMappings });
|
|
|
+
|
|
|
+ const result = instance.getFirstFormattedValueMapping(valueMappings, value);
|
|
|
+
|
|
|
+ expect(result.text).toEqual('1-20');
|
|
|
+ });
|
|
|
+});
|