视频播放器仓库

PlayPause.test.js 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import PlayPause from './PlayPause';
  4. import styles from './PlayPause.css';
  5. import PlayArrow from './../Icon/play_arrow.svg';
  6. import Pause from './../Icon/pause.svg';
  7. describe('PlayPause', () => {
  8. let component;
  9. beforeAll(() => {
  10. component = shallow(
  11. <PlayPause
  12. ariaLabelPlay="Play"
  13. ariaLabelPause="Pause" />
  14. );
  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('triggers \'onClick\' prop when the button is clicked', () => {
  29. const spy = jest.fn();
  30. component.setProps({
  31. onClick: spy
  32. });
  33. expect(spy)
  34. .not.toHaveBeenCalled();
  35. component.find('button').simulate('click');
  36. expect(spy)
  37. .toHaveBeenCalled();
  38. });
  39. describe('when paused', () => {
  40. beforeAll(() => {
  41. component.setProps({
  42. paused: true
  43. });
  44. });
  45. it('shows a play icon', () => {
  46. expect(component.html())
  47. .toContain(PlayArrow);
  48. expect(component.html())
  49. .not.toContain(Pause);
  50. });
  51. it('has correct aria-label', () => {
  52. expect(component.find('button').prop('aria-label'))
  53. .toEqual('Play');
  54. });
  55. });
  56. describe('when playing', () => {
  57. beforeAll(() => {
  58. component.setProps({
  59. paused: false
  60. });
  61. });
  62. it('shows a pause icon', () => {
  63. expect(component.html())
  64. .toContain(Pause);
  65. expect(component.html())
  66. .not.toContain(PlayArrow);
  67. });
  68. it('has correct aria-label', () => {
  69. expect(component.find('button').prop('aria-label'))
  70. .toEqual('Pause');
  71. });
  72. });
  73. });