<commit_before>/* eslint-env mocha */
/* global findElementByDataAutomationId */
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import { Reservation } from '../../src/frontend/containers/Reservation'
import ReactDOM from 'react-dom'
import { IntlProvider } from 'react-intl'

function setup (propOverrides) {
  const props = {
    isLoggedIn: true,
    isRequestingReservation: false,
    reservationActions: { reservePublication: expect.createSpy() },
    modalActions: {},
    ...propOverrides
  }

  const output = TestUtils.renderIntoDocument(
    <IntlProvider locale='en'>
      <Reservation {...props} />
    </IntlProvider>
  )

  return {
    props: props,
    output: output,
    node: ReactDOM.findDOMNode(output)
  }
}

describe('containers', () => {
  describe('Reservation', () => {
    it('should display success dialog', () => {
      const { node } = setup({ isSuccess: true, message: 'test' })
      expect(node.getAttribute('data-automation-id')).toEqual('reservation_success_modal')
    })

    it('should display error dialog', () => {
      const { node } = setup({ isError: true, message: 'test' })
      expect(node.getAttribute('data-automation-id')).toEqual('reservation_error_modal')
    })

    it('should pass record ID and selected branch when clicking to reserve publication', () => {
      const { output, props } = setup({ recordId: '123' })
      const reserveButton = findElementByDataAutomationId(output, 'reserve_button')
      TestUtils.Simulate.click(reserveButton)
      expect(props.reservationActions.reservePublication).toHaveBeenCalled()
      expect(props.reservationActions.reservePublication.calls[ 0 ].arguments).toEqual([ '123', 'dfb' ]) // dfb is currently the first selectable branch
    })
  })
})<commit_msg>patron-client: Rename test for clarity<commit_after>/* eslint-env mocha */
/* global findElementByDataAutomationId */
import expect from 'expect'
import React from 'react'
import TestUtils from 'react-addons-test-utils'
import { Reservation } from '../../src/frontend/containers/Reservation'
import ReactDOM from 'react-dom'
import { IntlProvider } from 'react-intl'

function setup (propOverrides) {
  const props = {
    isLoggedIn: true,
    isRequestingReservation: false,
    reservationActions: { reservePublication: expect.createSpy() },
    modalActions: {},
    ...propOverrides
  }

  const output = TestUtils.renderIntoDocument(
    <IntlProvider locale='en'>
      <Reservation {...props} />
    </IntlProvider>
  )

  return {
    props: props,
    output: output,
    node: ReactDOM.findDOMNode(output)
  }
}

describe('containers', () => {
  describe('Reservation', () => {
    it('should display success dialog', () => {
      const { node } = setup({ isSuccess: true, message: 'test' })
      expect(node.getAttribute('data-automation-id')).toEqual('reservation_success_modal')
    })

    it('should display error dialog', () => {
      const { node } = setup({ isError: true, message: 'test' })
      expect(node.getAttribute('data-automation-id')).toEqual('reservation_error_modal')
    })

    it('should pass record ID and selected branch when clicking reserve publication button', () => {
      const { output, props } = setup({ recordId: '123' })
      const reserveButton = findElementByDataAutomationId(output, 'reserve_button')
      TestUtils.Simulate.click(reserveButton)
      expect(props.reservationActions.reservePublication).toHaveBeenCalled()
      expect(props.reservationActions.reservePublication.calls[ 0 ].arguments).toEqual([ '123', 'dfb' ]) // dfb is currently the first selectable branch
    })
  })
})
{'fraction_non_alphanumeric': 0.1387599016662114, 'fraction_numerical': 0.0038240917782026767, 'mean_word_length': 3.908847184986595, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '2365311', 'n_tokens_mistral': 1082, 'n_tokens_neox': 1085, 'n_words': 244}