|
@@ -2,17 +2,14 @@ import React from 'react';
|
|
|
import { shallow } from 'enzyme';
|
|
import { shallow } from 'enzyme';
|
|
|
import Thresholds from './Thresholds';
|
|
import Thresholds from './Thresholds';
|
|
|
import { defaultProps, OptionsProps } from './module';
|
|
import { defaultProps, OptionsProps } from './module';
|
|
|
-import { PanelOptionsProps } from '../../../types';
|
|
|
|
|
|
|
+import { BasicGaugeColor, PanelOptionsProps } from 'app/types';
|
|
|
|
|
|
|
|
const setup = (propOverrides?: object) => {
|
|
const setup = (propOverrides?: object) => {
|
|
|
const props: PanelOptionsProps<OptionsProps> = {
|
|
const props: PanelOptionsProps<OptionsProps> = {
|
|
|
onChange: jest.fn(),
|
|
onChange: jest.fn(),
|
|
|
options: {
|
|
options: {
|
|
|
...defaultProps.options,
|
|
...defaultProps.options,
|
|
|
- thresholds: [
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ thresholds: [],
|
|
|
},
|
|
},
|
|
|
};
|
|
};
|
|
|
|
|
|
|
@@ -22,121 +19,51 @@ const setup = (propOverrides?: object) => {
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
describe('Add threshold', () => {
|
|
describe('Add threshold', () => {
|
|
|
- it('should add threshold between min and max', () => {
|
|
|
|
|
|
|
+ it('should add threshold', () => {
|
|
|
const instance = setup();
|
|
const instance = setup();
|
|
|
|
|
|
|
|
- instance.onAddThreshold(1);
|
|
|
|
|
|
|
+ instance.onAddThreshold(0);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: '', value: 50, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 2, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ]);
|
|
|
|
|
|
|
+ expect(instance.state.thresholds).toEqual([{ index: 0, value: 50, color: 'rgb(127, 115, 64)' }]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- it('should add threshold between min and added threshold', () => {
|
|
|
|
|
|
|
+ it('should add another threshold above a first', () => {
|
|
|
const instance = setup({
|
|
const instance = setup({
|
|
|
options: {
|
|
options: {
|
|
|
...defaultProps.options,
|
|
...defaultProps.options,
|
|
|
- thresholds: [
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: '', value: 50, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 2, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ],
|
|
|
|
|
|
|
+ thresholds: [{ index: 0, value: 50, color: 'rgb(127, 115, 64)' }],
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
instance.onAddThreshold(1);
|
|
instance.onAddThreshold(1);
|
|
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: '', value: 25, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 2, label: '', value: 50, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 3, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
|
|
+ { index: 1, value: 75, color: 'rgb(170, 95, 61)' },
|
|
|
|
|
+ { index: 0, value: 50, color: 'rgb(127, 115, 64)' },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
-describe('Add at index', () => {
|
|
|
|
|
- it('should return 1, no added thresholds', () => {
|
|
|
|
|
- const instance = setup();
|
|
|
|
|
-
|
|
|
|
|
- const result = instance.insertAtIndex(1);
|
|
|
|
|
-
|
|
|
|
|
- expect(result).toEqual(1);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('should return 1, one added threshold', () => {
|
|
|
|
|
- const instance = setup();
|
|
|
|
|
- instance.state = {
|
|
|
|
|
- thresholds: [
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false },
|
|
|
|
|
- { index: 1, label: '', value: 50, canRemove: true },
|
|
|
|
|
- { index: 2, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const result = instance.insertAtIndex(1);
|
|
|
|
|
-
|
|
|
|
|
- expect(result).toEqual(1);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('should return 2, two added thresholds', () => {
|
|
|
|
|
- const instance = setup({
|
|
|
|
|
- options: {
|
|
|
|
|
- thresholds: [
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false },
|
|
|
|
|
- { index: 1, label: '', value: 25, canRemove: true },
|
|
|
|
|
- { index: 2, label: '', value: 50, canRemove: true },
|
|
|
|
|
- { index: 3, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ],
|
|
|
|
|
- },
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- const result = instance.insertAtIndex(2);
|
|
|
|
|
-
|
|
|
|
|
- expect(result).toEqual(2);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- it('should return 2, one added threshold', () => {
|
|
|
|
|
- const instance = setup();
|
|
|
|
|
- instance.state = {
|
|
|
|
|
- thresholds: [
|
|
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false },
|
|
|
|
|
- { index: 1, label: '', value: 50, canRemove: true },
|
|
|
|
|
- { index: 2, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
- ],
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const result = instance.insertAtIndex(2);
|
|
|
|
|
-
|
|
|
|
|
- expect(result).toEqual(2);
|
|
|
|
|
- });
|
|
|
|
|
-});
|
|
|
|
|
-
|
|
|
|
|
describe('change threshold value', () => {
|
|
describe('change threshold value', () => {
|
|
|
it('should update value and resort rows', () => {
|
|
it('should update value and resort rows', () => {
|
|
|
const instance = setup();
|
|
const instance = setup();
|
|
|
const mockThresholds = [
|
|
const mockThresholds = [
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: '', value: 50, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 2, label: '', value: 75, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 3, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
|
|
+ { index: 0, value: 50, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
+ { index: 1, value: 75, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
instance.state = {
|
|
instance.state = {
|
|
|
|
|
+ baseColor: BasicGaugeColor.Green,
|
|
|
thresholds: mockThresholds,
|
|
thresholds: mockThresholds,
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const mockEvent = { target: { value: 78 } };
|
|
const mockEvent = { target: { value: 78 } };
|
|
|
|
|
|
|
|
- instance.onChangeThresholdValue(mockEvent, mockThresholds[1]);
|
|
|
|
|
|
|
+ instance.onChangeThresholdValue(mockEvent, mockThresholds[0]);
|
|
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 0, label: 'Min', value: 0, canRemove: false, color: 'rgba(50, 172, 45, 0.97)' },
|
|
|
|
|
- { index: 1, label: '', value: 78, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 2, label: '', value: 75, canRemove: true, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
- { index: 3, label: 'Max', value: 100, canRemove: false },
|
|
|
|
|
|
|
+ { index: 0, value: 78, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
|
|
+ { index: 1, value: 75, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|