ValueMappings.test.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { defaultProps, OptionModuleProps } from './module';
  4. import { MappingType } from '../../../types';
  5. import ValueMappings from './ValueMappings';
  6. const setup = (propOverrides?: object) => {
  7. const props: OptionModuleProps = {
  8. onChange: jest.fn(),
  9. options: {
  10. ...defaultProps.options,
  11. mappings: [
  12. { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' },
  13. { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' },
  14. ],
  15. },
  16. };
  17. Object.assign(props, propOverrides);
  18. const wrapper = shallow(<ValueMappings {...props} />);
  19. return wrapper.instance() as ValueMappings;
  20. };
  21. describe('On remove mapping', () => {
  22. it('Should remove mapping with id 0', () => {
  23. const instance = setup();
  24. instance.onRemoveMapping(1);
  25. expect(instance.state.mappings).toEqual([
  26. { id: 2, operator: '', type: MappingType.RangeToText, from: '21', to: '30', text: 'Meh' },
  27. ]);
  28. });
  29. it('should remove mapping with id 1', () => {
  30. const instance = setup();
  31. instance.onRemoveMapping(2);
  32. expect(instance.state.mappings).toEqual([
  33. { id: 1, operator: '', type: MappingType.ValueToText, value: '20', text: 'Ok' },
  34. ]);
  35. });
  36. });
  37. describe('Next id to add', () => {
  38. it('should be 4', () => {
  39. const instance = setup();
  40. instance.addMapping();
  41. expect(instance.state.nextIdToAdd).toEqual(4);
  42. });
  43. });