<commit_before>import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import FormQuestion from './FormQuestion';
import sinon from 'sinon';

let mockQuestion;
let mockFormState;
let mockSetFormState;
let mockScrollNext;

beforeEach(() => {
  mockQuestion = {
    id: 'sample1',
    text: 'this is question sample1 text',
  };
  mockFormState = {};
  mockSetFormState = () => {};
  mockScrollNext = () => {};
});

describe('coronavirus-screener', () => {
  describe('FormQuestion', () => {
    it('outputs question text', () => {
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
        />,
      );
      expect(wrapper.find('h2').text()).to.equal(mockQuestion.text);
      wrapper.unmount();
    });
    it('sets button class when no option is selected', () => {
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
        />,
      );
      expect(wrapper.find('.usa-button-secondary')).to.have.lengthOf(2);
      expect(wrapper.find('.usa-button')).to.have.lengthOf(0);
      wrapper.unmount();
    });
    it('sets button class when some option is selected', () => {
      mockFormState = {
        sample1: 'yes',
      };
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
        />,
      );
      expect(wrapper.find('.usa-button')).to.have.lengthOf(1);
      expect(wrapper.find('.usa-button-secondary')).to.have.lengthOf(1);
      wrapper.unmount();
    });

    it('sets form state when clicked', () => {
      const setFormStateSpy = sinon.spy();
      const mockValue = 'yes';
      const mockEvent = { target: { value: mockValue } };
      const expectedFormState = { [mockQuestion.id]: mockValue };

      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={setFormStateSpy}
          scrollNext={mockScrollNext}
        />,
      );

      wrapper
        .find('button')
        .at(0)
        .simulate('click', mockEvent);

      expect(setFormStateSpy.called).to.be.true;
      expect(setFormStateSpy.args[0]).to.deep.equal([expectedFormState]);<commit_msg>Form question unit test fix (#12826)<commit_after>import React from 'react';
import { expect } from 'chai';
import { shallow } from 'enzyme';
import FormQuestion from './FormQuestion';
import sinon from 'sinon';

let mockQuestion;
let mockFormState;
let mockSetFormState;
let mockScrollNext;
let mockSetResultSubmittedState;

beforeEach(() => {
  mockQuestion = {
    id: 'sample1',
    text: 'this is question sample1 text',
  };
  mockFormState = {};
  mockSetFormState = () => {};
  mockScrollNext = () => {};
  mockSetResultSubmittedState = () => {};
});

describe('coronavirus-screener', () => {
  describe('FormQuestion', () => {
    it('outputs question text', () => {
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
          setResultSubmittedState={mockSetResultSubmittedState}
        />,
      );
      expect(wrapper.find('h2').text()).to.equal(mockQuestion.text);
      wrapper.unmount();
    });
    it('sets button class when no option is selected', () => {
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
          setResultSubmittedState={mockSetResultSubmittedState}
        />,
      );
      expect(wrapper.find('.usa-button-secondary')).to.have.lengthOf(2);
      expect(wrapper.find('.usa-button')).to.have.lengthOf(0);
      wrapper.unmount();
    });
    it('sets button class when some option is selected', () => {
      mockFormState = {
        sample1: 'yes',
      };
      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={mockSetFormState}
          scrollNext={mockScrollNext}
          setResultSubmittedState={mockSetResultSubmittedState}
        />,
      );
      expect(wrapper.find('.usa-button')).to.have.lengthOf(1);
      expect(wrapper.find('.usa-button-secondary')).to.have.lengthOf(1);
      wrapper.unmount();
    });

    it('sets form state when clicked', () => {
      const setFormStateSpy = sinon.spy();
      const mockValue = 'yes';
      const mockEvent = { target: { value: mockValue } };
      const expectedFormState = { [mockQuestion.id]: mockValue };

      const wrapper = shallow(
        <FormQuestion
          question={mockQuestion}
          formState={mockFormState}
          setFormState={setFormStateSpy}
          scrollNext={mockScrollNext}
          setResultSubmittedState={mockSetResultSubmittedState}
        />,
      );

      wrapper
        .find('button')
        .at(0)
        .simulate('click', mockEvent);

      expect(setFormStateSpy.called).to.be.true;
      expect(setFormStateSpy.args[0]).to.deep.equal([expectedFormState]);
{'fraction_non_alphanumeric': 0.13988312636961286, 'fraction_numerical': 0.004565376186997808, 'mean_word_length': 2.6931894807821983, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 30, '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': '1921053', 'n_tokens_mistral': 1560, 'n_tokens_neox': 1538, 'n_words': 275}