|
@@ -1,6 +1,6 @@
|
|
|
import React, { ChangeEvent } from 'react';
|
|
import React, { ChangeEvent } from 'react';
|
|
|
import { mount } from 'enzyme';
|
|
import { mount } from 'enzyme';
|
|
|
-import { ThresholdsEditor, Props } from './ThresholdsEditor';
|
|
|
|
|
|
|
+import { ThresholdsEditor, Props, threshodsWithoutKey } from './ThresholdsEditor';
|
|
|
import { colors } from '../../utils';
|
|
import { colors } from '../../utils';
|
|
|
|
|
|
|
|
const setup = (propOverrides?: Partial<Props>) => {
|
|
const setup = (propOverrides?: Partial<Props>) => {
|
|
@@ -20,6 +20,10 @@ const setup = (propOverrides?: Partial<Props>) => {
|
|
|
};
|
|
};
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
+function getCurrentThresholds(editor: ThresholdsEditor) {
|
|
|
|
|
+ return threshodsWithoutKey(editor.state.thresholds);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
describe('Render', () => {
|
|
describe('Render', () => {
|
|
|
it('should render with base threshold', () => {
|
|
it('should render with base threshold', () => {
|
|
|
const { wrapper } = setup();
|
|
const { wrapper } = setup();
|
|
@@ -32,60 +36,55 @@ describe('Initialization', () => {
|
|
|
it('should add a base threshold if missing', () => {
|
|
it('should add a base threshold if missing', () => {
|
|
|
const { instance } = setup();
|
|
const { instance } = setup();
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([{ index: 0, value: -Infinity, color: colors[0] }]);
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([{ value: -Infinity, color: colors[0] }]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
describe('Add threshold', () => {
|
|
describe('Add threshold', () => {
|
|
|
- it('should not add threshold at index 0', () => {
|
|
|
|
|
- const { instance } = setup();
|
|
|
|
|
-
|
|
|
|
|
- instance.onAddThreshold(0);
|
|
|
|
|
-
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([{ index: 0, value: -Infinity, color: colors[0] }]);
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
it('should add threshold', () => {
|
|
it('should add threshold', () => {
|
|
|
const { instance } = setup();
|
|
const { instance } = setup();
|
|
|
|
|
|
|
|
- instance.onAddThreshold(1);
|
|
|
|
|
|
|
+ instance.onAddThresholdAfter(instance.state.thresholds[0]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: colors[0] },
|
|
|
|
|
- { index: 1, value: 50, color: colors[2] },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: colors[0] }, // 0
|
|
|
|
|
+ { value: 50, color: colors[2] }, // 1
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add another threshold above a first', () => {
|
|
it('should add another threshold above a first', () => {
|
|
|
const { instance } = setup({
|
|
const { instance } = setup({
|
|
|
- thresholds: [{ index: 0, value: -Infinity, color: colors[0] }, { index: 1, value: 50, color: colors[2] }],
|
|
|
|
|
|
|
+ thresholds: [
|
|
|
|
|
+ { value: -Infinity, color: colors[0] }, // 0
|
|
|
|
|
+ { value: 50, color: colors[2] }, // 1
|
|
|
|
|
+ ],
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- instance.onAddThreshold(2);
|
|
|
|
|
|
|
+ instance.onAddThresholdAfter(instance.state.thresholds[1]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: colors[0] },
|
|
|
|
|
- { index: 1, value: 50, color: colors[2] },
|
|
|
|
|
- { index: 2, value: 75, color: colors[3] },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: colors[0] }, // 0
|
|
|
|
|
+ { value: 50, color: colors[2] }, // 1
|
|
|
|
|
+ { value: 75, color: colors[3] }, // 2
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should add another threshold between first and second index', () => {
|
|
it('should add another threshold between first and second index', () => {
|
|
|
const { instance } = setup({
|
|
const { instance } = setup({
|
|
|
thresholds: [
|
|
thresholds: [
|
|
|
- { index: 0, value: -Infinity, color: colors[0] },
|
|
|
|
|
- { index: 1, value: 50, color: colors[2] },
|
|
|
|
|
- { index: 2, value: 75, color: colors[3] },
|
|
|
|
|
|
|
+ { value: -Infinity, color: colors[0] },
|
|
|
|
|
+ { value: 50, color: colors[2] },
|
|
|
|
|
+ { value: 75, color: colors[3] },
|
|
|
],
|
|
],
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- instance.onAddThreshold(2);
|
|
|
|
|
|
|
+ instance.onAddThresholdAfter(instance.state.thresholds[1]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: colors[0] },
|
|
|
|
|
- { index: 1, value: 50, color: colors[2] },
|
|
|
|
|
- { index: 2, value: 62.5, color: colors[4] },
|
|
|
|
|
- { index: 3, value: 75, color: colors[3] },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: colors[0] },
|
|
|
|
|
+ { value: 50, color: colors[2] },
|
|
|
|
|
+ { value: 62.5, color: colors[4] },
|
|
|
|
|
+ { value: 75, color: colors[3] },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -93,30 +92,30 @@ describe('Add threshold', () => {
|
|
|
describe('Remove threshold', () => {
|
|
describe('Remove threshold', () => {
|
|
|
it('should not remove threshold at index 0', () => {
|
|
it('should not remove threshold at index 0', () => {
|
|
|
const thresholds = [
|
|
const thresholds = [
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 50, color: '#EAB839' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
];
|
|
|
const { instance } = setup({ thresholds });
|
|
const { instance } = setup({ thresholds });
|
|
|
|
|
|
|
|
- instance.onRemoveThreshold(thresholds[0]);
|
|
|
|
|
|
|
+ instance.onRemoveThreshold(instance.state.thresholds[0]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual(thresholds);
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual(thresholds);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should remove threshold', () => {
|
|
it('should remove threshold', () => {
|
|
|
const thresholds = [
|
|
const thresholds = [
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 50, color: '#EAB839' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
];
|
|
|
const { instance } = setup({ thresholds });
|
|
const { instance } = setup({ thresholds });
|
|
|
|
|
|
|
|
- instance.onRemoveThreshold(thresholds[1]);
|
|
|
|
|
|
|
+ instance.onRemoveThreshold(instance.state.thresholds[1]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -124,25 +123,25 @@ describe('Remove threshold', () => {
|
|
|
describe('change threshold value', () => {
|
|
describe('change threshold value', () => {
|
|
|
it('should not change threshold at index 0', () => {
|
|
it('should not change threshold at index 0', () => {
|
|
|
const thresholds = [
|
|
const thresholds = [
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 50, color: '#EAB839' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
];
|
|
|
const { instance } = setup({ thresholds });
|
|
const { instance } = setup({ thresholds });
|
|
|
|
|
|
|
|
const mockEvent = ({ target: { value: '12' } } as any) as ChangeEvent<HTMLInputElement>;
|
|
const mockEvent = ({ target: { value: '12' } } as any) as ChangeEvent<HTMLInputElement>;
|
|
|
|
|
|
|
|
- instance.onChangeThresholdValue(mockEvent, thresholds[0]);
|
|
|
|
|
|
|
+ instance.onChangeThresholdValue(mockEvent, instance.state.thresholds[0]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual(thresholds);
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual(thresholds);
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
it('should update value', () => {
|
|
it('should update value', () => {
|
|
|
const { instance } = setup();
|
|
const { instance } = setup();
|
|
|
const thresholds = [
|
|
const thresholds = [
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D', key: 1 },
|
|
|
|
|
+ { value: 50, color: '#EAB839', key: 2 },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0', key: 3 },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
instance.state = {
|
|
instance.state = {
|
|
@@ -153,10 +152,10 @@ describe('change threshold value', () => {
|
|
|
|
|
|
|
|
instance.onChangeThresholdValue(mockEvent, thresholds[1]);
|
|
instance.onChangeThresholdValue(mockEvent, thresholds[1]);
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 78, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 78, color: '#EAB839' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
@@ -165,9 +164,9 @@ describe('on blur threshold value', () => {
|
|
|
it('should resort rows and update indexes', () => {
|
|
it('should resort rows and update indexes', () => {
|
|
|
const { instance } = setup();
|
|
const { instance } = setup();
|
|
|
const thresholds = [
|
|
const thresholds = [
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 78, color: '#EAB839' },
|
|
|
|
|
- { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D', key: 1 },
|
|
|
|
|
+ { value: 78, color: '#EAB839', key: 2 },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0', key: 3 },
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
instance.setState({
|
|
instance.setState({
|
|
@@ -176,10 +175,10 @@ describe('on blur threshold value', () => {
|
|
|
|
|
|
|
|
instance.onBlur();
|
|
instance.onBlur();
|
|
|
|
|
|
|
|
- expect(instance.state.thresholds).toEqual([
|
|
|
|
|
- { index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
- { index: 1, value: 75, color: '#6ED0E0' },
|
|
|
|
|
- { index: 2, value: 78, color: '#EAB839' },
|
|
|
|
|
|
|
+ expect(getCurrentThresholds(instance)).toEqual([
|
|
|
|
|
+ { value: -Infinity, color: '#7EB26D' },
|
|
|
|
|
+ { value: 75, color: '#6ED0E0' },
|
|
|
|
|
+ { value: 78, color: '#EAB839' },
|
|
|
]);
|
|
]);
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|