<commit_before>/* eslint-env jest */

import React from 'react'
import { mount, shallow } from 'enzyme'
import { QueryRenderer } from 'react-relay'
import WidgetsSettingsView from 'js/components/Settings/Widgets/WidgetsSettingsView'
import WidgetsSettings from 'js/components/Settings/Widgets/WidgetsSettingsContainer'
import ErrorMessage from 'js/components/General/ErrorMessage'
import logger from 'js/utils/logger'

jest.mock('react-relay')
jest.mock('js/components/General/ErrorMessage')
jest.mock('js/components/General/withUser')
jest.mock('js/utils/logger')
jest.mock('js/components/Settings/Widgets/WidgetsSettingsContainer')

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

const getMockProps = () => ({
  showError: jest.fn(),
})

describe('WidgetsSettingsView', () => {
  it('renders without error', () => {
    const mockProps = getMockProps()
    shallow(<WidgetsSettingsView {...mockProps} />).dive()
  })

  it('sets a root style of 100% width and height', () => {
    const mockProps = getMockProps()
    shallow(<WidgetsSettingsView {...mockProps} />).dive()
  })

  it('includes a QueryRenderer', () => {
    const mockProps = getMockProps()
    const wrapper = shallow(<WidgetsSettingsView {...mockProps} />).dive()
    expect(wrapper.find(QueryRenderer).exists()).toBe(true)
  })

  it('passes the expected variables to the QueryRenderer', () => {
    const mockProps = getMockProps()
    const wrapper = mount(<WidgetsSettingsView {...mockProps} />)
    expect(wrapper.find(QueryRenderer).prop('variables')).toEqual({
      userId: 'abc123xyz456', // default value in `withUser` mock
    })
  })
<commit_msg>Add a test for withUser<commit_after>/* eslint-env jest */

import React from 'react'
import { mount, shallow } from 'enzyme'
import { QueryRenderer } from 'react-relay'
import WidgetsSettingsView from 'js/components/Settings/Widgets/WidgetsSettingsView'
import WidgetsSettings from 'js/components/Settings/Widgets/WidgetsSettingsContainer'
import ErrorMessage from 'js/components/General/ErrorMessage'
import logger from 'js/utils/logger'

jest.mock('react-relay')
jest.mock('js/components/General/ErrorMessage')
jest.mock('js/components/General/withUser')
jest.mock('js/utils/logger')
jest.mock('js/components/Settings/Widgets/WidgetsSettingsContainer')

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

const getMockProps = () => ({
  showError: jest.fn(),
})

describe('withUser HOC in WidgetsSettingsView', () => {
  beforeEach(() => {
    jest.resetModules()
  })

  it('is called with the expected options', () => {
    const withUser = require('js/components/General/withUser').default

    /* eslint-disable-next-line no-unused-expressions */
    require('js/components/Settings/Widgets/WidgetsSettingsView').default
    expect(withUser).toHaveBeenCalledWith()
  })

  // TODO: test it actually wraps the WidgetsSettingsView component
})

describe('WidgetsSettingsView', () => {
  it('renders without error', () => {
    const mockProps = getMockProps()
    shallow(<WidgetsSettingsView {...mockProps} />).dive()
  })

  it('sets a root style of 100% width and height', () => {
    const mockProps = getMockProps()
    shallow(<WidgetsSettingsView {...mockProps} />).dive()
  })

  it('includes a QueryRenderer', () => {
    const mockProps = getMockProps()
    const wrapper = shallow(<WidgetsSettingsView {...mockProps} />).dive()
    expect(wrapper.find(QueryRenderer).exists()).toBe(true)
  })

  it('passes the expected variables to the QueryRenderer', () => {
    const mockProps = getMockProps()
    const wrapper = mount(<WidgetsSettingsView {...mockProps} />)
    expect(wrapper.find(QueryRenderer).prop('variables')).toEqual({
      userId: 'abc123xyz456', // default value in `withUser` mock
    })
  })

{'fraction_non_alphanumeric': 0.15429791777896423, 'fraction_numerical': 0.004805125467164976, 'mean_word_length': 4.584202682563339, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 28, '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': '6543798', 'n_tokens_mistral': 1149, 'n_tokens_neox': 1118, 'n_words': 235}