|
|
@@ -15,25 +15,56 @@ const setup = (propOverrides?: object) => {
|
|
|
return shallow(<ThresholdsEditor {...props} />).instance() as ThresholdsEditor;
|
|
|
};
|
|
|
|
|
|
+describe('Initialization', () => {
|
|
|
+ it('should add a base threshold if missing', () => {
|
|
|
+ const instance = setup();
|
|
|
+
|
|
|
+ expect(instance.state.thresholds).toEqual([{ index: 0, value: -Infinity, color: '#7EB26D' }]);
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
describe('Add threshold', () => {
|
|
|
it('should add threshold', () => {
|
|
|
const instance = setup();
|
|
|
|
|
|
- instance.onAddThreshold(0);
|
|
|
+ instance.onAddThreshold(1);
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([{ index: 0, value: 50, color: 'rgb(127, 115, 64)' }]);
|
|
|
+ expect(instance.state.thresholds).toEqual([
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ ]);
|
|
|
});
|
|
|
|
|
|
it('should add another threshold above a first', () => {
|
|
|
const instance = setup({
|
|
|
- thresholds: [{ index: 0, value: 50, color: 'rgb(127, 115, 64)' }],
|
|
|
+ thresholds: [{ index: 0, value: -Infinity, color: '#7EB26D' }, { index: 1, value: 50, color: '#EAB839' }],
|
|
|
});
|
|
|
|
|
|
- instance.onAddThreshold(1);
|
|
|
+ instance.onAddThreshold(2);
|
|
|
+
|
|
|
+ expect(instance.state.thresholds).toEqual([
|
|
|
+ { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ ]);
|
|
|
+ });
|
|
|
+
|
|
|
+ it('should add another threshold between first and second index', () => {
|
|
|
+ const instance = setup({
|
|
|
+ thresholds: [
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
+ ],
|
|
|
+ });
|
|
|
+
|
|
|
+ instance.onAddThreshold(2);
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 1, value: 75, color: 'rgb(170, 95, 61)' },
|
|
|
- { index: 0, value: 50, color: 'rgb(127, 115, 64)' },
|
|
|
+ { index: 3, value: 75, color: '#EF843C' },
|
|
|
+ { index: 2, value: 62.5, color: '#6ED0E0' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
]);
|
|
|
});
|
|
|
});
|
|
|
@@ -41,23 +72,25 @@ describe('Add threshold', () => {
|
|
|
describe('change threshold value', () => {
|
|
|
it('should update value and resort rows', () => {
|
|
|
const instance = setup();
|
|
|
- const mockThresholds = [
|
|
|
- { index: 0, value: 50, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
- { index: 1, value: 75, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
+ const thresholds = [
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
|
|
|
|
instance.state = {
|
|
|
baseColor: BasicGaugeColor.Green,
|
|
|
- thresholds: mockThresholds,
|
|
|
+ thresholds,
|
|
|
};
|
|
|
|
|
|
const mockEvent = { target: { value: 78 } };
|
|
|
|
|
|
- instance.onChangeThresholdValue(mockEvent, mockThresholds[0]);
|
|
|
+ instance.onChangeThresholdValue(mockEvent, thresholds[1]);
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 0, value: 78, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
- { index: 1, value: 75, color: 'rgba(237, 129, 40, 0.89)' },
|
|
|
+ { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 78, color: '#EAB839' },
|
|
|
+ { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
]);
|
|
|
});
|
|
|
});
|