all files / lib/in-line/ companion.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                                                                   
'use strict';
import axios from 'axios';
import React from 'react';
import BaseResource from '../resources/base-resource';
import { vastBaseStyle } from '../helpers/styles';
import { getVastDurationInMillis } from '../helpers/duration';
import { getTracking } from '../helpers/tracking';
 
class Companion 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(() => {
      this.onCompletedTracking();
    }, this.durationMillis);
  }
 
  onStartedTracking() {
    this.startTrackingArr.forEach((src) => {
      axios.get(src);
    });
  }
 
  onCompletedTracking() {
    this.completeTrackingArr.forEach((src) => {
      axios.get(src);
    });
  }
 
  render() {
    return (
      <div style={vastBaseStyle}>
        <BaseResource
          baseResource={this.props.companion}
          height={parseInt(this.props.companion.getAttr('height'), 10)}
          width={parseInt(this.props.companion.getAttr('width'), 10)}
        />
      </div>
    );
  }
}
 
Companion.propTypes = {
  companion: React.PropTypes.object.isRequired,
  duration: React.PropTypes.string,
  tracking: React.PropTypes.array,
};
 
export default Companion;