<commit_before>import { mount } from "enzyme"
import React from "react"

import { Button } from "@artsy/palette"
import { UntouchedOrder } from "Apps/__test__/Fixtures/Order"
import { TermsOfServiceCheckbox } from "Apps/Order/Components/TermsOfServiceCheckbox"
import { commitMutation, RelayProp } from "react-relay"
import { StepSummaryItem } from "Styleguide/Components/StepSummaryItem"
import { Provider } from "unstated"
import {
  ErrorModal,
  ModalButton,
} from "../../../../Components/Modal/ErrorModal"
import { OrderWithShippingDetails } from "../../../__test__/Fixtures/Order"
import {
  creatingCreditCardSuccess,
  settingOrderPaymentFailed,
} from "../__fixtures__/MutationResults"
import { ContinueButton } from "../Payment"
import { ReviewRoute } from "../Review"

jest.mock("react-relay", () => ({
  commitMutation: jest.fn(),
  createFragmentContainer: component => component,
}))

const pushMock = jest.fn()
const defaultProps = {
  order: { ...UntouchedOrder, id: "1234" },
  router: {
    push: pushMock,
  },
  relay: {
    environment: {},
  },
}

describe("Review", () => {
  const getWrapper = props => {
    return mount(
      <Provider>
        <ReviewRoute {...props} />
      </Provider>
    )
  }

  it("enables the button and routes to the payoff page", () => {
    const component = getWrapper(defaultProps)
    ;(commitMutation as jest.Mock<any>).mockImplementationOnce(
      (_, { onCompleted }) =>
        onCompleted({ submitOrder: { orderOrError: { order: {} } } })
    )
    component.find(Button).simulate("click")
    expect(commitMutation).toHaveBeenCalledTimes(1)
    expect(pushMock).toBeCalledWith("/order2/1234/status")
  })

  it("takes the user back to the /shipping view", () => {
    const component = getWrapper(defaultProps)
    component
      .find(StepSummaryItem)
      .first()
      .find("a")
      .simulate("click")
    expect(pushMock).toBeCalledWith("/order2/1234/shipping")
  })

  it("takes the user back to the /payment view", () => {
    const component = getWrapper(defaultProps)
    component
      .find(StepSummaryItem)
      .last()
      .find("a")
      .simulate("click")
    expect(pushMock).toBeCalledWith("/order2/1234/shipping")
  })

  it("shows an error modal when there is an error in submitOrderPayload", () => {
    console.error = jest.fn() // Silences component logging.

    const component = getWrapper(defaultProps)

    expect(component.find(ErrorModal).props().show).toBe(false)
    ;(commitMutation as jest.Mock<any>).mockImplementationOnce(
      (_, { onCompleted }) =>
        onCompleted({
          submitOrder: {
            orderOrError: {
              __typename: "OrderWithMutationFailure",
              error: {
                type: "validation",
                code: "credit_card_not_found",
                data: '{"credit_card_id":"<KEY>"}',
              },
            },
          },
        })
    )

    component.find(Button).simulate("click")

    expect(component.find(ErrorModal).props().show).toBe(true)<commit_msg>Fix tests<commit_after>import { mount } from "enzyme"
import React from "react"

import { Button } from "@artsy/palette"
import { UntouchedOrder } from "Apps/__test__/Fixtures/Order"
import { commitMutation } from "react-relay"
import { StepSummaryItem } from "Styleguide/Components/StepSummaryItem"
import { Provider } from "unstated"
import {
  ErrorModal,
  ModalButton,
} from "../../../../Components/Modal/ErrorModal"
import {
  creatingCreditCardSuccess,
  settingOrderPaymentFailed,
} from "../__fixtures__/MutationResults"
import { ReviewRoute } from "../Review"

jest.mock("react-relay", () => ({
  commitMutation: jest.fn(),
  createFragmentContainer: component => component,
}))

const pushMock = jest.fn()
const defaultProps = {
  order: { ...UntouchedOrder, id: "1234" },
  router: {
    push: pushMock,
  },
  relay: {
    environment: {},
  },
}

describe("Review", () => {
  const getWrapper = props => {
    return mount(
      <Provider>
        <ReviewRoute {...props} />
      </Provider>
    )
  }

  it("enables the button and routes to the payoff page", () => {
    const component = getWrapper(defaultProps)
    ;(commitMutation as jest.Mock<any>).mockImplementationOnce(
      (_, { onCompleted }) =>
        onCompleted({ ecommerceSubmitOrder: { orderOrError: { order: {} } } })
    )
    component.find(Button).simulate("click")
    expect(commitMutation).toHaveBeenCalledTimes(1)
    expect(pushMock).toBeCalledWith("/order2/1234/status")
  })

  it("takes the user back to the /shipping view", () => {
    const component = getWrapper(defaultProps)
    component
      .find(StepSummaryItem)
      .first()
      .find("a")
      .simulate("click")
    expect(pushMock).toBeCalledWith("/order2/1234/shipping")
  })

  it("takes the user back to the /payment view", () => {
    const component = getWrapper(defaultProps)
    component
      .find(StepSummaryItem)
      .last()
      .find("a")
      .simulate("click")
    expect(pushMock).toBeCalledWith("/order2/1234/shipping")
  })

  it("shows an error modal when there is an error in submitOrderPayload", () => {
    console.error = jest.fn() // Silences component logging.

    const component = getWrapper(defaultProps)

    expect(component.find(ErrorModal).props().show).toBe(false)
    ;(commitMutation as jest.Mock<any>).mockImplementationOnce(
      (_, { onCompleted }) =>
        onCompleted({
          ecommerceSubmitOrder: {
            orderOrError: {
              __typename: "OrderWithMutationFailure",
              error: {
                type: "validation",
                code: "credit_card_not_found",
                data: '{"credit_card_id":"<KEY>"}',
              },
            },
          },
        })
    )

    component.find(Button).simulate("click")

    expect(component.find(ErrorModal).props().show).toBe(true)
{'fraction_non_alphanumeric': 0.14692347025737174, 'fraction_numerical': 0.006817794443497529, 'mean_word_length': 2.975609756097561, 'pattern_counts': {'":': 2, '<': 15, '<?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': '1208280', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1737, 'n_words': 347}