<commit_before>import * as React from 'react';
import * as renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

import Icon from '../../src/Icon';

let consoleError: jest.SpyInstance<{}>;

beforeAll(() => {
  consoleError = jest.spyOn(console, 'error');
});

afterEach(() => {
  expect(consoleError).not.toHaveBeenCalled();
});

describe('Icon', () => {

  it('renders correctly', () => {
    const component = renderer.create(
      <Icon icon='foo' />
    );
    expect(component).toMatchSnapshot();
  });

  it('renders null if no icon is passed', () => {
    const component = renderer.create(
      <Icon />
    );
    expect(component.toJSON()).toBeNull();
  });

  it('renders no child when path is 1', () => {
    const component = shallow(
      <Icon icon='foo' paths={1} />
    );
    expect(component.children().length).toBe(0);
  });

  it('renders a child for each path', () => {
    const component = shallow(
      <Icon icon='foo' paths={4} />
    );
    expect(component.children().length).toBe(4);
    component.children().forEach((child, i) => {
      expect(child.prop('className')).toBe(`path${i + 1}`);
    });
  });

  it('calls onClick once when clicked', () => {
    const onClick = jest.fn();
    const component = shallow(
      <Icon icon='foo' onClick={onClick} />
    );
    component.simulate('click');
    expect(onClick).toHaveBeenCalledTimes(1);
  });


  it('computes className', () => {
    const component = shallow(
      <Icon icon='foo' className='myicon' />
    );
    expect(component.hasClass('icon')).toBe(true);
    expect(component.hasClass('icon-foo')).toBe(true);
    expect(component.hasClass('myicon')).toBe(true);
  });

  it('computes color when not provided', () => {
    const component = shallow(
      <Icon icon='foo' />
    );<commit_msg>add simple test for Icon.prefix<commit_after>import * as React from 'react';
import * as renderer from 'react-test-renderer';
import { shallow } from 'enzyme';

import Icon from '../../src/Icon';

let consoleError: jest.SpyInstance<{}>;

beforeAll(() => {
  consoleError = jest.spyOn(console, 'error');
});

afterEach(() => {
  expect(consoleError).not.toHaveBeenCalled();
});

describe('Icon', () => {

  it('renders correctly', () => {
    const component = renderer.create(
      <Icon icon='foo' />
    );
    expect(component).toMatchSnapshot();
  });

  it('renders null if no icon is passed', () => {
    const component = renderer.create(
      <Icon />
    );
    expect(component.toJSON()).toBeNull();
  });

  it('renders no child when path is 1', () => {
    const component = shallow(
      <Icon icon='foo' paths={1} />
    );
    expect(component.children().length).toBe(0);
  });

  it('renders a child for each path', () => {
    const component = shallow(
      <Icon icon='foo' paths={4} />
    );
    expect(component.children().length).toBe(4);
    component.children().forEach((child, i) => {
      expect(child.prop('className')).toBe(`path${i + 1}`);
    });
  });

  it('calls onClick once when clicked', () => {
    const onClick = jest.fn();
    const component = shallow(
      <Icon icon='foo' onClick={onClick} />
    );
    component.simulate('click');
    expect(onClick).toHaveBeenCalledTimes(1);
  });


  it('computes className', () => {
    const component = shallow(
      <Icon icon='foo' className='myicon' />
    );
    expect(component.hasClass('icon')).toBe(true);
    expect(component.hasClass('icon-foo')).toBe(true);
    expect(component.hasClass('myicon')).toBe(true);
  });

  it('computes className with custom prefix', () => {
    const component = shallow(
      <Icon icon='foo' prefix='fa' />
    );
    expect(component.hasClass('fa')).toBe(true);
    expect(component.hasClass('fa-foo')).toBe(true);
  });

  it('computes color when not provided', () => {
    const component = shallow(
      <Icon icon='foo' />
    );
{'fraction_non_alphanumeric': 0.195680123425045, 'fraction_numerical': 0.0035998971457958345, 'mean_word_length': 3.3078626799557034, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 43, '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': '336353', 'n_tokens_mistral': 1212, 'n_tokens_neox': 1208, 'n_words': 249}