<commit_before>import React from 'react';
import { mount, shallow } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';
import Navigation from '../../../public/src/components/navigation';

describe('<Navigation />', () => {
  // test variables
  const testUser = {
    first_name: 'Mr.',
    last_name: 'Cat',
    email: '<EMAIL>',
    phone_number: '15555555555'
  };
  const linksLoggedIn = [
    { title: 'Account', href: `/account/1` },
    { title: 'Logout', href: '/logout' }
  ];
  const linksLoggedOut = [
    { title: 'Register', href: '/registration' },
    { title: 'Login', href: '/login' }
  ];
  const logout = jest.fn();
  const propsLoggedIn = {
    title: testUser.first_name,
    links: linksLoggedIn,
    userInfo: testUser,
    history: {},
    logout: logout
  };
  const propsLoggedOut ={
    title: 'Menu',
    links: linksLoggedOut
  };
  describe('rendering', () => {
    const wrapper = mount(
      <MemoryRouter>
        <Navigation {...propsLoggedOut}/>
      </MemoryRouter>
    );
    it('renders correctly', () => {
      const tree = renderer.create(
        <MemoryRouter>
          <Navigation {...propsLoggedOut} />
        </MemoryRouter>
      ).toJSON();
      expect(tree).toMatchSnapshot();
    });
    it('should render <ButtonToolbar />', () => {
      expect(wrapper.find('ButtonToolbar').length).toBe(1);
    });
    it('should render <DropdownButton />', () => {
      expect(wrapper.find('DropdownButton').length).toBe(1);
    });
    it('should render <Link />', () => {
      expect(wrapper.find('Link').length).toBeGreaterThan(1);
    });
  });

  describe('props', () => {
    const wrapper = shallow(<Navigation {...propsLoggedOut} />);

    it('should recieve "Menu" if user is logged out',() => {
      expect(wrapper.instance().props['title']).toBe('Menu');
    });
    it('should recieve "Login"/"Register" links if user is logged out',() => {
      expect(wrapper.instance().props['links']).toBe(linksLoggedOut);
    });
  });

  describe('onClick',() => {
    it('should call logoutOnClick() when log out is clicked',() => {
      const wrapper = mount(
        <MemoryRouter>
          <Navigation {...propsLoggedIn}/>
        </MemoryRouter>
      );
      wrapper.find('a').last().find('a').simulate('click');
      expect(logout).toHaveBeenCalled();
    });
    it('should not render logout link, instead login link exists',() => {
      const wrapper = mount(
        <MemoryRouter>
          <Navigation {...propsLoggedOut}/>
        </MemoryRouter>
      );
      expect(wrapper.find('a').last().find('a').text()).toBe('Login');
    });
  });
});<commit_msg>Completed navigation test with updates<commit_after>import React from 'react';
import { mount, shallow } from 'enzyme';
import { MemoryRouter } from 'react-router-dom';
import renderer from 'react-test-renderer';
import Navigation from '../../../public/src/components/navigation';

describe('<Navigation />', () => {
  // test variables
  const testUser = {
    first_name: 'Beyonce',
    last_name: 'Cat',
    email: '<EMAIL>',
    phone_number: '15555555555'
  };
  const linksLoggedIn = [
    { title: 'Account', href: `/account/1` },
    { title: 'Logout', href: '/logout' }
  ];
  const linksLoggedOut = [
    { title: 'Register', href: '/registration' },
    { title: 'Login', href: '/login' }
  ];
  const logout = jest.fn();
  const propsLoggedIn = {
    title: testUser.first_name,
    links: linksLoggedIn,
    userInfo: testUser,
    history: {},
    logout: logout
  };
  const propsLoggedOut ={
    title: 'Menu',
    links: linksLoggedOut
  };
  describe('rendering', () => {
    const wrapper = mount(
      <MemoryRouter>
        <Navigation {...propsLoggedOut}/>
      </MemoryRouter>
    );
    it('renders correctly', () => {
      const tree = renderer.create(
        <MemoryRouter>
          <Navigation {...propsLoggedOut} />
        </MemoryRouter>
      ).toJSON();
      expect(tree).toMatchSnapshot();
    });
    it('should render <ButtonToolbar />', () => {
      expect(wrapper.find('ButtonToolbar').length).toBe(1);
    });
    it('should render <DropdownButton />', () => {
      expect(wrapper.find('DropdownButton').length).toBe(1);
    });
    it('should render <Link />', () => {
      expect(wrapper.find('Link').length).toBeGreaterThan(1);
    });
  });

  describe('props', () => {
    const wrapper = shallow(<Navigation {...propsLoggedOut} />);

    it('should recieve "Menu" if user is logged out',() => {
      expect(wrapper.instance().props['title']).toBe('Menu');
    });
    it('should recieve "Login"/"Register" links if user is logged out',() => {
      expect(wrapper.instance().props['links']).toBe(linksLoggedOut);
    });
    it('should recieve name if user is logged in',() => {
      wrapper.setProps(propsLoggedIn);
      expect(wrapper.instance().props['title']).toBe('Beyonce');
    });
    it('should recieve "Login"/"Register" links if user is logged out',() => {
      wrapper.setProps(propsLoggedIn);
      expect(wrapper.instance().props['links']).toBe(linksLoggedIn);
    });
  });

  describe('onClick',() => {
    it('should call logoutOnClick() when "Logout" is clicked',() => {
      const wrapper = mount(
        <MemoryRouter>
          <Navigation {...propsLoggedIn}/>
        </MemoryRouter>
      );
      wrapper.find('a').last().find('a').simulate('click');
      expect(logout).toHaveBeenCalled();
    });
    it('should not render logout link if user logged out',() => {
      const wrapper = mount(
        <MemoryRouter>
          <Navigation {...propsLoggedOut}/>
        </MemoryRouter>
      );
      expect(wrapper.find('a').last().find('a').text()).not.toBe('Logout');
    });
  });

  describe('renderLinks()',() => {
    const wrapper = shallow(<Navigation {...propsLoggedOut} />);
    it('should return link items correctly',() => {
      const links = wrapper.instance().renderLinks();
      expect(Array.isArray(links)).toBe(true);
    });
  });
});
{'fraction_non_alphanumeric': 0.19159189099368562, 'fraction_numerical': 0.004985044865403789, 'mean_word_length': 2.9288511749347257, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 68, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4217295', 'n_tokens_mistral': 1851, 'n_tokens_neox': 1829, 'n_words': 366}