<commit_before>/* eslint-env mocha */
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import {Search} from '../../src/frontend/containers/Search'
import Constants from '../../src/frontend/constants/Constants'
import ReactDOM from 'react-dom'
import {IntlProvider} from 'react-intl'

function setup (propOverrides) {
  const props = {
    searchActions: { search: expect.createSpy() },
    searchResults: [],
    isSearching: false,
    dispatch: () => {},
    searchError: false,
    filters: [],
    location: { query: {} },
    locationQuery: {},
    totalHits: 0,
    totalHitsPublications: 0,
    searchFilterActions: {
      toggleFilter: () => {},
      toggleFilterVisibility: () => {},
      toggleAllFiltersVisibility: () => {},
      toggleCollapseFilter: () => {}
    },
    resourceActions: {
      fetchWorkResource: () => {}
    },
    resources: {},
    items: {},
    windowWidth: 1000,
    ...propOverrides
  }

  const output = TestUtils.renderIntoDocument(
    <IntlProvider locale="en">
      <Search {...props} />
    </IntlProvider>
  )

  return {
    props: props,
    output: output,
    node: ReactDOM.findDOMNode(output)
  }
}

describe('containers', () => {
  describe('Search', () => {
    it('should search on mount when query is provided', () => {
      const { props } = setup({ locationQuery: { query: 'test_query' } })
      expect(props.searchActions.search).toHaveBeenCalled()
    })

    it('should not render pagination when few results', () => {
      const { node } = setup({ location: { query: { query: 'test' } }, totalHits: Constants.maxSearchResultsPerPage })
      expect(node.querySelectorAll("[data-automation-id='search-results-pagination']").length).toBe(0)
    })

    it('should render pagination when many results', () => {
      const { node } = setup({
        location: { query: { query: 'test' } },
        totalHits: Constants.maxSearchResultsPerPage + 1
      })
      expect(node.querySelectorAll("[data-automation-id='search-results-pagination']").length).toBe(1)
    })

    it('should render links to pages', () => {
      const { node } = setup({
        location: { query: { query: 'test' } },
        totalHits: Constants.maxSearchResultsPerPage * 3
      })
      expect(node.querySelector("[data-automation-id='search-results-pagination']")
        .getElementsByClassName('pagination')[ 0 ].children.length).toBe(5) // including next and prev
    })
  })
})<commit_msg>Revert "Patron-client: Search.spec pagination test fix"<commit_after>/* eslint-env mocha */
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import {Search} from '../../src/frontend/containers/Search'
import Constants from '../../src/frontend/constants/Constants'
import ReactDOM from 'react-dom'
import {IntlProvider} from 'react-intl'

function setup (propOverrides) {
  const props = {
    searchActions: { search: expect.createSpy() },
    searchResults: [],
    isSearching: false,
    dispatch: () => {},
    searchError: false,
    filters: [],
    location: { query: {} },
    locationQuery: {},
    totalHits: 0,
    totalHitsPublications: 0,
    searchFilterActions: {
      toggleFilter: () => {},
      toggleFilterVisibility: () => {},
      toggleAllFiltersVisibility: () => {},
      toggleCollapseFilter: () => {}
    },
    resourceActions: {
      fetchWorkResource: () => {}
    },
    resources: {},
    items: {},
    windowWidth: 1000,
    ...propOverrides
  }

  const output = TestUtils.renderIntoDocument(
    <IntlProvider locale="en">
      <Search {...props} />
    </IntlProvider>
  )

  return {
    props: props,
    output: output,
    node: ReactDOM.findDOMNode(output)
  }
}

describe('containers', () => {
  describe('Search', () => {
    it('should search on mount when query is provided', () => {
      const { props } = setup({ locationQuery: { query: 'test_query' } })
      expect(props.searchActions.search).toHaveBeenCalled()
    })

    it('should not render pagination when few results', () => {
      const { node } = setup({ location: { query: { query: 'test' } }, totalHits: Constants.maxSearchResultsPerPage })
      expect(node.querySelectorAll("[data-automation-id='search-results-pagination']").length).toBe(0)
    })

    it('should render pagination when many results', () => {
      const { node } = setup({
        location: { query: { query: 'test' } },
        totalHits: Constants.maxSearchResultsPerPage + 1
      })
      expect(node.querySelectorAll("[data-automation-id='search-results-pagination']").length).toBe(1)
    })

    it('should render links to pages', () => {
      const { node } = setup({
        location: { query: { query: 'test' } },
        totalHits: Constants.maxSearchResultsPerPage * 3
      })
      expect(node.querySelector("[data-automation-id='search-results-pagination']")
        .getElementsByClassName('pagination')[ 0 ].children.length).toBe(10) // including next and prev
    })
  })
})
{'fraction_non_alphanumeric': 0.16139303482587064, 'fraction_numerical': 0.004975124378109453, 'mean_word_length': 3.133223684210526, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 33, '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': '2489165', 'n_tokens_mistral': 1508, 'n_tokens_neox': 1502, 'n_words': 313}