mirror of https://github.com/grafana/grafana
parent
76f296e299
commit
ddf080dab6
@ -0,0 +1,54 @@ |
|||||||
|
import React from 'react'; |
||||||
|
import { shallow } from 'enzyme'; |
||||||
|
import { defaultProps, OptionModuleProps } from './module'; |
||||||
|
import { MappingType } from '../../../types'; |
||||||
|
import ValueMappings from './ValueMappings'; |
||||||
|
|
||||||
|
const setup = (propOverrides?: object) => { |
||||||
|
const props: OptionModuleProps = { |
||||||
|
onChange: jest.fn(), |
||||||
|
options: { |
||||||
|
...defaultProps.options, |
||||||
|
mappings: [ |
||||||
|
{ id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, |
||||||
|
{ id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, |
||||||
|
], |
||||||
|
}, |
||||||
|
}; |
||||||
|
|
||||||
|
Object.assign(props, propOverrides); |
||||||
|
|
||||||
|
const wrapper = shallow(<ValueMappings {...props} />); |
||||||
|
|
||||||
|
return wrapper.instance() as ValueMappings; |
||||||
|
}; |
||||||
|
|
||||||
|
describe('On remove mapping', () => { |
||||||
|
it('Should remove mapping with id 0', () => { |
||||||
|
const instance = setup(); |
||||||
|
instance.onRemoveMapping(1); |
||||||
|
|
||||||
|
expect(instance.state.mappings).toEqual([ |
||||||
|
{ id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' }, |
||||||
|
]); |
||||||
|
}); |
||||||
|
|
||||||
|
it('should remove mapping with id 1', () => { |
||||||
|
const instance = setup(); |
||||||
|
instance.onRemoveMapping(2); |
||||||
|
|
||||||
|
expect(instance.state.mappings).toEqual([ |
||||||
|
{ id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' }, |
||||||
|
]); |
||||||
|
}); |
||||||
|
}); |
||||||
|
|
||||||
|
describe('Next id to add', () => { |
||||||
|
it('should be 4', () => { |
||||||
|
const instance = setup(); |
||||||
|
|
||||||
|
instance.addMapping(); |
||||||
|
|
||||||
|
expect(instance.state.nextIdToAdd).toEqual(4); |
||||||
|
}); |
||||||
|
}); |
||||||
Loading…
Reference in new issue