<commit_before>import { expect } from 'chai';
import React from 'react';
import Loader from 'react-loader';
import simple from 'simple-mock';

import PageWrapper from 'pages/PageWrapper';
import { shallowWithIntl } from 'utils/testUtils';
import { UnconnectedHomePage as HomePage } from './HomePage';
import HomeSearchBox from './HomeSearchBox';

describe('pages/home/HomePage', () => {
  const history = {
    push: () => {},
  };

  const defaultProps = {
    history,
    actions: {
      fetchPurposes: simple.stub(),
    },
    isFetchingPurposes: false,
    purposes: [
      {
        label: 'Purpose 1',
        value: 'purpose-1',
      },
      {
        label: 'Purpose 2',
        value: 'purpose-2',
      },
      {
        label: 'Purpose 3',
        value: 'purpose-3',
      },
      {
        label: 'Purpose 4',
        value: 'purpose-4',
      },
    ],
  };

  function getWrapper(extraProps) {
    return shallowWithIntl(<HomePage {...defaultProps} {...extraProps} />);
  }

  describe('render', () => {
    it('renders PageWrapper with correct props', () => {
      const pageWrapper = getWrapper().find(PageWrapper);
      expect(pageWrapper).to.have.length(1);
      expect(pageWrapper.prop('className')).to.equal('app-HomePageContent');
      expect(pageWrapper.prop('title')).to.equal('HomePage.title');
    });

    it('renders HomeSearchBox with correct props', () => {
      const wrapper = getWrapper();
      const instance = wrapper.instance();
      const homeSearchBox = wrapper.find(HomeSearchBox);
      expect(homeSearchBox).to.have.length(1);
      expect(homeSearchBox.prop('onSearch')).to.equal(instance.handleSearch);
    });

    describe('Loader', () => {
      it('renders Loader with correct props when not fetching purposes', () => {
        const loader = getWrapper().find(Loader);
        expect(loader.length).to.equal(1);
        expect(loader.at(0).prop('loaded')).to.be.true;
      });

      it('renders Loader with correct props when fetching purposes', () => {
        const loader = getWrapper({ isFetchingPurposes: true }).find(Loader);
        expect(loader.length).to.equal(1);
        expect(loader.at(0).prop('loaded')).to.be.false;
      });

      it('renders purpose banners', () => {
        const banners = getWrapper().find('.app-HomePageContent__banner');
        expect(banners.length).to.equal(defaultProps.purposes.length);
      });
    });

    describe('Purpose banners', () => {
      let instance;

      before(() => {
        const wrapper = getWrapper();
        instance = wrapper.instance();
      });

      after(() => {
        simple.restore();
      });

      it(' is a Link component', () => {
        expect(instance.find('Link')).to.have.lengthOf(1);
        expect(instance.find('Link').prop('to')).to.be.exist();
      });
    });
  });

  describe('componentDidMount', () => {
    function callComponentDidMount(props, extraActions) {
      const actions = { ...defaultProps.actions, ...extraActions };
      const instance = getWrapper({ ...props, actions }).instance();
      instance.componentDidMount();
    }

    it('fetches purposes', () => {
      const fetchPurposes = simple.mock();
      callComponentDidMount({}, { fetchPurposes });
      expect(fetchPurposes.callCount).to.equal(1);
    });
  });

  describe('handleSearch', () => {<commit_msg>change test to find component<commit_after>import { expect } from 'chai';
import React from 'react';
import Loader from 'react-loader';
import simple from 'simple-mock';
import Link from 'react-router-dom/Link';

import PageWrapper from 'pages/PageWrapper';
import { shallowWithIntl } from 'utils/testUtils';
import { UnconnectedHomePage as HomePage } from './HomePage';
import HomeSearchBox from './HomeSearchBox';

describe('pages/home/HomePage', () => {
  const history = {
    push: () => {},
  };

  const defaultProps = {
    history,
    actions: {
      fetchPurposes: simple.stub(),
    },
    isFetchingPurposes: false,
    purposes: [
      {
        label: 'Purpose 1',
        value: 'purpose-1',
      },
      {
        label: 'Purpose 2',
        value: 'purpose-2',
      },
      {
        label: 'Purpose 3',
        value: 'purpose-3',
      },
      {
        label: 'Purpose 4',
        value: 'purpose-4',
      },
    ],
  };

  function getWrapper(extraProps) {
    return shallowWithIntl(<HomePage {...defaultProps} {...extraProps} />);
  }

  describe('render', () => {
    it('renders PageWrapper with correct props', () => {
      const pageWrapper = getWrapper().find(PageWrapper);
      expect(pageWrapper).to.have.length(1);
      expect(pageWrapper.prop('className')).to.equal('app-HomePageContent');
      expect(pageWrapper.prop('title')).to.equal('HomePage.title');
    });

    it('renders HomeSearchBox with correct props', () => {
      const wrapper = getWrapper();
      const instance = wrapper.instance();
      const homeSearchBox = wrapper.find(HomeSearchBox);
      expect(homeSearchBox).to.have.length(1);
      expect(homeSearchBox.prop('onSearch')).to.equal(instance.handleSearch);
    });

    describe('Loader', () => {
      it('renders Loader with correct props when not fetching purposes', () => {
        const loader = getWrapper().find(Loader);
        expect(loader.length).to.equal(1);
        expect(loader.at(0).prop('loaded')).to.be.true;
      });

      it('renders Loader with correct props when fetching purposes', () => {
        const loader = getWrapper({ isFetchingPurposes: true }).find(Loader);
        expect(loader.length).to.equal(1);
        expect(loader.at(0).prop('loaded')).to.be.false;
      });

      it('renders purpose banners', () => {
        const banners = getWrapper().find('.app-HomePageContent__banner');
        expect(banners.length).to.equal(defaultProps.purposes.length);
      });
    });

    describe('Purpose banners', () => {
      let instance;

      before(() => {
        const wrapper = getWrapper();
        instance = wrapper.instance();
      });

      after(() => {
        simple.restore();
      });

      it(' is a Link component', () => {
        expect(instance.find(Link)).to.have.lengthOf(1);
        expect(instance.find(Link).prop('to')).to.be.exist();
      });
    });
  });

  describe('componentDidMount', () => {
    function callComponentDidMount(props, extraActions) {
      const actions = { ...defaultProps.actions, ...extraActions };
      const instance = getWrapper({ ...props, actions }).instance();
      instance.componentDidMount();
    }

    it('fetches purposes', () => {
      const fetchPurposes = simple.mock();
      callComponentDidMount({}, { fetchPurposes });
      expect(fetchPurposes.callCount).to.equal(1);
    });
  });

  describe('handleSearch', () => {
{'fraction_non_alphanumeric': 0.16982248520710058, 'fraction_numerical': 0.004733727810650888, 'mean_word_length': 2.7770949720670393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, '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': '6250991', 'n_tokens_mistral': 2010, 'n_tokens_neox': 1958, 'n_words': 372}