index.spec.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. import Stepper from '..';
  2. import { mount } from '../../../test/utils';
  3. test('disabled stepper', () => {
  4. const wrapper = mount(Stepper, {
  5. propsData: {
  6. disabled: true
  7. }
  8. });
  9. expect(wrapper).toMatchSnapshot();
  10. });
  11. test('disable stepper input', () => {
  12. const wrapper = mount(Stepper, {
  13. propsData: {
  14. disableInput: true
  15. }
  16. });
  17. expect(wrapper).toMatchSnapshot();
  18. });
  19. test('click button', () => {
  20. const wrapper = mount(Stepper, {
  21. propsData: {
  22. value: 1,
  23. max: 2
  24. }
  25. });
  26. const plus = wrapper.find('.van-stepper__plus');
  27. const minus = wrapper.find('.van-stepper__minus');
  28. plus.trigger('click');
  29. plus.trigger('click');
  30. minus.trigger('click');
  31. minus.trigger('click');
  32. expect(wrapper.emitted('input')).toEqual([[2], [1]]);
  33. expect(wrapper.emitted('overlimit')).toEqual([['plus'], ['minus']]);
  34. });
  35. test('correct value when value is not correct', () => {
  36. const wrapper = mount(Stepper, {
  37. propsData: {
  38. value: 50,
  39. max: 30,
  40. min: 10
  41. }
  42. });
  43. const input = wrapper.find('input');
  44. input.element.value = 1;
  45. input.trigger('input');
  46. input.element.value = 'abc';
  47. input.trigger('input');
  48. wrapper.setData({ value: 'abc' });
  49. input.trigger('input');
  50. wrapper.setData({ value: '' });
  51. input.trigger('input');
  52. wrapper.setData({ value: 40 });
  53. input.trigger('input');
  54. wrapper.setData({ value: 30 });
  55. input.trigger('input');
  56. expect(wrapper.emitted('input')).toEqual([[30], [1], [0], [40], [30]]);
  57. });
  58. test('only allow interger', () => {
  59. const wrapper = mount(Stepper, {
  60. propsData: {
  61. integer: true
  62. }
  63. });
  64. const input = wrapper.find('input');
  65. input.element.value = '1.2';
  66. input.trigger('input');
  67. input.trigger('blur');
  68. expect(wrapper.emitted('input')).toEqual([[1]]);
  69. });
  70. test('stepper focus', () => {
  71. const wrapper = mount(Stepper);
  72. const input = wrapper.find('input');
  73. input.trigger('focus');
  74. expect(wrapper.emitted('focus')).toBeTruthy();
  75. });
  76. test('stepper blur', () => {
  77. const wrapper = mount(Stepper, {
  78. propsData: {
  79. value: 5,
  80. min: 3
  81. }
  82. });
  83. wrapper.vm.$on('input', value => {
  84. wrapper.setProps({ value });
  85. });
  86. const input = wrapper.find('input');
  87. input.trigger('blur');
  88. input.element.value = '';
  89. input.trigger('input');
  90. input.trigger('blur');
  91. expect(wrapper.emitted('input')).toEqual([[0], [3]]);
  92. expect(wrapper.emitted('blur')).toBeTruthy();
  93. });
  94. test('input width', () => {
  95. const wrapper = mount(Stepper, {
  96. propsData: {
  97. inputWidth: '10rem'
  98. }
  99. });
  100. expect(wrapper).toMatchSnapshot();
  101. });