<commit_before>import { test } from '@/test'
import { VRadioGroup, VRadio } from '@/components/VRadioGroup'

test('VRadioGroup.vue', ({ mount }) => {
  it('should render role on radio group', () => {
    const wrapper = mount(VRadioGroup)

    expect(wrapper.html()).toMatchSnapshot()

    const radioGroup = wrapper.find('.v-input--radio-group__input')[0]
    expect(radioGroup.getAttribute('role')).toBe('radiogroup')
  })

  // TODO: Test ability to toggle multiple data types

  it('should be in error when v-radio-group is', async () => {
    const wrapper = mount(VRadioGroup, {
      propsData: {
        error: false
      },
      slots: {
        default: [VRadio]
      }
    })

    const radio = wrapper.vm.radios[0]

    wrapper.setProps({ error: true })
    await wrapper.vm.$nextTick()
    expect(radio.parentError).toBe(true)
    expect(wrapper.html()).toMatchSnapshot()

    wrapper.setProps({ error: false })
    await wrapper.vm.$nextTick()
    expect(radio.parentError).toBe(false)
    expect(wrapper.html()).toMatchSnapshot()
  })

  it('should provide isMandatory', () => {
    const stub = {
      name: 'stub',
      inject: ['isMandatory'],
      render: h => null
    }
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [stub]
      }
    })

    const find = wrapper.first(stub)

    expect(find.vm.isMandatory()).toBe(true)

    wrapper.setProps({ mandatory: false })

    expect(find.vm.isMandatory()).toBe(false)
  })

  it('should toggle radio', async () => {
    const stub = value => ({
      extends: VRadio,
      props: {
        value: {
          default: value
        }
      }
    })
    const wrapper = mount(VRadioGroup, {
      attachToDocument: true,
      slots: {
        default: [stub('foo'), stub('bar')]
      }
    })

    expect(wrapper.vm.radios.length).toBe(2)

    const radios = wrapper.find(VRadio)
    const one = radios[0]
    const two = radios[1]
    const inputOne = one.first('input')
    const inputTwo = two.first('input')

    inputOne.trigger('focus')
    inputOne.trigger('keydown.enter')


    expect(one.vm.isActive).toBe(true)

    wrapper.setProps({ disabled: true })

    inputTwo.trigger('focus')
    inputTwo.trigger('keydown.enter')

    await wrapper.vm.$nextTick()

    expect(one.vm.isActive).toBe(true)
    expect(two.vm.isActive).toBe(false)
  })

  it('should change selected radio', async () => {
    const wrapper = mount(VRadioGroup, {
      attachToDocument: true,
      slots: {
        default: [{
          functional: true,

          render: h => h(VRadio, {
            props: { value: 'foo' }
          })
        }]
      }
    })

    const radio = wrapper.first(VRadio)

    expect(wrapper.vm.internalValue).toBe(undefined)
    expect(radio.vm.isActive).toBe(false)

    wrapper.setProps({ value: 'foo' })

    await wrapper.vm.$nextTick()

    expect(wrapper.vm.internalValue).toBe('foo')
    expect(radio.vm.isActive).toBe(true)
  })

  it('should have custom tabindex', () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          functional: true,

          render: h => h(VRadio, {
            attrs: {
              tabindex: 2
            }
          })
        }]
      }
    })

    const input = wrapper.first('input')

    expect(input.element.tabIndex).toBe(2)
  })

  it('should unregister radios that are removed', () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          functional: true,
          render: h => h(VRadio)
        }]
      }
    })

    const radio = wrapper.first(VRadio)

    expect(wrapper.vm.radios.length).toBe(1)

    radio.vm.$destroy()

    expect(wrapper.vm.radios.length).toBe(0)
  })

  it('should validate on blur', async () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          extends: VRadio
        }]
      }
    })

    const blur = jest.fn()
    const input = wrapper.first('input')
    wrapper.vm.$on('blur', blur)

    expect(wrapper.vm.shouldValidate).toBe(false)

    input.trigger('focus')
    await wrapper.vm.$nextTick()
    input.trigger('blur')

    expect(blur).toHaveBeenCalledTimes(1)
    expect(wrapper.vm.shouldValidate).toBe(true)
<commit_msg>test(v-radio-group): removed unneeded await<commit_after>import { test } from '@/test'
import { VRadioGroup, VRadio } from '@/components/VRadioGroup'

