<commit_before>import React from 'react';
import {shallow} from 'enzyme';
import {shallowToJson} from 'enzyme-to-json';
import {AuthLinksComponent} from './AuthLinks';
import {initReactDevise} from '../config';

describe('<AuthLinksComponent />', () => {
  const resourceName = 'users';
  const currentUser = {isLoggedIn: false};
  const AuthLinksList = ({children}) => <ul>{children}</ul>;
  const AuthLinksListItem = ({children}) => <li>{children}</li>;
  const location = {pathname: 'no-match'};

  it('should render list with 4 links', () => {
    initReactDevise();
    const component = shallow(<AuthLinksComponent
      resourceName={resourceName}
      AuthLinksList={AuthLinksList}
      AuthLinksListItem={AuthLinksListItem}
      currentUser={currentUser}
      location={location}
    />);
    const tree = shallowToJson(component);
    [
      ['/users/login', 'Log In'],
      ['/users/sign-up', 'Sign Up'],
      ['/users/confirmation/new', 'Resend Confirmation Instructions'],
      ['/users/password/new', 'Reset Your Password']
    ].forEach(route => {
      expect(tree.children.some(n => n.props.path === route[0] && n.children[0] === route[1])).toBeTruthy();
    });
  });
  it('should render link for custom route', () => {
    initReactDevise({
      routes: {
        login: {
          path: '/foo',
          linkText: 'Foo Bar'
        }
      }
    });
    const component = shallow(<AuthLinksComponent
      resourceName={resourceName}
      AuthLinksList={AuthLinksList}
      AuthLinksListItem={AuthLinksListItem}
      currentUser={currentUser}
      location={location}
    />);
    const tree = shallowToJson(component);
    expect(tree.children.some(n => n.props.path === '/users/foo' && n.children[0] === 'Foo Bar')).toBeTruthy();
  });
});
<commit_msg>Fixed tests.<commit_after>import React from 'react';
import {shallow, mount} from 'enzyme';
import {shallowToJson, mountToJson} from 'enzyme-to-json';
import {AuthLinksComponent} from './AuthLinks';
import {initReactDevise} from '../config';

describe('<AuthLinksComponent />', () => {
  const resourceName = 'users';
  const currentUser = {isLoggedIn: false};
  const AuthLinksList = ({children}) => <ul>{children}</ul>;
  const AuthLinksListItem = ({path, route: {linkText}, location: {pathname}}) => {
    return <li><a href={path}>{linkText}</a></li>;
  };
  const location = {pathname: 'no-match'};

  it('should render list with 4 links', () => {
    initReactDevise();
    const component = mount(<AuthLinksComponent
      resourceName={resourceName}
      AuthLinksList={AuthLinksList}
      AuthLinksListItem={AuthLinksListItem}
      currentUser={currentUser}
      location={location}
    />);
    const tree = mountToJson(component);
    const list = tree.children[0].children[0];
    expect(list.type).toEqual('ul');
    [
      ['/users/login', 'Log In'],
      ['/users/sign-up', 'Sign Up'],
      ['/users/confirmation/new', 'Resend Confirmation Instructions'],
      ['/users/password/new', 'Reset Your Password']
    ].forEach(([path, text]) => {
      expect(list.children.some(listItem => {
        return (
          listItem.children[0].type === 'li' &&
          listItem.children[0].children[0].type === 'a' &&
          listItem.children[0].children[0].props.href === path &&
          listItem.children[0].children[0].children[0] === text
        );
      })).toBeTruthy();
    });
  });
  it('should render link for custom route', () => {
    initReactDevise({
      routes: {
        login: {
          path: '/foo',
          linkText: 'Foo Bar'
        }
      }
    });
    const component = mount(<AuthLinksComponent
      resourceName={resourceName}
      AuthLinksList={AuthLinksList}
      AuthLinksListItem={AuthLinksListItem}
      currentUser={currentUser}
      location={location}
    />);
    const tree = mountToJson(component);
    const list = tree.children[0].children[0];
    expect(list.children.some(listItem => {
      return (
        listItem.children[0].children[0].props.href === '/users/foo' &&
        listItem.children[0].children[0].children[0] === 'Foo Bar'
      );
    })).toBeTruthy();
  });
});

{'fraction_non_alphanumeric': 0.17293777134587554, 'fraction_numerical': 0.005547515677761698, 'mean_word_length': 3.2446264073694984, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, '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': '6786556', 'n_tokens_mistral': 1259, 'n_tokens_neox': 1248, 'n_words': 243}