/* eslint-disable no-console */
import React from 'react';
import { shallow } from 'enzyme';
import NavigationList from './navigation-list';

describe('<NavigationList />', () => {
  it('should render the Opinion list correctly', () => {
    const listCount = 10;
    const component = shallow(
      <NavigationList type='opinion' showNavToggle menuIsOpen />,
    );
    expect(component.find('NavigationControl').props().title).toEqual(
      'Opinion',
    );
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the Current topics list correctly', () => {
    const listCount = 7;
    const component = shallow(
      <NavigationList type='current-topics' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual(
      'Current topics',
    );
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the World list correctly', () => {
    const listCount = 13;
    const component = shallow(
      <NavigationList type='world' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual('World');
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the In depth list correctly', () => {
    const listCount = 8;
    const component = shallow(
      <NavigationList type='in-depth' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual(
      'In depth',
    );
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the Business & economics list correctly', () => {
    const listCount = 5;
    const component = shallow(
      <NavigationList type='business-and-economics' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual(
      'Business & economics',
    );
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the Culture & society list correctly', () => {
    const listCount = 5;
    const component = shallow(
      <NavigationList type='culture-and-society' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual(
      'Culture & society',
    );
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it('should render the More list correctly', () => {
    const listCount = 8;
    const component = shallow(
      <NavigationList type='more' menuIsOpen showNavToggle />,
    );
    expect(component.find('NavigationControl').props().title).toEqual('More');
    expect(component.find('NavigationLink')).toHaveLength(listCount);
  });

  it("should not render a NavigationList when type isn't one of the required types", () => {
    const originalError = console.error;
    console.error = jest.fn();

    const component = shallow(<NavigationList type='' menuIsOpen />);
    expect(component.find('NavigationList')).toHaveLength(0);

    console.error = originalError;
  });
});