test('VRadioGroup.vue', ({ mount }) => {
  it('should render role on radio group', () => {
    const wrapper = mount(VRadioGroup)

    expect(wrapper.html()).toMatchSnapshot()

    const radioGroup = wrapper.find('.v-input--radio-group__input')[0]
    expect(radioGroup.getAttribute('role')).toBe('radiogroup')
  })

  // TODO: Test ability to toggle multiple data types

  it('should be in error when v-radio-group is', async () => {
    const wrapper = mount(VRadioGroup, {
      propsData: {
        error: false
      },
      slots: {
        default: [VRadio]
      }
    })

    const radio = wrapper.vm.radios[0]

    wrapper.setProps({ error: true })
    await wrapper.vm.$nextTick()
    expect(radio.parentError).toBe(true)
    expect(wrapper.html()).toMatchSnapshot()

    wrapper.setProps({ error: false })
    await wrapper.vm.$nextTick()
    expect(radio.parentError).toBe(false)
    expect(wrapper.html()).toMatchSnapshot()
  })

  it('should provide isMandatory', () => {
    const stub = {
      name: 'stub',
      inject: ['isMandatory'],
      render: h => null
    }
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [stub]
      }
    })

    const find = wrapper.first(stub)

    expect(find.vm.isMandatory()).toBe(true)

    wrapper.setProps({ mandatory: false })

    expect(find.vm.isMandatory()).toBe(false)
  })

  it('should toggle radio', async () => {
    const stub = value => ({
      extends: VRadio,
      props: {
        value: {
          default: value
        }
      }
    })
    const wrapper = mount(VRadioGroup, {
      attachToDocument: true,
      slots: {
        default: [stub('foo'), stub('bar')]
      }
    })

    expect(wrapper.vm.radios.length).toBe(2)

    const radios = wrapper.find(VRadio)
    const one = radios[0]
    const two = radios[1]
    const inputOne = one.first('input')
    const inputTwo = two.first('input')

    inputOne.trigger('focus')
    inputOne.trigger('keydown.enter')


    expect(one.vm.isActive).toBe(true)

    wrapper.setProps({ disabled: true })

    inputTwo.trigger('focus')
    inputTwo.trigger('keydown.enter')

    await wrapper.vm.$nextTick()

    expect(one.vm.isActive).toBe(true)
    expect(two.vm.isActive).toBe(false)
  })

  it('should change selected radio', async () => {
    const wrapper = mount(VRadioGroup, {
      attachToDocument: true,
      slots: {
        default: [{
          functional: true,

          render: h => h(VRadio, {
            props: { value: 'foo' }
          })
        }]
      }
    })

    const radio = wrapper.first(VRadio)

    expect(wrapper.vm.internalValue).toBe(undefined)
    expect(radio.vm.isActive).toBe(false)

    wrapper.setProps({ value: 'foo' })

    await wrapper.vm.$nextTick()

    expect(wrapper.vm.internalValue).toBe('foo')
    expect(radio.vm.isActive).toBe(true)
  })

  it('should have custom tabindex', () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          functional: true,

          render: h => h(VRadio, {
            attrs: {
              tabindex: 2
            }
          })
        }]
      }
    })

    const input = wrapper.first('input')

    expect(input.element.tabIndex).toBe(2)
  })

  it('should unregister radios that are removed', () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          functional: true,
          render: h => h(VRadio)
        }]
      }
    })

    const radio = wrapper.first(VRadio)

    expect(wrapper.vm.radios.length).toBe(1)

    radio.vm.$destroy()

    expect(wrapper.vm.radios.length).toBe(0)
  })

  it('should validate on blur', async () => {
    const wrapper = mount(VRadioGroup, {
      slots: {
        default: [{
          extends: VRadio
        }]
      }
    })

    const blur = jest.fn()
    const input = wrapper.first('input')
    wrapper.vm.$on('blur', blur)

    expect(wrapper.vm.shouldValidate).toBe(false)

    input.trigger('focus')
    input.trigger('blur')

    expect(blur).toHaveBeenCalledTimes(1)
    expect(wrapper.vm.shouldValidate).toBe(true)

{'fraction_non_alphanumeric': 0.151103765789163, 'fraction_numerical': 0.002360996340455672, 'mean_word_length': 2.3779904306220097, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, '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': '2555000', 'n_tokens_mistral': 2703, 'n_tokens_neox': 2636, 'n_words': 491}