all files / components/ Header.js

88.57% Statements 31/35
56.67% Branches 17/30
91.67% Functions 11/12
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 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                                              
import React from 'react';IEE
import PropTypes from 'prop-types';
import { browserHistory, Link } from 'react-router';EIII
 
class Header extends React.Component {
  componentDidMount() {
    // some logic here - we only test if the method is called
  }
  render() {
    return (
      <div className="wrapper">
        <div className="header col-wrap">
          <div className="col col--lg-one-third col--md-one-third">
            <a onClick={() => browserHistory.push(this.props.imageUrl)} style={{ cursor: 'pointer' }}>
              <img className="logo" src="https://cdn.ons.gov.uk/assets/images/ons-logo/v2/ons-logo.svg" alt="Office for National Statistics" />
            </a>
          </div>
          <div className="col col--lg-two-thirds col--md-two-thirds print--hide">&nbsp;</div>
          {this.props.showHeaderItems &&
            <div className="secondary-nav col col--lg-two-thirds col--md-two-thirds print--hide">
              <ul className="secondary-nav__list js-nav-clone__list">
                {
                  this.props.headerLinks.map((item) => {
                    return (
                      <li key={item.text} className="secondary-nav__item">
                        <Link className="secondary-nav__link  js-nav-clone__link" to={item.link}>{item.text}</Link>
                      </li>
                    );
                  })
                }
                {this.props.children}
              </ul>
            </div>
          }
        </div>
      </div>
    );
  }
}
 
Header.defaultProps = {
  showHeaderItems: true,
  headerLinks: [],
  children: null,
};
 
Header.propTypes = {
  showHeaderItems: PropTypes.bool,
  headerLinks: PropTypes.array,
  imageUrl: PropTypes.string.isRequired,
  children: PropTypes.object,
};
 
export default Header;