All files OpenWeatherMap.js

100% Statements 8/8
100% Branches 2/2
100% Functions 1/1
100% Lines 8/8
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      1x 4x 2x         2x 2x   2x                         1x         1x            
import React, { PropTypes } from 'react';
import moment from 'moment';
 
const OpenWeatherMap = ({ data, config }) => {
  if (data === OpenWeatherMap.defaultProps.data) {
    return (
      <div className={config.containerClassName} />
    );
  }
 
  const day = moment.unix(data.dt);
  const src = `http://openweathermap.org/img/w/${data.weather[0].icon}.png`;
 
  return (
    <div className={config.containerClassName}>
      <div className="main-heading">{data.name}, {data.sys.country}</div>
      <div className="day">{day.format('dddd h:mm A')}</div>
      <div className="description">{data.weather[0].description}</div>
      <div className="icon">
        <img src={src} alt={data.weather[0].description} />
      </div>
      <div className="temperature">{data.main.temp} &deg;C</div>
    </div>
  );
};
 
OpenWeatherMap.propTypes = {
  data: PropTypes.object.isRequired,
  config: PropTypes.object,
};
 
OpenWeatherMap.defaultProps = {
  data: { weather: [{}], sys: {}, main: {} },
  config: { containerClassName: 'react-open-weather-map' },
};
 
export default OpenWeatherMap;