Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. import React from 'react';
  2. import { mount } from 'enzyme';
  3.  
  4. import CurrencySlider from 'components/CurrencySlider';
  5.  
  6. describe('CurrencySlider', () => {
  7. let component;
  8. const props = {
  9. attribute: 'attribute',
  10. max: 500000,
  11. min: 0,
  12. onChange: jest.fn(),
  13. value: 0
  14. };
  15.  
  16. beforeEach(() => {
  17. component = mount(<CurrencySlider {...props} />);
  18. });
  19.  
  20. afterEach(() => {
  21. component.unmount();
  22. });
  23.  
  24. describe('autoSave enabled', () => {
  25. it('automatically saves when blurring the text field', () => {
  26. const textInput = component.find('.form-input');
  27.  
  28. expect(component.prop('onChange')).not.toHaveBeenCalled();
  29.  
  30. textInput.simulate('change', { target: { value: 20000 } });
  31. textInput.simulate('blur');
  32.  
  33. expect(component.prop('onChange')).toHaveBeenCalled();
  34. });
  35.  
  36. it('automatically saves when you finish moving the slider', () => {
  37. const { $slider } = component.instance();
  38. const newValue = 10000;
  39.  
  40. expect(component.prop('onChange')).not.toHaveBeenCalled();
  41.  
  42. $slider()
  43. .val(newValue)
  44. .change();
  45.  
  46. expect(component.prop('onChange')).toHaveBeenCalled();
  47. });
  48.  
  49. it('displays an error message when input is out of range', () => {
  50. component.setProps({ min: 1000, value: 1100 });
  51. const textInput = component.find('.form-input');
  52.  
  53. expect(component.find('p')).not.toExist();
  54.  
  55. textInput.simulate('change', { target: { value: 700 } });
  56. textInput.simulate('blur');
  57.  
  58. expect(component.find('p').text()).toContain(
  59. `Please enter an amount larger than $${component.prop('min')}`
  60. );
  61. });
  62. });
  63. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement