视频播放器仓库

Seek.test.js 2.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import Seek from './Seek';
  4. import styles from './Seek.css';
  5. describe('Seek', () => {
  6. let component;
  7. beforeAll(() => {
  8. component = shallow(<Seek />);
  9. });
  10. it('should accept a className prop and append it to the components class', () => {
  11. const newClassNameString = 'a new className';
  12. expect(component.prop('className'))
  13. .toContain(styles.component);
  14. component.setProps({
  15. className: newClassNameString
  16. });
  17. expect(component.prop('className'))
  18. .toContain(styles.component);
  19. expect(component.prop('className'))
  20. .toContain(newClassNameString);
  21. });
  22. it('has a range input with correct ranges and percentagePlayed value', () => {
  23. component.setProps({
  24. percentagePlayed: 10
  25. });
  26. const rangeInput = component.find(`.${styles.input}`);
  27. expect(rangeInput.prop('type'))
  28. .toEqual('range');
  29. expect(rangeInput.prop('orient'))
  30. .toEqual('horizontal');
  31. expect(rangeInput.prop('step'))
  32. .toEqual(1);
  33. expect(rangeInput.prop('min'))
  34. .toEqual('0');
  35. expect(rangeInput.prop('max'))
  36. .toEqual('100');
  37. expect(rangeInput.prop('value'))
  38. .toEqual(10);
  39. });
  40. it('handles an undefined percentagePlayed value', () => {
  41. component.setProps({
  42. percentagePlayed: undefined
  43. });
  44. const rangeInput = component.find(`.${styles.input}`);
  45. expect(rangeInput.prop('value'))
  46. .toEqual(0);
  47. });
  48. it('triggers \'onChange\' prop when the input is changed', () => {
  49. const spy = jest.fn();
  50. component.setProps({
  51. onChange: spy
  52. });
  53. expect(spy)
  54. .not.toHaveBeenCalled();
  55. component.find('input').simulate('change');
  56. expect(spy)
  57. .toHaveBeenCalled();
  58. });
  59. it('changes the played fill bar width', () => {
  60. component.setProps({
  61. percentagePlayed: 0
  62. });
  63. expect(component.find(`.${styles.fill}`).prop('style').width)
  64. .toEqual('0%');
  65. component.setProps({
  66. percentagePlayed: 11
  67. });
  68. expect(component.find(`.${styles.fill}`).prop('style').width)
  69. .toEqual('11%');
  70. });
  71. it('changes the buffer bar width', () => {
  72. component.setProps({
  73. percentageBuffered: 0
  74. });
  75. expect(component.find(`.${styles.buffer}`).prop('style').width)
  76. .toEqual('0%');
  77. component.setProps({
  78. percentageBuffered: 11
  79. });
  80. expect(component.find(`.${styles.buffer}`).prop('style').width)
  81. .toEqual('11%');
  82. });
  83. });