<commit_before>import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import Form from './form';
import Textbox from './../textbox';
import Portal from './../portal';
import Validation from './../../utils/validations/presence';
import ImmutableHelper from './../../utils/helpers/immutable';
import Dialog from './../dialog';
import I18n from "i18n-js";
import CancelButton from './cancel-button';
import SaveButton from './save-button';
import FormSummary from './form-summary';
import Button from './../button';
import MultiActionButton from './../multi-action-button';
import ElementResize from './../../utils/helpers/element-resize';

import { mount, shallow } from 'enzyme';
import { elementsTagTest, rootTagTest } from '../../utils/helpers/tags/tags-specs';

/* global jest */

describe('Form', () => {
  let instance, wrapper;

  beforeEach(() => {
    instance = TestUtils.renderIntoDocument(
      <Form />
    );
  });

  describe('initialize', () => {
    it('sets the errorCount to 0', () => {
      expect(instance.state.errorCount).toEqual(0);
    });
  });

  describe('componentWillReceiveProps', () => {
    describe('when stickyFooter is enabled', () => {
      it('adds the listeners', () => {
        wrapper = mount(<Form />);
        
        spyOn(wrapper.instance(), 'addStickyFooterListeners');
        wrapper.setProps({ stickyFooter: true });
        expect(wrapper.instance().addStickyFooterListeners).toHaveBeenCalled();
      });
    });

    describe('when stickyFooter is disabled', () => {
      it('adds the listeners', () => {
        // TODO - 1007 - shallow seems to fail when creating Form
        // 'offsetHeight' of undefined
        wrapper = mount(<Form stickyFooter />);
        spyOn(wrapper.instance(), 'removeStickyFooterListeners');
        wrapper.setProps({ stickyFooter: false });
        expect(wrapper.instance().removeStickyFooterListeners).toHaveBeenCalled();
      });
    });
  });

  describe('componentDidMount', () => {
    it('does not validate by default', () => {
      spyOn(instance, 'validate');
      instance.componentDidMount();
      expect(instance.validate).not.toHaveBeenCalled();
    });

    describe('when validateOnMount is set to true', () => {
      it('validates the form', () => {
        instance = TestUtils.renderIntoDocument(<Form validateOnMount={ true } />);
        spyOn(instance, 'validate');
        instance.componentDidMount();
        expect(instance.validate).toHaveBeenCalled();
      });
    });

    it('adds sticky footer listeners is enabled', () => {
      // TODO - 1007 - shallow seems to fail when creating Form
      // 'offsetHeight' of undefined
      wrapper = mount(<Form stickyFooter />);
      spyOn(wrapper.instance(), 'addStickyFooterListeners');
      wrapper.instance().componentDidMount();
      expect(wrapper.instance().addStickyFooterListeners).toHaveBeenCalled();
    });
  });

  describe('componentWillUnmount', () => {
    it('does not remove sticky footer listeners if not enabled', () => {
      wrapper = shallow(<Form />);
      spyOn(wrapper.instance(), 'removeStickyFooterListeners');
      wrapper.instance().componentWillUnmount();
      expect(wrapper.instance().removeStickyFooterListeners).not.toHaveBeenCalled();
    });

    it('removes sticky footer listeners if enabled', () => {
      // TODO - 1007 - shallow seems to fail when creating Form
      // 'offsetHeight' of undefined
      wrapper = mount(<Form stickyFooter />);
      spyOn(wrapper.instance(), 'removeStickyFooterListeners');
      wrapper.instance().componentWillUnmount();
      expect(wrapper.instance().removeStickyFooterListeners).toHaveBeenCalled();
    });
  });

  describe('addStickyFooterListeners', () => {
    beforeEach(() => {
      wrapper = mount(<Form />);
      instance = wrapper.instance();
      instance._form = {};
      spyOn(instance, 'checkStickyFooter');
      spyOn(ElementResize, 'addListener');
      spyOn(instance._window, 'addEventListener');
    });

    it('calls checkStickyFooter', () => {
      instance.addStickyFooterListeners();
      expect(instance.checkStickyFooter).toHaveBeenCalled();
    });
<commit_msg>Comments removed from passing tests<commit_after>import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-dom/test-utils';
import Form from './form';
import Textbox from './../textbox';
import Portal from './../portal';
import Validation from './../../utils/validations/presence';
import ImmutableHelper from './../../utils/helpers/immutable';
import Dialog from './../dialog';
import I18n from "i18n-js";
import CancelButton from './cancel-button';
import SaveButton from './save-button';
import FormSummary from './form-summary';
import Button from './../button';
import MultiActionButton from './../multi-action-button';
import ElementResize from './../../utils/helpers/element-resize';

import { mount, shallow } from 'enzyme';
import { elementsTagTest, rootTagTest } from '../../utils/helpers/tags/tags-specs';

/* global jest */

describe('Form', () => {
  let instance, wrapper;

  beforeEach(() => {
    instance = TestUtils.renderIntoDocument(
      <Form />
    );
  });

  describe('initialize', () => {
    it('sets the errorCount to 0', () => {
      expect(instance.state.errorCount).toEqual(0);
    });
  });

  describe('componentWillReceiveProps', () => {
    describe('when stickyFooter is enabled', () => {
      it('adds the listeners', () => {
        wrapper = mount(<Form />);
        
        spyOn(wrapper.instance(), 'addStickyFooterListeners');
        wrapper.setProps({ stickyFooter: true });
        expect(wrapper.instance().addStickyFooterListeners).toHaveBeenCalled();
      });
    });

    describe('when stickyFooter is disabled', () => {
      it('adds the listeners', () => {
        wrapper = mount(<Form stickyFooter />);
        spyOn(wrapper.instance(), 'removeStickyFooterListeners');
        wrapper.setProps({ stickyFooter: false });
        expect(wrapper.instance().removeStickyFooterListeners).toHaveBeenCalled();
      });
    });
  });

  describe('componentDidMount', () => {
    it('does not validate by default', () => {
      spyOn(instance, 'validate');
      instance.componentDidMount();
      expect(instance.validate).not.toHaveBeenCalled();
    });

    describe('when validateOnMount is set to true', () => {
      it('validates the form', () => {
        instance = TestUtils.renderIntoDocument(<Form validateOnMount={ true } />);
        spyOn(instance, 'validate');
        instance.componentDidMount();
        expect(instance.validate).toHaveBeenCalled();
      });
    });

    it('adds sticky footer listeners is enabled', () => {
      wrapper = mount(<Form stickyFooter />);
      spyOn(wrapper.instance(), 'addStickyFooterListeners');
      wrapper.instance().componentDidMount();
      expect(wrapper.instance().addStickyFooterListeners).toHaveBeenCalled();
    });
  });

  describe('componentWillUnmount', () => {
    it('does not remove sticky footer listeners if not enabled', () => {
      wrapper = shallow(<Form />);
      spyOn(wrapper.instance(), 'removeStickyFooterListeners');
      wrapper.instance().componentWillUnmount();
      expect(wrapper.instance().removeStickyFooterListeners).not.toHaveBeenCalled();
    });

    it('removes sticky footer listeners if enabled', () => {
      wrapper = mount(<Form stickyFooter />);
      spyOn(wrapper.instance(), 'removeStickyFooterListeners');
      wrapper.instance().componentWillUnmount();
      expect(wrapper.instance().removeStickyFooterListeners).toHaveBeenCalled();
    });
  });

  describe('addStickyFooterListeners', () => {
    beforeEach(() => {
      wrapper = mount(<Form />);
      instance = wrapper.instance();
      instance._form = {};
      spyOn(instance, 'checkStickyFooter');
      spyOn(ElementResize, 'addListener');
      spyOn(instance._window, 'addEventListener');
    });

    it('calls checkStickyFooter', () => {
      instance.addStickyFooterListeners();
      expect(instance.checkStickyFooter).toHaveBeenCalled();
    });

{'fraction_non_alphanumeric': 0.16443076923076924, 'fraction_numerical': 0.0029538461538461537, 'mean_word_length': 3.3805929919137467, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 59, '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': '1859604', 'n_tokens_mistral': 2249, 'n_tokens_neox': 2242, 'n_words': 458}