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

import SignInPopup from './signInPopup'

test('renders without crashing', () => {
  shallow(
    <SignInPopup onCancel={() => {}} isSignUp onSend={() => {}} />
  )

  shallow(
    <SignInPopup onCancel={() => {}} onSend={() => {}} />
  )
})

test('renders different with isSignUp', () => {
  const signUp = shallow(<SignInPopup onCancel={() => {}} isSignUp onSend={() => {}} />)

  const signIn = shallow(<SignInPopup onCancel={() => {}} onSend={() => {}} />)

  expect(signUp.find('Popup').prop('title')).toBe('sign up')
  expect(signUp.find('input').length).toBe(3)

  expect(signIn.find('Popup').prop('title')).toBe('sign in')
  expect(signIn.find('input[autoComplete="new-password"]').first().prop('style')).toEqual({
    display: 'none'
  })

  ;[signUp, signIn].forEach((popup, index) => {
    const buttons = popup.find('button')

    expect(buttons.length).toBe(2)
    expect(buttons.first().text()).toBe('cancel')
    expect(buttons.last().text()).toBe(index === 0 ? 'sign up' : 'sign in')
  })
})

test('click actions', () => {
  let cancelCallCount = 0
  let sendCallCount = 0
  let shouldCallSend = false

  const onSend = (username, password, type, ...rest) => {
    expect(shouldCallSend).toBe(true)
    expect(username).toBe('<EMAIL>')
    expect(password).toBe('<PASSWORD>')
    expect(rest.length).toBe(0)

    sendCallCount += 1
  }

  const onCancel = event => {
    cancelCallCount += 1
  }

  const signUp = mount(<SignInPopup
    onCancel={onCancel}
    isSignUp
    onSend={onSend}
  />)

  const signIn = mount(<SignInPopup
    onCancel={onCancel}
    onSend={onSend}
  />)

  ;[signUp, signIn].forEach((popup, index) => {
    const isSignUp = index === 0

    popup.find('button').first().simulate('click')
    popup.find('a[href="#close_popup"]').simulate('click', {
      preventDefault: () => {}
    })

    popup.find('button').last().simulate('click')

    popup.find('input[type="email"]').simulate('change', {
      target: {
        value: '<EMAIL>',
        validity: {
          valid: true
        },
        dataset: {
          key: 'username'
        }
      }
    })

    popup.find('button').last().simulate('click')

    const passwordInputs = popup.find('input[type="password"]')
    const addPassword = (aInput, key) => {
      aInput.simulate('change', {
        target: {
          value: 'secret',
          dataset: {
            key
          }
        }
      })
    }
    addPassword(passwordInputs.first(), 'password')
    if (isSignUp) {
      popup.find('button').last().simulate('click')
      addPassword(passwordInputs.last(), '<PASSWORD>')
    }

    shouldCallSend = true
    popup.find('button').last().simulate('click')
  })

  expect(cancelCallCount).toBe(4)
  expect(sendCallCount).toBe(2)
})<commit_msg>test(signInPopup): add tests for cryptoPassword<commit_after>import React from 'react'
import { shallow, mount } from 'enzyme'

import SignInPopup from './signInPopup'

test('renders without crashing', () => {
  shallow(
    <SignInPopup onCancel={() => {}} isSignUp onSend={() => {}} />
  )

  shallow(
    <SignInPopup onCancel={() => {}} onSend={() => {}} />
  )
})

test('renders different with isSignUp', () => {
  const signUp = shallow(<SignInPopup onCancel={() => {}} isSignUp onSend={() => {}} />)

  const signIn = shallow(<SignInPopup onCancel={() => {}} onSend={() => {}} />)

  expect(signUp.find('Popup').prop('title')).toBe('sign up')
  expect(signUp.find('input').length).toBe(5)

  expect(signIn.find('Popup').prop('title')).toBe('sign in')
  expect(signIn.find('input[autoComplete="new-password"]').first().prop('style')).toEqual({
    display: 'none'
  })

  ;[signUp, signIn].forEach((popup, index) => {
    const buttons = popup.find('button')

    expect(buttons.length).toBe(2)
    expect(buttons.first().text()).toBe('cancel')
    expect(buttons.last().text()).toBe(index === 0 ? 'sign up' : 'sign in')
  })
})

test('click actions', () => {
  let cancelCallCount = 0
  let sendCallCount = 0
  let shouldCallSend = false

  const onSend = (username, password, cryptoPassword, type, ...rest) => {
    expect(shouldCallSend).toBe(true)
    expect(username).toBe('<EMAIL>')
    expect(password).toBe('<PASSWORD>')
    expect(cryptoPassword).toBe('encrypted')
    expect(rest.length).toBe(0)

    sendCallCount += 1
  }

  const onCancel = event => {
    cancelCallCount += 1
  }

  const signUp = mount(<SignInPopup
    onCancel={onCancel}
    isSignUp
    onSend={onSend}
  />)

  const signIn = mount(<SignInPopup
    onCancel={onCancel}
    onSend={onSend}
  />)

  ;[signUp, signIn].forEach((popup, index) => {
    const isSignUp = index === 0

    popup.find('button').first().simulate('click')
    popup.find('a[href="#close_popup"]').simulate('click', {
      preventDefault: () => {}
    })

    popup.find('button').last().simulate('click')

    popup.find('input[type="email"]').simulate('change', {
      target: {
        value: '<EMAIL>',
        validity: {
          valid: true
        },
        dataset: {
          key: 'username'
        }
      }
    })

    popup.find('button').last().simulate('click')

    const passwordInputs = popup.find('input[type="password"]')
    const addPassword = (aInput, key, password) => {
      aInput.simulate('change', {
        target: {
          value: password,
          dataset: {
            key
          }
        }
      })
    }
    addPassword(passwordInputs.first(), 'password', 'secret')
    addPassword(passwordInputs.at(2), 'cryptoPassword', 'encrypted')
    if (isSignUp) {
      popup.find('button').last().simulate('click')
      addPassword(passwordInputs.at(1), 'password2', 'secret')
      addPassword(passwordInputs.at(3), '<PASSWORD>', 'encrypted')
    }

    shouldCallSend = true
    popup.find('button').last().simulate('click')
  })

  expect(cancelCallCount).toBe(4)
  expect(sendCallCount).toBe(2)
})
{'fraction_non_alphanumeric': 0.19741480611045828, 'fraction_numerical': 0.0043646130602652345, 'mean_word_length': 3.258756254467477, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 57, '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': '6868777', 'n_tokens_mistral': 1956, 'n_tokens_neox': 1935, 'n_words': 311}