import React from 'react';
import { shallow } from 'enzyme';
import FooterList from './footer-list';

describe('<FooterList />', () => {
  const testLinks = [
    {
      id: 'id',
      name: 'Test Link',
      url: 'www.test.com',
    },
    {
      id: 'id',
      name: 'Test Link 2',
      url: 'www.test2.com',
    },
  ];

  it('should render the correct number of links', () => {
    const component = shallow(<FooterList links={testLinks} />);
    expect(component.find('NavigationLink')).toHaveLength(2);
  });

  it('should pass secondary prop to NavigationLink when secondary is set', () => {
    const component = shallow(<FooterList links={testLinks} secondary />);
    expect(
      component
        .find('NavigationLink')
        .first()
        .props().secondary,
    ).toEqual(true);
  });

  it('should pass major prop to NavigationLink when major is set', () => {
    const component = shallow(<FooterList links={testLinks} major />);
    expect(
      component
        .find('NavigationLink')
        .first()
        .props().major,
    ).toEqual(true);
  });

  it('should pass minor prop to NavigationLink when minor is set', () => {
    const component = shallow(<FooterList links={testLinks} minor />);
    expect(
      component
        .find('NavigationLink')
        .first()
        .props().minor,
    ).toEqual(true);
  });

  it('should pass inverse prop to NavigationLink when inverse is set', () => {
    const component = shallow(<FooterList links={testLinks} inverse />);
    expect(
      component
        .find('NavigationLink')
        .first()
        .props().inverse,
    ).toEqual(true);
  });

  it('should not render the link in a region it is not allowed in', () => {
    const component = shallow(
      <FooterList
        links={[
          ...testLinks,
          {
            id: 'test',
            name: 'Regional Link',
            url: '/something',
            allowedRegions: ['DE'],
          },
        ]}
        region='US'
      />,
    );
    expect(component.find('NavigationLink')).toHaveLength(2);
  });

  it('should render the link in allowed region', () => {
    const component = shallow(
      <FooterList
        links={[
          ...testLinks,
          {
            id: 'test',
            name: 'Regional Link',
            url: '/something',
            allowedRegions: ['DE', 'US'],
          },
        ]}
        region='DE'
      />,
    );
    expect(component.find('NavigationLink')).toHaveLength(3);
  });
});
