<commit_before>import { axe } from 'jest-axe'
import React from 'react'
import { shallow, mount } from 'enzyme'

import ChatDialog from './chatDialog'
import AvatarName from '../avatarName'

test('renders without crashing', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  shallow(<ChatDialog
    names={names}
    data={[]}
    isIM={false}
    sendTo={() => {}}
  />)
})

test('renders local chat', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  const sendData = {
    text: null,
    count: 0
  }

  const renderedLocal = mount(<ChatDialog
    names={names}
    data={[]}
    sendTo={text => {
      sendData.text = text
      sendData.count += 1
    }}
  />)

  expect(renderedLocal.find('input').prop('placeholder')).toBe('Send to local chat')

  const sendButton = renderedLocal.find('button')
  expect(sendButton.text()).toBe('send')

  renderedLocal.find('input').simulate('change', {
    target: {
      value: 'Hello World!'
    }
  })
  sendButton.simulate('submit')

  expect(sendData.text).toBe('Hello World!')
  expect(sendData.count).toBe(1)
})

test('renders IM chat', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  const imData = {
    chatUUID: 'abc',
    saveId: 'def',
    messages: []
  }

  const loadHistoryData = {
    id: null,
    saveId: null,
    count: 0
  }

  const sendData = {
    text: null,
    count: 0
  }

  const renderedIM = mount(<ChatDialog
    names={names}
    data={imData}
    isIM
    sendTo={text => {
      sendData.text = text
      sendData.count += 1
    }}
    loadHistory={(id, saveId) => {
      loadHistoryData.id = id
      loadHistoryData.saveId = saveId
      loadHistoryData.count += 1
    }}
  />)

  expect(renderedIM.find('input').prop('placeholder')).toBe('Send Instant Message')

  const sendButton = renderedIM.find('button')
  expect(sendButton.text()).toBe('send')
  renderedIM.find('input').simulate('change', {
    target: {
      value: 'Hello World!'
    }
  })
  sendButton.simulate('click')

  expect(sendData.text).toBe('Hello World!')
  expect(sendData.count).toBe(1)

  expect(loadHistoryData.id).toBe('abc')<commit_msg>fix(chatDialog): fix missing change from click to submit<commit_after>import { axe } from 'jest-axe'
import React from 'react'
import { shallow, mount } from 'enzyme'

import ChatDialog from './chatDialog'
import AvatarName from '../avatarName'

test('renders without crashing', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  shallow(<ChatDialog
    names={names}
    data={[]}
    isIM={false}
    sendTo={() => {}}
  />)
})

test('renders local chat', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  const sendData = {
    text: null,
    count: 0
  }

  const renderedLocal = mount(<ChatDialog
    names={names}
    data={[]}
    sendTo={text => {
      sendData.text = text
      sendData.count += 1
    }}
  />)

  expect(renderedLocal.find('input').prop('placeholder')).toBe('Send to local chat')

  const sendButton = renderedLocal.find('button')
  expect(sendButton.text()).toBe('send')

  renderedLocal.find('input').simulate('change', {
    target: {
      value: 'Hello World!'
    }
  })
  sendButton.simulate('submit')

  expect(sendData.text).toBe('Hello World!')
  expect(sendData.count).toBe(1)
})

test('renders IM chat', () => {
  const names = {
    first: new AvatarName('<NAME>')
  }

  const imData = {
    chatUUID: 'abc',
    saveId: 'def',
    messages: []
  }

  const loadHistoryData = {
    id: null,
    saveId: null,
    count: 0
  }

  const sendData = {
    text: null,
    count: 0
  }

  const renderedIM = mount(<ChatDialog
    names={names}
    data={imData}
    isIM
    sendTo={text => {
      sendData.text = text
      sendData.count += 1
    }}
    loadHistory={(id, saveId) => {
      loadHistoryData.id = id
      loadHistoryData.saveId = saveId
      loadHistoryData.count += 1
    }}
  />)

  expect(renderedIM.find('input').prop('placeholder')).toBe('Send Instant Message')

  const sendButton = renderedIM.find('button')
  expect(sendButton.text()).toBe('send')
  renderedIM.find('input').simulate('change', {
    target: {
      value: 'Hello World!'
    }
  })
  sendButton.simulate('submit')

  expect(sendData.text).toBe('Hello World!')
  expect(sendData.count).toBe(1)

  expect(loadHistoryData.id).toBe('abc')
{'fraction_non_alphanumeric': 0.16788822721026112, 'fraction_numerical': 0.0036646816307833257, 'mean_word_length': 3.1043233082706765, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 29, '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': '4208048', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1439, 'n_words': 286}