视频播放器仓库

Volume.test.js 4.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import Volume from './Volume';
  4. import styles from './Volume.css';
  5. import VolumeOff from './../Icon/volume_off.svg';
  6. import VolumeUp from './../Icon/volume_up.svg';
  7. describe('Volume', () => {
  8. let component;
  9. beforeAll(() => {
  10. component = shallow(
  11. <Volume
  12. ariaLabelMute="Mute"
  13. ariaLabelUnmute="Unmute"
  14. ariaLabelVolume="Change volume" />
  15. );
  16. });
  17. it('should accept a className prop and append it to the components class', () => {
  18. const newClassNameString = 'a new className';
  19. expect(component.prop('className'))
  20. .toContain(styles.component);
  21. component.setProps({
  22. className: newClassNameString
  23. });
  24. expect(component.prop('className'))
  25. .toContain(styles.component);
  26. expect(component.prop('className'))
  27. .toContain(newClassNameString);
  28. });
  29. it('has a vertical range input with correct ranges and step', () => {
  30. const rangeInput = component.find(`.${styles.input}`);
  31. expect(rangeInput.prop('type'))
  32. .toEqual('range');
  33. expect(rangeInput.prop('orient'))
  34. .toEqual('vertical');
  35. expect(rangeInput.prop('step'))
  36. .toEqual(0.1);
  37. expect(rangeInput.prop('min'))
  38. .toEqual('0');
  39. expect(rangeInput.prop('max'))
  40. .toEqual('1');
  41. expect(rangeInput.prop('aria-label'))
  42. .toEqual('Change volume');
  43. });
  44. it('handles an undefined volume value', () => {
  45. component.setProps({
  46. volume: undefined
  47. });
  48. const rangeInput = component.find(`.${styles.input}`);
  49. expect(rangeInput.prop('value'))
  50. .toEqual(0);
  51. });
  52. it('triggers \'onClick\' prop when the button is clicked', () => {
  53. const spy = jest.fn();
  54. component.setProps({
  55. onClick: spy
  56. });
  57. expect(spy)
  58. .not.toHaveBeenCalled();
  59. component.find('button').simulate('click');
  60. expect(spy)
  61. .toHaveBeenCalled();
  62. });
  63. it('triggers \'onChange\' prop when the input is changed', () => {
  64. const spy = jest.fn();
  65. component.setProps({
  66. onChange: spy
  67. });
  68. expect(spy)
  69. .not.toHaveBeenCalled();
  70. component.find('input').simulate('change');
  71. expect(spy)
  72. .toHaveBeenCalled();
  73. });
  74. describe('when muted', () => {
  75. beforeAll(() => {
  76. component.setProps({
  77. muted: true,
  78. volume: 0.5
  79. });
  80. });
  81. it('shows a muted icon', () => {
  82. expect(component.html())
  83. .toContain(VolumeOff);
  84. expect(component.html())
  85. .not.toContain(VolumeUp);
  86. });
  87. it('has an empty track fill and range input', () => {
  88. expect(component.find(`.${styles.fill}`).prop('style').height)
  89. .toEqual('0%');
  90. expect(component.find(`.${styles.input}`).prop('value'))
  91. .toEqual(0);
  92. });
  93. it('has correct aria-label', () => {
  94. expect(component.find('button').prop('aria-label'))
  95. .toEqual('Unmute');
  96. });
  97. });
  98. describe('when unmuted but has no volume', () => {
  99. beforeAll(() => {
  100. component.setProps({
  101. muted: false,
  102. volume: 0
  103. });
  104. });
  105. it('shows a muted icon', () => {
  106. expect(component.html())
  107. .toContain(VolumeOff);
  108. expect(component.html())
  109. .not.toContain(VolumeUp);
  110. });
  111. it('has an empty track fill and range input', () => {
  112. expect(component.find(`.${styles.fill}`).prop('style').height)
  113. .toEqual('0%');
  114. expect(component.find(`.${styles.input}`).prop('value'))
  115. .toEqual(0);
  116. });
  117. it('has correct aria-label', () => {
  118. expect(component.find('button').prop('aria-label'))
  119. .toEqual('Unmute');
  120. });
  121. });
  122. describe('when has volume and is not muted', () => {
  123. beforeAll(() => {
  124. component.setProps({
  125. muted: false,
  126. volume: 0.5
  127. });
  128. });
  129. it('shows an unmute icon', () => {
  130. expect(component.html())
  131. .toContain(VolumeUp);
  132. expect(component.html())
  133. .not.toContain(VolumeOff);
  134. });
  135. it('has some track filled and a range input value', () => {
  136. expect(component.find(`.${styles.fill}`).prop('style').height)
  137. .toEqual('50%');
  138. expect(component.find(`.${styles.input}`).prop('value'))
  139. .toEqual(0.5);
  140. });
  141. it('has correct aria-label', () => {
  142. expect(component.find('button').prop('aria-label'))
  143. .toEqual('Mute');
  144. });
  145. });
  146. });