|
|
@@ -1,9 +1,8 @@
|
|
|
import React, { ChangeEvent } from 'react';
|
|
|
-import { shallow } from 'enzyme';
|
|
|
-
|
|
|
+import { mount } from 'enzyme';
|
|
|
import { ThresholdsEditor, Props } from './ThresholdsEditor';
|
|
|
|
|
|
-const setup = (propOverrides?: object) => {
|
|
|
+const setup = (propOverrides?: Partial<Props>) => {
|
|
|
const props: Props = {
|
|
|
onChange: jest.fn(),
|
|
|
thresholds: [],
|
|
|
@@ -11,12 +10,26 @@ const setup = (propOverrides?: object) => {
|
|
|
|
|
|
Object.assign(props, propOverrides);
|
|
|
|
|
|
- return shallow(<ThresholdsEditor {...props} />).instance() as ThresholdsEditor;
|
|
|
+ const wrapper = mount(<ThresholdsEditor {...props} />);
|
|
|
+ const instance = wrapper.instance() as ThresholdsEditor;
|
|
|
+
|
|
|
+ return {
|
|
|
+ instance,
|
|
|
+ wrapper,
|
|
|
+ };
|
|
|
};
|
|
|
|
|
|
+describe('Render', () => {
|
|
|
+ it('should render with base threshold', () => {
|
|
|
+ const { wrapper } = setup();
|
|
|
+
|
|
|
+ expect(wrapper).toMatchSnapshot();
|
|
|
+ });
|
|
|
+});
|
|
|
+
|
|
|
describe('Initialization', () => {
|
|
|
it('should add a base threshold if missing', () => {
|
|
|
- const instance = setup();
|
|
|
+ const { instance } = setup();
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([{ index: 0, value: -Infinity, color: '#7EB26D' }]);
|
|
|
});
|
|
|
@@ -24,7 +37,7 @@ describe('Initialization', () => {
|
|
|
|
|
|
describe('Add threshold', () => {
|
|
|
it('should not add threshold at index 0', () => {
|
|
|
- const instance = setup();
|
|
|
+ const { instance } = setup();
|
|
|
|
|
|
instance.onAddThreshold(0);
|
|
|
|
|
|
@@ -32,32 +45,32 @@ describe('Add threshold', () => {
|
|
|
});
|
|
|
|
|
|
it('should add threshold', () => {
|
|
|
- const instance = setup();
|
|
|
+ const { instance } = setup();
|
|
|
|
|
|
instance.onAddThreshold(1);
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
]);
|
|
|
});
|
|
|
|
|
|
it('should add another threshold above a first', () => {
|
|
|
- const instance = setup({
|
|
|
+ const { instance } = setup({
|
|
|
thresholds: [{ index: 0, value: -Infinity, color: '#7EB26D' }, { index: 1, value: 50, color: '#EAB839' }],
|
|
|
});
|
|
|
|
|
|
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' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 2, value: 75, color: '#6ED0E0' },
|
|
|
]);
|
|
|
});
|
|
|
|
|
|
it('should add another threshold between first and second index', () => {
|
|
|
- const instance = setup({
|
|
|
+ const { instance } = setup({
|
|
|
thresholds: [
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
{ index: 1, value: 50, color: '#EAB839' },
|
|
|
@@ -68,10 +81,10 @@ describe('Add threshold', () => {
|
|
|
instance.onAddThreshold(2);
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 3, value: 75, color: '#6ED0E0' },
|
|
|
- { index: 2, value: 62.5, color: '#EF843C' },
|
|
|
- { index: 1, value: 50, color: '#EAB839' },
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 50, color: '#EAB839' },
|
|
|
+ { index: 2, value: 62.5, color: '#EF843C' },
|
|
|
+ { index: 3, value: 75, color: '#6ED0E0' },
|
|
|
]);
|
|
|
});
|
|
|
});
|
|
|
@@ -83,7 +96,7 @@ describe('Remove threshold', () => {
|
|
|
{ index: 1, value: 50, color: '#EAB839' },
|
|
|
{ index: 2, value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
|
- const instance = setup({ thresholds });
|
|
|
+ const { instance } = setup({ thresholds });
|
|
|
|
|
|
instance.onRemoveThreshold(thresholds[0]);
|
|
|
|
|
|
@@ -96,9 +109,7 @@ describe('Remove threshold', () => {
|
|
|
{ index: 1, value: 50, color: '#EAB839' },
|
|
|
{ index: 2, value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
|
- const instance = setup({
|
|
|
- thresholds,
|
|
|
- });
|
|
|
+ const { instance } = setup({ thresholds });
|
|
|
|
|
|
instance.onRemoveThreshold(thresholds[1]);
|
|
|
|
|
|
@@ -116,7 +127,7 @@ describe('change threshold value', () => {
|
|
|
{ index: 1, value: 50, color: '#EAB839' },
|
|
|
{ index: 2, value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
|
- const instance = setup({ thresholds });
|
|
|
+ const { instance } = setup({ thresholds });
|
|
|
|
|
|
const mockEvent = ({ target: { value: '12' } } as any) as ChangeEvent<HTMLInputElement>;
|
|
|
|
|
|
@@ -126,7 +137,7 @@ describe('change threshold value', () => {
|
|
|
});
|
|
|
|
|
|
it('should update value', () => {
|
|
|
- const instance = setup();
|
|
|
+ const { instance } = setup();
|
|
|
const thresholds = [
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
{ index: 1, value: 50, color: '#EAB839' },
|
|
|
@@ -150,24 +161,24 @@ describe('change threshold value', () => {
|
|
|
});
|
|
|
|
|
|
describe('on blur threshold value', () => {
|
|
|
- it('should resort rows and update indexes', () => {
|
|
|
- const instance = setup();
|
|
|
+ it.only('should resort rows and update indexes', () => {
|
|
|
+ const { instance } = setup();
|
|
|
const thresholds = [
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
{ index: 1, value: 78, color: '#EAB839' },
|
|
|
{ index: 2, value: 75, color: '#6ED0E0' },
|
|
|
];
|
|
|
|
|
|
- instance.state = {
|
|
|
+ instance.setState({
|
|
|
thresholds,
|
|
|
- };
|
|
|
+ });
|
|
|
|
|
|
instance.onBlur();
|
|
|
|
|
|
expect(instance.state.thresholds).toEqual([
|
|
|
- { index: 2, value: 78, color: '#EAB839' },
|
|
|
- { index: 1, value: 75, color: '#6ED0E0' },
|
|
|
{ index: 0, value: -Infinity, color: '#7EB26D' },
|
|
|
+ { index: 1, value: 75, color: '#6ED0E0' },
|
|
|
+ { index: 2, value: 78, color: '#EAB839' },
|
|
|
]);
|
|
|
});
|
|
|
});
|