<commit_before>import * as React from "react";

import Editable, { EditableChildProps, EditableStatus } from "./editable";

import { shallow } from "enzyme";
import MockComponent from "./__mocks__/mock-component";

const MockComponentWrapper = <TValue, TCommitType>(
  editableProps: EditableChildProps<TValue, TCommitType>
) => <MockComponent {...editableProps} />;

const PROPS_VALUE = "propsValue";
const STATE_VALUE = "stateValue";
const NEW_VALUE = "newValue";
const COMMIT_PARAM = "commit";

const EDITING_STATE = {
  status: EditableStatus.EDITING,
  value: STATE_VALUE
};

function createComponentWithStateAndTriggerEvent({
  initialProps = {},
  initialState = {},
  event,
  eventArgs = []
}: {
  initialProps?: object;
  initialState?: object;
  event: string;
  eventArgs?: any[];
}) {
  const props = {
    value: PROPS_VALUE,
    ...initialProps
  };
  const wrapper = shallow(
    <Editable {...props}>{MockComponentWrapper}</Editable>
  );
  const maybePromise = wrapper
    .setState(initialState)
    .find(MockComponent)
    .props()
    [event](...eventArgs);

  if (maybePromise && maybePromise.then) {
    maybePromise.then((result: any) => {
      wrapper.update();
      return result;
    });
  }
  wrapper.update();

  return { wrapper, promise: maybePromise };
}

describe("Editable", () => {
  describe("smoke tests", () => {
    test("shouldn't fatal", () => {
      expect(() => <Editable value={undefined} />).not.toThrow();
    });

    test("should render MockComponent", () => {
      expect(
        shallow(<Editable value={undefined} children={MockComponentWrapper} />)
      ).toMatchSnapshot();
    });
  });

  describe(`when status is PRESENTING`, () => {
    test(`should transition to EDITING when onStart is called`, () => {
      const { wrapper } = createComponentWithStateAndTriggerEvent({
        event: "onStart"
      });

      expect(wrapper.find(MockComponent).props()).toMatchObject({
        status: EditableStatus.EDITING,
        value: PROPS_VALUE
      });
    });<commit_msg>update smoke test test render<commit_after>import * as React from "react";

import Editable, { EditableChildProps, EditableStatus } from "./editable";

import { shallow } from "enzyme";
import MockComponent from "./__mocks__/mock-component";

const MockComponentWrapper = <TValue, TCommitType>(
  editableProps: EditableChildProps<TValue, TCommitType>
) => <MockComponent {...editableProps} />;

const PROPS_VALUE = "propsValue";
const STATE_VALUE = "stateValue";
const NEW_VALUE = "newValue";
const COMMIT_PARAM = "commit";

const EDITING_STATE = {
  status: EditableStatus.EDITING,
  value: STATE_VALUE
};

function createComponentWithStateAndTriggerEvent({
  initialProps = {},
  initialState = {},
  event,
  eventArgs = []
}: {
  initialProps?: object;
  initialState?: object;
  event: string;
  eventArgs?: any[];
}) {
  const props = {
    value: PROPS_VALUE,
    ...initialProps
  };
  const wrapper = shallow(
    <Editable {...props}>{MockComponentWrapper}</Editable>
  );
  const maybePromise = wrapper
    .setState(initialState)
    .find(MockComponent)
    .props()
    [event](...eventArgs);

  if (maybePromise && maybePromise.then) {
    maybePromise.then((result: any) => {
      wrapper.update();
      return result;
    });
  }
  wrapper.update();

  return { wrapper, promise: maybePromise };
}

describe("Editable", () => {
  describe("smoke tests", () => {
    test("shouldn't fatal", () => {
      expect(() => shallow(<Editable value={undefined} />)).not.toThrow();
    });

    test("should render MockComponent", () => {
      expect(
        shallow(<Editable value={undefined} children={MockComponentWrapper} />)
      ).toMatchSnapshot();
    });
  });

  describe(`when status is PRESENTING`, () => {
    test(`should transition to EDITING when onStart is called`, () => {
      const { wrapper } = createComponentWithStateAndTriggerEvent({
        event: "onStart"
      });

      expect(wrapper.find(MockComponent).props()).toMatchObject({
        status: EditableStatus.EDITING,
        value: PROPS_VALUE
      });
    });
{'fraction_non_alphanumeric': 0.15286935286935288, 'fraction_numerical': 0.0, 'mean_word_length': 3.638731596828992, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 35, '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': '7111318', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1209, 'n_words': 262}