all files / lib/in-line/ non-linear.jsx

100% Statements 22/22
50% Branches 1/2
100% Functions 8/8
100% Lines 22/22
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56                                                                    
import axios from 'axios';
import React from 'react';
import BaseResource from '../resources/base-resource';
import { getVastDurationInMillis } from '../helpers/duration';
import { getTracking } from '../helpers/tracking';
 
class NonLinear extends React.Component {
  constructor(props) {
    super(props);
    this.durationMillis = getVastDurationInMillis(this.props.duration);
    this.startTrackingArr = getTracking('start', this.props.tracking);
    this.completeTrackingArr = getTracking('complete', this.props.tracking);
  }
 
  componentDidMount() {
    this.onStartedTracking();
    setTimeout((e) => {
      this.onCompletedTracking();
      this.props.onEnded(e);
    }, this.durationMillis);
  }
 
  onStartedTracking() {
    this.startTrackingArr.forEach((src) => {
      axios.get(src);
    });
  }
 
  onCompletedTracking() {
    this.completeTrackingArr.forEach((src) => {
      axios.get(src);
    });
  }
 
  render() {
    return (
      <BaseResource
        baseResource={this.props.nonLinear}
        height={this.props.height}
        width={this.props.width}
      />
    );
  }
}
 
NonLinear.propTypes = {
  tracking: React.PropTypes.array,
  onEnded: React.PropTypes.func,
  nonLinear: React.PropTypes.object,
  height: React.PropTypes.number,
  width: React.PropTypes.number,
  duration: React.PropTypes.string,
};
 
export default NonLinear;