<commit_before>/* eslint-env jest */

import React from 'react'
import {
  shallow
} from 'enzyme'
import toJson from 'enzyme-to-json'
import { isSearchPageEnabled } from 'js/utils/feature-flags'
import {
  goTo,
  dashboardURL
} from 'js/navigation/navigation'

jest.mock('js/utils/feature-flags')
jest.mock('js/navigation/navigation')

const getMockProps = () => ({
  user: {
    id: 'some-user-id-here'
  },
  app: {}
})

beforeEach(() => {
  isSearchPageEnabled.mockReturnValue(true)
})

afterEach(() => {
  jest.clearAllMocks()
})

describe('Search page component', () => {
  it('renders without error', () => {
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    )
  })

  it('renders no DOM elements when the search page feature is not enabled', () => {
    isSearchPageEnabled.mockReturnValue(false)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    const wrapper = shallow(
      <SearchPageComponent {...mockProps} />
    )
    expect(toJson(wrapper)).toEqual('')
  })

  it('redirects to the dashboard when the search page feature is not enabled', () => {
    isSearchPageEnabled.mockReturnValue(false)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    )
    expect(goTo).toHaveBeenCalledWith(dashboardURL)
  })

  it('renders DOM elements when the search page feature is enabled', () => {
    isSearchPageEnabled.mockReturnValue(true)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    const wrapper = shallow(
      <SearchPageComponent {...mockProps} />
    )
    expect(toJson(wrapper)).not.toEqual('')
  })

  it('does not redirect to the dashboard when the search page feature is enabled', () => {
    isSearchPageEnabled.mockReturnValue(true)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    )
    expect(goTo).not.toHaveBeenCalled()
  })
})<commit_msg>Fix tests when using withStyles HOC<commit_after>/* eslint-env jest */

import React from 'react'
import {
  shallow
} from 'enzyme'
import toJson from 'enzyme-to-json'
import { isSearchPageEnabled } from 'js/utils/feature-flags'
import {
  goTo,
  dashboardURL
} from 'js/navigation/navigation'

jest.mock('js/utils/feature-flags')
jest.mock('js/navigation/navigation')

const getMockProps = () => ({
  user: {
    id: 'some-user-id-here'
  },
  app: {}
})

beforeEach(() => {
  isSearchPageEnabled.mockReturnValue(true)
})

afterEach(() => {
  jest.clearAllMocks()
})

describe('Search page component', () => {
  it('renders without error', () => {
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    ).dive()
  })

  it('renders no DOM elements when the search page feature is not enabled', () => {
    isSearchPageEnabled.mockReturnValue(false)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    const wrapper = shallow(
      <SearchPageComponent {...mockProps} />
    ).dive()
    expect(toJson(wrapper)).toEqual('')
  })

  it('redirects to the dashboard when the search page feature is not enabled', () => {
    isSearchPageEnabled.mockReturnValue(false)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    ).dive()
    expect(goTo).toHaveBeenCalledWith(dashboardURL)
  })

  it('renders DOM elements when the search page feature is enabled', () => {
    isSearchPageEnabled.mockReturnValue(true)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    const wrapper = shallow(
      <SearchPageComponent {...mockProps} />
    ).dive()
    expect(toJson(wrapper)).not.toEqual('')
  })

  it('does not redirect to the dashboard when the search page feature is enabled', () => {
    isSearchPageEnabled.mockReturnValue(true)
    const SearchPageComponent = require('js/components/Search/SearchPageComponent').default
    const mockProps = getMockProps()
    shallow(
      <SearchPageComponent {...mockProps} />
    ).dive()
    expect(goTo).not.toHaveBeenCalled()
  })
})
{'fraction_non_alphanumeric': 0.13345904043578463, 'fraction_numerical': 0.0, 'mean_word_length': 3.9574247144340604, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 31, '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': '1373148', 'n_tokens_mistral': 1389, 'n_tokens_neox': 1385, 'n_words': 302}