2022-03-25 15:35:56 +08:00
|
|
|
import { nextTick, ref } from 'vue'
|
2020-10-16 10:37:35 +08:00
|
|
|
import { mount } from '@vue/test-utils'
|
2022-05-24 13:42:09 +08:00
|
|
|
import { describe, expect, it, test } from 'vitest'
|
2022-03-25 15:35:56 +08:00
|
|
|
import { ArrowDown, ArrowUp } from '@element-plus/icons-vue'
|
2022-05-05 22:04:32 +08:00
|
|
|
import { ElFormItem } from '@element-plus/components/form'
|
2021-10-22 23:28:03 +08:00
|
|
|
import InputNumber from '../src/input-number.vue'
|
2020-10-16 10:37:35 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
const mouseup = new Event('mouseup')
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-10-16 10:37:35 +08:00
|
|
|
describe('InputNumber.vue', () => {
|
|
|
|
test('create', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(1)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber label="描述文字" v-model={num.value} />
|
|
|
|
))
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.find('input').exists()).toBe(true)
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('modelValue', () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const inputText = ref(1)
|
|
|
|
const wrapper = mount(() => <InputNumber modelValue={inputText.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.find('input').element.value).toEqual('1')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2022-01-19 15:27:29 +08:00
|
|
|
test('set modelValue undefined to form validate', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(undefined)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<>
|
|
|
|
<InputNumber modelValue={num.value} placeholder="input number" />
|
|
|
|
<p>{num.value}</p>
|
|
|
|
</>
|
|
|
|
))
|
2022-01-19 15:27:29 +08:00
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('p').element.innerText).toBeUndefined()
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2021-12-29 14:27:23 +08:00
|
|
|
test('set modelValue undefined to display placeholder', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const inputText = ref<number | undefined>(1)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber modelValue={inputText.value} placeholder="input number" />
|
|
|
|
))
|
2021-12-29 14:27:23 +08:00
|
|
|
expect(wrapper.find('input').element.value).toEqual('1')
|
2022-05-28 09:13:34 +08:00
|
|
|
inputText.value = undefined
|
2021-12-29 14:27:23 +08:00
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('')
|
|
|
|
expect(wrapper.find('input').element.getAttribute('aria-valuenow')).toEqual(
|
2022-05-17 01:16:44 +08:00
|
|
|
'null'
|
2021-12-29 14:27:23 +08:00
|
|
|
)
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('min', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(1)
|
|
|
|
const wrapper = mount(() => <InputNumber min={3} v-model={num.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.find('input').element.value).toEqual('3')
|
|
|
|
wrapper.find('.el-input-number__decrease').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('3')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('max', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(5)
|
|
|
|
const wrapper = mount(() => <InputNumber max={3} v-model={num.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.find('input').element.value).toEqual('3')
|
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('3')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('step, increase and decrease', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => <InputNumber v-model={num.value} step={2} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
wrapper.find('.el-input-number__decrease').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('-2')
|
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('0')
|
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('2')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('step-strictly', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber step-strictly={true} step={2} v-model={num.value} />
|
|
|
|
))
|
2020-11-15 00:01:21 +08:00
|
|
|
await wrapper.find('input').setValue(3)
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('4')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2022-07-02 15:38:07 +08:00
|
|
|
test('value decimals miss prop precision', async () => {
|
|
|
|
const num = ref(0.2)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber step-strictly={true} step={0.1} v-model={num.value} />
|
|
|
|
))
|
|
|
|
const elInputNumber = wrapper.findComponent({ name: 'ElInputNumber' }).vm
|
|
|
|
elInputNumber.increase()
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('0.3')
|
|
|
|
num.value = 0.4
|
|
|
|
await nextTick()
|
|
|
|
elInputNumber.decrease()
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('0.3')
|
|
|
|
})
|
|
|
|
|
2022-05-24 13:42:09 +08:00
|
|
|
describe('precision accuracy 2', () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber precision={2} v-model={num.value} />
|
|
|
|
))
|
2022-05-24 13:42:09 +08:00
|
|
|
it.each([
|
|
|
|
[1.1111111111, '1.11'],
|
|
|
|
[17.275, '17.28'],
|
|
|
|
[17.2745, '17.27'],
|
|
|
|
[1.09, '1.09'],
|
|
|
|
[1.009, '1.01'],
|
|
|
|
[10.999, '11.00'],
|
|
|
|
[15, '15.00'],
|
|
|
|
[15.5, '15.50'],
|
|
|
|
[15.555, '15.56'],
|
|
|
|
])(
|
|
|
|
'each precision accuracy test: $input $output',
|
|
|
|
async (input, output) => {
|
|
|
|
await wrapper.find('input').setValue(input)
|
|
|
|
expect(wrapper.find('input').element.value).toEqual(`${output}`)
|
|
|
|
}
|
|
|
|
)
|
2020-11-15 00:01:21 +08:00
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2022-05-24 13:42:09 +08:00
|
|
|
describe('precision accuracy 3', () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber precision={3} v-model={num.value} />
|
|
|
|
))
|
2022-05-24 13:42:09 +08:00
|
|
|
it.each([
|
|
|
|
[1.1111111111, '1.111'],
|
|
|
|
[17.275, '17.275'],
|
|
|
|
[17.2745, '17.275'],
|
|
|
|
[1.09, '1.090'],
|
|
|
|
[10.999, '10.999'],
|
|
|
|
[10.9999, '11.000'],
|
|
|
|
[15.555, '15.555'],
|
|
|
|
[1.3335, '1.334'],
|
|
|
|
])(
|
|
|
|
'each precision accuracy test: $input $output',
|
|
|
|
async (input, output) => {
|
|
|
|
await wrapper.find('input').setValue(input)
|
|
|
|
expect(wrapper.find('input').element.value).toEqual(`${output}`)
|
|
|
|
}
|
|
|
|
)
|
2022-05-02 16:38:08 +08:00
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('disabled', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber disabled={true} v-model={num.value} />
|
|
|
|
))
|
2020-11-15 00:01:21 +08:00
|
|
|
wrapper.find('.el-input-number__decrease').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('0')
|
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.find('input').element.value).toEqual('0')
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('controls', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber controls={false} v-model={num.value} />
|
|
|
|
))
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.find('.el-input-number__increase').exists()).toBe(false)
|
|
|
|
expect(wrapper.find('.el-input-number__decrease').exists()).toBe(false)
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('controls-position', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber controls-position="right" v-model={num.value} />
|
|
|
|
))
|
2021-10-27 23:17:13 +08:00
|
|
|
expect(wrapper.findComponent(ArrowDown).exists()).toBe(true)
|
|
|
|
expect(wrapper.findComponent(ArrowUp).exists()).toBe(true)
|
2020-11-15 00:01:21 +08:00
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('change-event', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => <InputNumber v-model={num.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('change')).toHaveLength(1)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.getComponent(InputNumber).emitted().change[0]).toEqual([
|
|
|
|
1, 0,
|
|
|
|
])
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('input')).toHaveLength(1)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.getComponent(InputNumber).emitted('update:modelValue')
|
|
|
|
).toHaveLength(1)
|
2020-11-15 00:01:21 +08:00
|
|
|
wrapper.find('.el-input-number__increase').trigger('mousedown')
|
|
|
|
document.dispatchEvent(mouseup)
|
|
|
|
await nextTick()
|
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('change')).toHaveLength(2)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(wrapper.getComponent(InputNumber).emitted().change[1]).toEqual([
|
|
|
|
2, 1,
|
|
|
|
])
|
2020-11-15 00:01:21 +08:00
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('input')).toHaveLength(2)
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
|
|
|
wrapper.getComponent(InputNumber).emitted('update:modelValue')
|
|
|
|
).toHaveLength(2)
|
2020-11-15 00:01:21 +08:00
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('blur-event', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => <InputNumber v-model={num.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
await wrapper.find('input').trigger('blur')
|
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('blur')).toHaveLength(1)
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2020-11-15 00:01:21 +08:00
|
|
|
test('focus-event', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(0)
|
|
|
|
const wrapper = mount(() => <InputNumber v-model={num.value} />)
|
2020-11-15 00:01:21 +08:00
|
|
|
await wrapper.find('input').trigger('focus')
|
|
|
|
expect(wrapper.getComponent(InputNumber).emitted('focus')).toHaveLength(1)
|
2020-10-16 10:37:35 +08:00
|
|
|
})
|
2021-01-11 10:30:44 +08:00
|
|
|
|
2022-05-17 01:16:44 +08:00
|
|
|
test('clear with :value-on-clear="null"', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(2)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber v-model={num.value} min={1} max={10} />
|
|
|
|
))
|
2022-05-17 01:16:44 +08:00
|
|
|
const elInput = wrapper.findComponent({ name: 'ElInputNumber' }).vm
|
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(null)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.increase()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.increase()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(2)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(null)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.decrease()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.decrease()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2022-05-17 01:16:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('clear with value-on-clear="min"', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(2)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber value-on-clear="min" v-model={num.value} min={1} max={10} />
|
|
|
|
))
|
2021-01-11 10:30:44 +08:00
|
|
|
const elInput = wrapper.findComponent({ name: 'ElInputNumber' }).vm
|
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2021-01-11 10:30:44 +08:00
|
|
|
elInput.increase()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(2)
|
2021-01-11 10:30:44 +08:00
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2021-01-11 10:30:44 +08:00
|
|
|
elInput.decrease()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(1)
|
2021-01-11 10:30:44 +08:00
|
|
|
})
|
2021-01-12 10:50:27 +08:00
|
|
|
|
2022-05-17 01:16:44 +08:00
|
|
|
test('clear with value-on-clear="max"', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(2)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber value-on-clear="max" v-model={num.value} min={1} max={10} />
|
|
|
|
))
|
2022-05-17 01:16:44 +08:00
|
|
|
const elInput = wrapper.findComponent({ name: 'ElInputNumber' }).vm
|
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(10)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.increase()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(10)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(10)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.decrease()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(9)
|
2022-05-17 01:16:44 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
test('clear with :value-on-clear="5"', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num = ref(2)
|
|
|
|
const wrapper = mount(() => (
|
|
|
|
<InputNumber value-on-clear={5} v-model={num.value} min={1} max={10} />
|
|
|
|
))
|
2022-05-17 01:16:44 +08:00
|
|
|
const elInput = wrapper.findComponent({ name: 'ElInputNumber' }).vm
|
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(5)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.increase()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(6)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.handleInputChange('')
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(5)
|
2022-05-17 01:16:44 +08:00
|
|
|
elInput.decrease()
|
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num.value).toBe(4)
|
2022-05-17 01:16:44 +08:00
|
|
|
})
|
|
|
|
|
2021-01-12 10:50:27 +08:00
|
|
|
test('check increase and decrease button when modelValue not in [min, max]', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const num1 = ref(-5)
|
|
|
|
const num2 = ref(15)
|
2022-05-29 03:55:04 +08:00
|
|
|
const wrapper = mount({
|
|
|
|
setup() {
|
|
|
|
return () => (
|
|
|
|
<>
|
|
|
|
<InputNumber
|
|
|
|
ref="inputNumber1"
|
|
|
|
v-model={num1.value}
|
|
|
|
min={1}
|
|
|
|
max={10}
|
|
|
|
/>
|
|
|
|
<InputNumber
|
|
|
|
ref="inputNumber2"
|
|
|
|
v-model={num2.value}
|
|
|
|
min={1}
|
|
|
|
max={10}
|
|
|
|
/>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
},
|
|
|
|
})
|
2022-05-28 09:13:34 +08:00
|
|
|
|
2022-05-29 03:55:04 +08:00
|
|
|
const inputNumber1 = wrapper.findComponent({ ref: 'inputNumber1' }).vm
|
|
|
|
const inputNumber2 = wrapper.findComponent({ ref: 'inputNumber2' }).vm
|
2022-05-28 09:13:34 +08:00
|
|
|
|
|
|
|
expect(num1.value).toBe(1)
|
|
|
|
expect(num2.value).toBe(10)
|
2021-01-12 10:50:27 +08:00
|
|
|
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber1.decrease()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num1.value).toBe(1)
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber1.increase()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num1.value).toBe(2)
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber1.increase()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num1.value).toBe(3)
|
2021-01-12 10:50:27 +08:00
|
|
|
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber2.increase()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num2.value).toBe(10)
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber2.decrease()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num2.value).toBe(9)
|
2022-05-29 03:55:04 +08:00
|
|
|
inputNumber2.decrease()
|
2021-01-12 10:50:27 +08:00
|
|
|
await nextTick()
|
2022-05-28 09:13:34 +08:00
|
|
|
expect(num2.value).toBe(8)
|
2021-01-12 10:50:27 +08:00
|
|
|
})
|
2022-05-05 22:04:32 +08:00
|
|
|
|
|
|
|
describe('form item accessibility integration', () => {
|
|
|
|
test('automatic id attachment', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<ElFormItem label="Foobar" data-test-ref="item">
|
|
|
|
<InputNumber />
|
|
|
|
</ElFormItem>
|
|
|
|
))
|
2022-05-05 22:04:32 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
const formItemLabel = formItem.find('.el-form-item__label')
|
|
|
|
const innerInput = wrapper.find('.el-input__inner')
|
|
|
|
expect(formItem.attributes().role).toBeFalsy()
|
|
|
|
expect(formItemLabel.attributes().for).toBe(innerInput.attributes().id)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('specified id attachment', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<ElFormItem label="Foobar" data-test-ref="item">
|
|
|
|
<InputNumber id="foobar" />
|
|
|
|
</ElFormItem>
|
|
|
|
))
|
2022-05-05 22:04:32 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
const formItemLabel = formItem.find('.el-form-item__label')
|
|
|
|
const innerInput = wrapper.find('.el-input__inner')
|
|
|
|
expect(formItem.attributes().role).toBeFalsy()
|
|
|
|
expect(innerInput.attributes().id).toBe('foobar')
|
|
|
|
expect(formItemLabel.attributes().for).toBe(innerInput.attributes().id)
|
|
|
|
})
|
|
|
|
|
|
|
|
test('form item role is group when multiple inputs', async () => {
|
2022-05-28 09:13:34 +08:00
|
|
|
const wrapper = mount(() => (
|
|
|
|
<ElFormItem label="Foobar" data-test-ref="item">
|
|
|
|
<InputNumber />
|
|
|
|
<InputNumber />
|
|
|
|
</ElFormItem>
|
|
|
|
))
|
2022-05-05 22:04:32 +08:00
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
expect(formItem.attributes().role).toBe('group')
|
|
|
|
})
|
|
|
|
})
|
2020-10-16 10:37:35 +08:00
|
|
|
})
|