|
| 1 | +import React from 'react'; |
| 2 | +import { shallow } from 'enzyme'; |
| 3 | +import Time from './Time'; |
| 4 | +import styles from './Time.css'; |
| 5 | + |
| 6 | +describe('Time', () => { |
| 7 | + let component; |
| 8 | + |
| 9 | + beforeAll(() => { |
| 10 | + component = shallow(<Time />); |
| 11 | + }); |
| 12 | + |
| 13 | + it('should accept a className prop and append it to the components class', () => { |
| 14 | + const newClassNameString = 'a new className'; |
| 15 | + expect(component.prop('className')) |
| 16 | + .toContain(styles.component); |
| 17 | + component.setProps({ |
| 18 | + className: newClassNameString |
| 19 | + }); |
| 20 | + expect(component.prop('className')) |
| 21 | + .toContain(styles.component); |
| 22 | + expect(component.prop('className')) |
| 23 | + .toContain(newClassNameString); |
| 24 | + }); |
| 25 | + |
| 26 | + it('shows video duration', () => { |
| 27 | + component.setProps({ |
| 28 | + duration: 10 |
| 29 | + }); |
| 30 | + expect(component.find(`.${styles.duration}`).text()) |
| 31 | + .toEqual('00:00:10'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('shows current video elapsed time', () => { |
| 35 | + component.setProps({ |
| 36 | + currentTime: 10 |
| 37 | + }); |
| 38 | + expect(component.find(`.${styles.current}`).text()) |
| 39 | + .toEqual('00:00:10'); |
| 40 | + }); |
| 41 | + |
| 42 | + it('can handle minutes, hours and seconds', () => { |
| 43 | + component.setProps({ |
| 44 | + currentTime: 60 * 2 |
| 45 | + }); |
| 46 | + expect(component.find(`.${styles.current}`).text()) |
| 47 | + .toEqual('00:02:00'); |
| 48 | + |
| 49 | + component.setProps({ |
| 50 | + currentTime: 60 * 60 * 3 |
| 51 | + }); |
| 52 | + expect(component.find(`.${styles.current}`).text()) |
| 53 | + .toEqual('03:00:00'); |
| 54 | + |
| 55 | + component.setProps({ |
| 56 | + currentTime: 60 * 60 * 3 + 72 |
| 57 | + }); |
| 58 | + expect(component.find(`.${styles.current}`).text()) |
| 59 | + .toEqual('03:01:12'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('fails gracefully and shows 00:00:00 when video is greater than 24 hours', () => { |
| 63 | + // Who has a video longer than 24 hours? If this ever occurs then we |
| 64 | + // should consider adding it. |
| 65 | + component.setProps({ |
| 66 | + currentTime: 86401 |
| 67 | + }); |
| 68 | + expect(component.find(`.${styles.current}`).text()) |
| 69 | + .toEqual('00:00:00'); |
| 70 | + |
| 71 | + component.setProps({ |
| 72 | + currentTime: 86400 |
| 73 | + }); |
| 74 | + expect(component.find(`.${styles.current}`).text()) |
| 75 | + .toEqual('00:00:00'); |
| 76 | + }); |
| 77 | + |
| 78 | + it('fails gracefully and shows 00:00:00 when not given a number', () => { |
| 79 | + component.setProps({ |
| 80 | + currentTime: null |
| 81 | + }); |
| 82 | + expect(component.find(`.${styles.current}`).text()) |
| 83 | + .toEqual('00:00:00'); |
| 84 | + |
| 85 | + component.setProps({ |
| 86 | + currentTime: undefined |
| 87 | + }); |
| 88 | + expect(component.find(`.${styles.current}`).text()) |
| 89 | + .toEqual('00:00:00'); |
| 90 | + }); |
| 91 | +}); |
0 commit comments