<commit_before>import $ from 'jquery';
import React from 'react';
import renderer from 'react-test-renderer';
import {mount} from 'enzyme';
import ReactTestUtils from 'react-addons-test-utils';
import SwipeToDelete from '../src/js/main';
import Device from '../src/js/utils/device';


describe('A SwipeToDelete', () => {
  const device = Device.factory(false);

  it('should renders correctly', () => {
    const componentDidMountOrig = SwipeToDelete.prototype.componentDidMount;
    // In componentDidMount requires a DOM
    SwipeToDelete.prototype.componentDidMount = () => {};

    const component = renderer.create(
      <SwipeToDelete><div>Content ...</div></SwipeToDelete>
    );

    let tree = component.toJSON();
    expect(tree).toMatchSnapshot();

    SwipeToDelete.prototype.componentDidMount = componentDidMountOrig;
  });

  it('should add handlers of lifecycle swiping on "componentDidMount"', () => {

  });

  it('should move a content component', () => {
    SwipeToDelete.prototype.moveAt = jest.fn();

    const component = ReactTestUtils.renderIntoDocument(<SwipeToDelete><div className="content">Content ...</div></SwipeToDelete>);
    const content = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'content');

    simulateDOMMouseEvent(device.getStartEventName(), content);
    simulateDOMMouseEvent(device.getInteractEventName(), document);

    expect(SwipeToDelete.prototype.moveAt).toBeCalled();
  });

  describe('A content component is moved', () => {
    describe('It\'s moved more "deleteSwipe" props', () => {
      it('should add a "js-transition-delete-right" class, when content component will be swiped on right', () => {

      });

      it('should add a "js-transition-delete-left" class, when content component will be swiped on left', () => {

      });

      it('should call a "onDelete()" method', () => {

      });

      describe('A "onDelete()"', () => {
        it('should call a "onDelete()" props', () => {

        });

        it('should delete component', () => {

        });
      });
    });

    describe('It\'s moved less "deleteSwipe" props', () => {
      it('should add "js-transition-cancel" class', () => {

      });

      it('should call a "onCancel()" method', () => {

      });

      describe('A "onCancel()"', () => {
        it('should call a "onCancel()" props', () => {

        });

        it('should remove a "js-transition-cancel" class', () => {

        });
      });

      it('should again add handlers of lifecycle swiping', () => {

      });
    });
  });

  describe('A content component isn\'t moved', () => {
    it('should not call a "stopInteract()" method', () => {

    });

    it('should again add handlers of lifecycle swiping', () => {

    });
  });
});


// Simulate a mouse events; can't use TestUtils here because it uses react's event system only,
// but <SwipeToDelete> attaches event listeners directly to the document.
const simulateDOMMouseEvent = (eventName, node, {pageX = 0, pageY = 0} = {}) => {
  const event = new MouseEvent(eventName, {
    pageX,
    pageY,
    bubbles: true,<commit_msg>Tests: return mocking functions in "afterEach"<commit_after>import $ from 'jquery';
import React from 'react';
import renderer from 'react-test-renderer';
import {mount} from 'enzyme';
import ReactTestUtils from 'react-addons-test-utils';
import SwipeToDelete from '../src/js/main';
import Device from '../src/js/utils/device';


describe('A SwipeToDelete', () => {
  const device = Device.factory(false);
  const componentDidMountOrig = SwipeToDelete.prototype.componentDidMount;;
  const addHandlersOrig = SwipeToDelete.prototype.addHandlers;
  const moveAtOrig = SwipeToDelete.prototype.moveAt;

  afterEach(() => {
    // Return original methods after mock
    SwipeToDelete.prototype.componentDidMount = componentDidMountOrig;
    SwipeToDelete.prototype.addHandlers = addHandlersOrig;
    SwipeToDelete.prototype.moveAt = moveAtOrig;
  });

  it('should renders correctly', () => {
    // In componentDidMount requires a DOM
    SwipeToDelete.prototype.componentDidMount = () => {};

    const component = renderer.create(<SwipeToDelete><div>Content ...</div></SwipeToDelete>);
    const tree = component.toJSON();

    expect(tree).toMatchSnapshot();
  });

  it('should add handlers of lifecycle swiping on "componentDidMount"', () => {
    SwipeToDelete.prototype.addHandlers = jest.fn();
    const component = ReactTestUtils.renderIntoDocument(<SwipeToDelete><div className="content">Content ...</div></SwipeToDelete>);
    expect(SwipeToDelete.prototype.addHandlers).toBeCalled();
  });

  it('should move a content component', () => {
    SwipeToDelete.prototype.moveAt = jest.fn();

    const component = ReactTestUtils.renderIntoDocument(<SwipeToDelete><div className="content">Content ...</div></SwipeToDelete>);
    const content = ReactTestUtils.findRenderedDOMComponentWithClass(component, 'content');

    simulateDOMMouseEvent(device.getStartEventName(), content);
    simulateDOMMouseEvent(device.getInteractEventName(), document);

    expect(SwipeToDelete.prototype.moveAt).toBeCalled();
  });

  describe('A content component is moved', () => {
    describe('It\'s moved more "deleteSwipe" props', () => {
      it('should add a "js-transition-delete-right" class, when content component will be swiped on right', () => {

      });

      it('should add a "js-transition-delete-left" class, when content component will be swiped on left', () => {

      });

      it('should call a "onDelete()" method', () => {

      });

      describe('A "onDelete()"', () => {
        it('should call a "onDelete()" props', () => {

        });

        it('should delete component', () => {

        });
      });
    });

    describe('It\'s moved less "deleteSwipe" props', () => {
      it('should add "js-transition-cancel" class', () => {

      });

      it('should call a "onCancel()" method', () => {

      });

      describe('A "onCancel()"', () => {
        it('should call a "onCancel()" props', () => {

        });

        it('should remove a "js-transition-cancel" class', () => {

        });
      });

      it('should again add handlers of lifecycle swiping', () => {

      });
    });
  });

  describe('A content component isn\'t moved', () => {
    it('should not call a "stopInteract()" method', () => {

    });

    it('should again add handlers of lifecycle swiping', () => {

    });
  });
});

// Simulate a mouse events; can't use TestUtils here because it uses react's event system only,
// but <SwipeToDelete> attaches event listeners directly to the document.
const simulateDOMMouseEvent = (eventName, node, {pageX = 0, pageY = 0} = {}) => {
  const event = new MouseEvent(eventName, {
    pageX,
    pageY,
    bubbles: true,
{'fraction_non_alphanumeric': 0.16114790286975716, 'fraction_numerical': 0.0005886681383370125, 'mean_word_length': 3.401554404145078, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 74, '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': '2846698', 'n_tokens_mistral': 2047, 'n_tokens_neox': 1944, 'n_words': 479}