视频播放器仓库

Time.test.js 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. import React from 'react';
  2. import { shallow } from 'enzyme';
  3. import Time from './Time';
  4. import styles from './Time.css';
  5. describe('Time', () => {
  6. let component;
  7. beforeAll(() => {
  8. component = shallow(<Time />);
  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('shows video duration', () => {
  23. component.setProps({
  24. duration: 10
  25. });
  26. expect(component.find(`.${styles.duration}`).text())
  27. .toEqual('0:10');
  28. });
  29. it('shows current video elapsed time', () => {
  30. component.setProps({
  31. currentTime: 10
  32. });
  33. expect(component.find(`.${styles.current}`).text())
  34. .toEqual('0:10');
  35. });
  36. it('can handle minutes, hours and seconds', () => {
  37. component.setProps({
  38. currentTime: 60 * 2
  39. });
  40. expect(component.find(`.${styles.current}`).text())
  41. .toEqual('2:00');
  42. component.setProps({
  43. currentTime: 60 * 60 * 3
  44. });
  45. expect(component.find(`.${styles.current}`).text())
  46. .toEqual('3:00:00');
  47. component.setProps({
  48. currentTime: 60 * 60 * 3 + 72
  49. });
  50. expect(component.find(`.${styles.current}`).text())
  51. .toEqual('3:01:12');
  52. });
  53. it('fails gracefully and shows 00:00:00 when video is greater than 24 hours', () => {
  54. // Who has a video longer than 24 hours? If this ever occurs then we
  55. // should consider adding it.
  56. component.setProps({
  57. currentTime: 86401
  58. });
  59. expect(component.find(`.${styles.current}`).text())
  60. .toEqual('0:00');
  61. component.setProps({
  62. currentTime: 86400
  63. });
  64. expect(component.find(`.${styles.current}`).text())
  65. .toEqual('0:00');
  66. });
  67. it('fails gracefully and shows 00:00 when not given a number', () => {
  68. component.setProps({
  69. currentTime: null
  70. });
  71. expect(component.find(`.${styles.current}`).text())
  72. .toEqual('0:00');
  73. component.setProps({
  74. currentTime: undefined
  75. });
  76. expect(component.find(`.${styles.current}`).text())
  77. .toEqual('0:00');
  78. });
  79. });