视频播放器仓库

DefaultPlayer.test.js 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import { DefaultPlayer } from './DefaultPlayer';
  4. import styles from './DefaultPlayer.css';
  5. import Time from './Time/Time';
  6. import Seek from './Seek/Seek';
  7. import Volume from './Volume/Volume';
  8. import PlayPause from './PlayPause/PlayPause';
  9. import Fullscreen from './Fullscreen/Fullscreen';
  10. import Overlay from './Overlay/Overlay';
  11. describe('DefaultPlayer', () => {
  12. let component;
  13. beforeAll(() => {
  14. component = shallow(<DefaultPlayer />);
  15. });
  16. it('should accept a className prop and append it to the components class', () => {
  17. const newClassNameString = 'a new className';
  18. expect(component.prop('className'))
  19. .toContain(styles.component);
  20. component.setProps({
  21. className: newClassNameString
  22. });
  23. expect(component.prop('className'))
  24. .toContain(styles.component);
  25. expect(component.prop('className'))
  26. .toContain(newClassNameString);
  27. });
  28. it('applies `style` prop if provided', () => {
  29. component.setProps({
  30. style: { color: 'red' }
  31. });
  32. expect(component.prop('style'))
  33. .toEqual({ color: 'red' });
  34. });
  35. it('spreads all parent props on the video element', () => {
  36. component.setProps({
  37. autoPlay: true
  38. });
  39. expect(component.find('video').prop('autoPlay'))
  40. .toEqual(true);
  41. });
  42. it('has an overlay component', () => {
  43. expect(component.find(Overlay).exists())
  44. .toBeTruthy();
  45. });
  46. it('renders some default controls in a default order', () => {
  47. const controlsComponent = component.find(`.${styles.controls}`);
  48. expect(controlsComponent.childAt(0).is(PlayPause))
  49. .toBeTruthy();
  50. expect(controlsComponent.childAt(1).is(Seek))
  51. .toBeTruthy();
  52. expect(controlsComponent.childAt(2).is(Time))
  53. .toBeTruthy();
  54. expect(controlsComponent.childAt(3).is(Volume))
  55. .toBeTruthy();
  56. expect(controlsComponent.childAt(4).is(Fullscreen))
  57. .toBeTruthy();
  58. });
  59. it('renders controls in a given custom order', () => {
  60. component.setProps({
  61. controls: ['Fullscreen', 'Seek', 'Time']
  62. });
  63. const controlsComponent = component.find(`.${styles.controls}`);
  64. expect(controlsComponent.childAt(0).is(Fullscreen))
  65. .toBeTruthy();
  66. expect(controlsComponent.childAt(1).is(Seek))
  67. .toBeTruthy();
  68. expect(controlsComponent.childAt(2).is(Time))
  69. .toBeTruthy();
  70. });
  71. it('renders no controls when given an empty array', () => {
  72. expect(component.find(`.${styles.controls}`).exists())
  73. .toBeTruthy();
  74. component.setProps({
  75. controls: []
  76. });
  77. expect(component.find(`.${styles.controls}`).exists())
  78. .toBeFalsy();
  79. });
  80. it('renders no controls when there is an error', () => {
  81. component.setProps({
  82. controls: ['PlayPause'],
  83. video: {
  84. error: false
  85. }
  86. });
  87. expect(component.find(`.${styles.controls}`).exists())
  88. .toBeTruthy();
  89. component.setProps({
  90. controls: ['PlayPause'],
  91. video: {
  92. error: true
  93. }
  94. });
  95. expect(component.find(`.${styles.controls}`).exists())
  96. .toBeFalsy();
  97. });
  98. });