2022-06-22 08:04:42 +08:00
|
|
|
// @ts-nocheck
|
2021-09-17 15:27:31 +08:00
|
|
|
import { nextTick } from 'vue'
|
|
|
|
import { mount } from '@vue/test-utils'
|
2022-04-19 12:46:57 +08:00
|
|
|
import { afterEach, describe, expect, it } from 'vitest'
|
2021-08-24 13:36:48 +08:00
|
|
|
import dayjs from 'dayjs'
|
2022-04-19 12:46:57 +08:00
|
|
|
import triggerEvent from '@element-plus/test-utils/trigger-event'
|
2022-05-05 22:04:32 +08:00
|
|
|
import { ElFormItem } from '@element-plus/components/form'
|
2020-10-03 20:13:19 +08:00
|
|
|
import DatePicker from '../src/date-picker'
|
|
|
|
|
|
|
|
const formatStr = 'YYYY-MM-DD HH:mm:ss'
|
|
|
|
const makeRange = (start, end) => {
|
|
|
|
const result = []
|
|
|
|
for (let i = start; i <= end; i++) {
|
|
|
|
result.push(i)
|
|
|
|
}
|
|
|
|
return result
|
|
|
|
}
|
2021-09-04 19:29:28 +08:00
|
|
|
const _mount = (template: string, data = () => ({}), otherObj?) =>
|
|
|
|
mount(
|
|
|
|
{
|
|
|
|
components: {
|
|
|
|
'el-date-picker': DatePicker,
|
2022-05-05 22:04:32 +08:00
|
|
|
'el-form-item': ElFormItem,
|
2021-09-04 19:29:28 +08:00
|
|
|
},
|
|
|
|
template,
|
|
|
|
data,
|
|
|
|
...otherObj,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
attachTo: 'body',
|
|
|
|
}
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
document.documentElement.innerHTML = ''
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('Datetime Picker', () => {
|
|
|
|
it('both picker show correct formated value (extract date-format and time-format from format property', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
|
|
|
:format="format"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: new Date(2018, 2, 5, 10, 15, 24),
|
|
|
|
format: 'YYYY/MM/DD HH:mm A',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const dateInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(1) input'
|
|
|
|
)
|
|
|
|
const timeInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(2) input'
|
|
|
|
)
|
|
|
|
;(timeInput as HTMLElement).focus()
|
2020-10-03 20:13:19 +08:00
|
|
|
await nextTick()
|
|
|
|
// both input shows correct value
|
|
|
|
expect((dateInput as HTMLInputElement).value).toBe('2018/03/05')
|
|
|
|
expect((timeInput as HTMLInputElement).value).toBe('10:15 AM')
|
|
|
|
wrapper.setProps({
|
|
|
|
format: 'MM-DD-YYYY HH a',
|
|
|
|
})
|
|
|
|
await nextTick()
|
|
|
|
expect((dateInput as HTMLInputElement).value).toBe('03-05-2018')
|
|
|
|
expect((timeInput as HTMLInputElement).value).toBe('10 am')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('both picker show correct value', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: new Date(2000, 9, 1, 10, 0, 1),
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const dateInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(1) input'
|
|
|
|
)
|
|
|
|
const timeInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(2) input'
|
|
|
|
)
|
|
|
|
;(timeInput as HTMLElement).focus()
|
2020-10-03 20:13:19 +08:00
|
|
|
await nextTick()
|
|
|
|
// both input shows correct value
|
|
|
|
expect((dateInput as HTMLInputElement).value).toBe('2000-10-01')
|
|
|
|
expect((timeInput as HTMLInputElement).value).toBe('10:00:01')
|
|
|
|
// time spinner highlight is correct
|
2021-09-04 19:29:28 +08:00
|
|
|
let spinners = document.querySelectorAll(
|
2022-03-23 22:58:43 +08:00
|
|
|
'.el-time-spinner ul li.is-active'
|
2021-09-04 19:29:28 +08:00
|
|
|
) as any
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(spinners[0].textContent).toBe('10')
|
|
|
|
expect(spinners[1].textContent).toBe('00')
|
|
|
|
expect(spinners[2].textContent).toBe('01')
|
|
|
|
wrapper.setProps({
|
|
|
|
modelValue: new Date(2001, 10, 2, 11, 1, 2),
|
|
|
|
})
|
|
|
|
await nextTick()
|
2022-03-23 22:58:43 +08:00
|
|
|
spinners = document.querySelectorAll(
|
|
|
|
'.el-time-spinner ul li.is-active'
|
|
|
|
) as any
|
2020-10-03 20:13:19 +08:00
|
|
|
expect((dateInput as HTMLInputElement).value).toBe('2001-11-02')
|
|
|
|
expect((timeInput as HTMLInputElement).value).toBe('11:01:02')
|
|
|
|
expect(spinners[0].textContent).toBe('11')
|
|
|
|
expect(spinners[1].textContent).toBe('01')
|
|
|
|
expect(spinners[2].textContent).toBe('02')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('click now button', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
2021-09-04 19:29:28 +08:00
|
|
|
await nextTick()
|
|
|
|
;(
|
|
|
|
document.querySelector('.el-picker-panel__link-btn') as HTMLElement
|
|
|
|
).click()
|
2020-10-03 20:13:19 +08:00
|
|
|
await nextTick()
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
// test if is current time (deviation 10 seconds)
|
|
|
|
expect(dayjs(vm.value).diff(dayjs()) < 10).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('timepicker select && input time && input date', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const input_ = document.querySelectorAll(
|
|
|
|
'.el-date-picker__editor-wrap input'
|
|
|
|
)[1]
|
|
|
|
;(input_ as HTMLElement).focus()
|
2020-10-03 20:13:19 +08:00
|
|
|
await nextTick()
|
|
|
|
const timePanel = document.querySelector('.el-time-panel')
|
|
|
|
expect(timePanel.querySelector('.el-time-spinner').innerHTML).not.toBeNull()
|
2021-09-04 19:29:28 +08:00
|
|
|
const button = document.querySelector(
|
|
|
|
'.el-time-panel .confirm'
|
|
|
|
) as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
button.click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).not.toBe('')
|
2021-09-04 19:29:28 +08:00
|
|
|
const timeInput = document.querySelectorAll(
|
|
|
|
'.el-date-picker__editor-wrap input'
|
|
|
|
)[1] as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
timeInput.value = '20:30:33'
|
|
|
|
timeInput.dispatchEvent(new Event('change'))
|
|
|
|
await nextTick()
|
|
|
|
const valueResult = dayjs(vm.value)
|
|
|
|
expect(valueResult.hour()).toBe(20)
|
|
|
|
expect(valueResult.minute()).toBe(30)
|
|
|
|
expect(valueResult.second()).toBe(33)
|
2021-09-04 19:29:28 +08:00
|
|
|
const dateInput = document.querySelector(
|
|
|
|
'.el-date-picker__editor-wrap input'
|
|
|
|
) as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
dateInput.value = '2017-02-02'
|
|
|
|
dateInput.dispatchEvent(new Event('change'))
|
|
|
|
await nextTick()
|
|
|
|
const valueResult2 = dayjs(vm.value)
|
|
|
|
expect(valueResult2.year()).toBe(2017)
|
|
|
|
expect(valueResult2.month()).toBe(1)
|
|
|
|
expect(valueResult2.date()).toBe(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('now button: can not choose disabled date', async () => {
|
|
|
|
let isDisable = true
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
|
|
|
:disabledDate="disabledDate"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
disabledDate() {
|
|
|
|
return isDisable
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
|
|
|
// click now button
|
2021-09-04 19:29:28 +08:00
|
|
|
const btn = document.querySelector(
|
2022-05-06 13:16:44 +08:00
|
|
|
'.el-picker-panel__footer .is-text'
|
2021-09-04 19:29:28 +08:00
|
|
|
) as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
const vm = wrapper.vm as any
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
isDisable = false
|
|
|
|
await nextTick()
|
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).not.toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('confirm button honors picked date', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: new Date(2000, 9, 1, 12, 0, 0), // 2010-10-01 12:00:00
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
2021-09-04 19:29:28 +08:00
|
|
|
await nextTick()
|
2020-10-03 20:13:19 +08:00
|
|
|
// changed month / year should not effect picked time
|
2021-09-04 19:29:28 +08:00
|
|
|
;(
|
|
|
|
document.querySelector(
|
2021-10-27 23:17:13 +08:00
|
|
|
'.el-date-picker__header .arrow-right'
|
2021-09-04 19:29:28 +08:00
|
|
|
) as HTMLElement
|
|
|
|
).click()
|
|
|
|
;(
|
|
|
|
document.querySelector(
|
2021-10-27 23:17:13 +08:00
|
|
|
'.el-date-picker__header .d-arrow-right'
|
2021-09-04 19:29:28 +08:00
|
|
|
) as HTMLElement
|
|
|
|
).click()
|
2020-10-03 20:13:19 +08:00
|
|
|
// click confirm button
|
2021-12-28 19:38:23 +08:00
|
|
|
document.querySelectorAll('.el-picker-panel__footer .el-button')[1].click()
|
2020-10-03 20:13:19 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
expect(dayjs(vm.value).format(formatStr)).toBe('2000-10-01 12:00:00')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('selectableRange', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const disabledHoursArr = [
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 23,
|
|
|
|
]
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
|
|
|
:disabledHours="disabledHours"
|
|
|
|
:disabledMinutes="disabledMinutes"
|
|
|
|
:disabledSeconds="disabledSeconds"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: new Date(2019, 0, 1, 18, 50),
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
|
|
|
disabledHours() {
|
|
|
|
return disabledHoursArr
|
|
|
|
},
|
|
|
|
disabledMinutes(hour) {
|
|
|
|
// ['17:30:00 - 18:30:00', '18:50:00 - 20:30:00', '21:00:00 - 22:00:00']
|
|
|
|
if (hour === 17) {
|
|
|
|
return makeRange(0, 29)
|
|
|
|
}
|
|
|
|
if (hour === 18) {
|
|
|
|
return makeRange(31, 49)
|
|
|
|
}
|
|
|
|
if (hour === 20) {
|
|
|
|
return makeRange(31, 59)
|
|
|
|
}
|
|
|
|
if (hour === 22) {
|
|
|
|
return makeRange(1, 59)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
disabledSeconds(hour, minute) {
|
|
|
|
if (hour === 18 && minute === 30) {
|
|
|
|
return makeRange(1, 59)
|
|
|
|
}
|
|
|
|
if (hour === 20 && minute === 30) {
|
|
|
|
return makeRange(1, 59)
|
|
|
|
}
|
|
|
|
if (hour === 22 && minute === 0) {
|
|
|
|
return makeRange(1, 59)
|
|
|
|
}
|
|
|
|
},
|
2020-10-03 20:13:19 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const input1 = document.querySelectorAll(
|
|
|
|
'.el-date-picker__editor-wrap input'
|
|
|
|
)[1] as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
input1.blur()
|
|
|
|
input1.focus()
|
|
|
|
await nextTick()
|
|
|
|
const list = document.querySelectorAll('.el-time-spinner__list')
|
|
|
|
const hoursEl = list[0]
|
2022-03-23 22:58:43 +08:00
|
|
|
const disabledHours = Array.from(
|
|
|
|
hoursEl.querySelectorAll('.is-disabled')
|
|
|
|
).map((node) => Number(node.textContent))
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(disabledHours).toStrictEqual(disabledHoursArr)
|
|
|
|
const minutesEl = list[1]
|
2022-03-08 14:03:32 +08:00
|
|
|
const disabledMinutes = Array.from(
|
2022-03-23 22:58:43 +08:00
|
|
|
minutesEl.querySelectorAll('.is-disabled')
|
2022-03-08 14:03:32 +08:00
|
|
|
).map((node) => Number(node.textContent))
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(disabledMinutes.length).toBe(19)
|
|
|
|
})
|
2021-04-29 15:43:15 +08:00
|
|
|
|
|
|
|
it('defaultTime takes effect when the type is datetime', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2021-04-29 15:43:15 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
|
|
|
:default-time="defaultTime"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
defaultTime: new Date(2000, 1, 1, 12, 24, 48),
|
|
|
|
})
|
|
|
|
)
|
2021-04-29 15:43:15 +08:00
|
|
|
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const someDateTd = document.querySelector(
|
|
|
|
'.el-picker-panel__content tr:nth-child(3) td:nth-child(4)'
|
|
|
|
)
|
|
|
|
const timeInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(2) input'
|
|
|
|
)
|
|
|
|
;(someDateTd as HTMLElement).click()
|
|
|
|
;(timeInput as HTMLElement).focus()
|
2021-04-29 15:43:15 +08:00
|
|
|
await nextTick()
|
|
|
|
expect((timeInput as HTMLInputElement).value).toBe('12:24:48')
|
|
|
|
// time spinner highlight is correct
|
2021-09-04 19:29:28 +08:00
|
|
|
const spinners = document.querySelectorAll(
|
2022-03-23 22:58:43 +08:00
|
|
|
'.el-time-spinner ul li.is-active'
|
2021-09-04 19:29:28 +08:00
|
|
|
) as any
|
2021-04-29 15:43:15 +08:00
|
|
|
expect(spinners[0].textContent).toBe('12')
|
|
|
|
expect(spinners[1].textContent).toBe('24')
|
|
|
|
expect(spinners[2].textContent).toBe('48')
|
|
|
|
})
|
2021-11-05 18:19:01 +08:00
|
|
|
|
|
|
|
it('defaultTime only takes effect when time is not selected', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
|
|
|
v-model="value"
|
|
|
|
type="datetime"
|
|
|
|
:default-time="defaultTime"
|
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
defaultTime: new Date(2000, 1, 1, 12, 0, 0),
|
|
|
|
})
|
|
|
|
)
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
|
|
|
const cells = document.querySelectorAll('.available .el-date-table-cell')
|
|
|
|
;(cells[0] as HTMLElement).click()
|
|
|
|
await nextTick()
|
|
|
|
const timeInput = document.querySelector(
|
|
|
|
'.el-date-picker__time-header > span:nth-child(2) input'
|
|
|
|
) as HTMLInputElement
|
|
|
|
expect(timeInput.value).toBe('12:00:00')
|
|
|
|
;(timeInput as HTMLElement).focus()
|
|
|
|
await nextTick()
|
|
|
|
const spinner = document.querySelector(
|
2022-03-23 22:58:43 +08:00
|
|
|
'.el-time-spinner ul li.is-active'
|
2021-11-05 18:19:01 +08:00
|
|
|
) as HTMLElement
|
|
|
|
;(spinner.nextSibling as HTMLElement).click()
|
|
|
|
await nextTick()
|
|
|
|
expect(timeInput.value).toBe('13:00:00')
|
|
|
|
})
|
2020-10-03 20:13:19 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('Datetimerange', () => {
|
|
|
|
it('select daterange and default Time and input format', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
2022-05-27 21:19:42 +08:00
|
|
|
:default-time="new Date(2020, 1, 1, 1, 1, 1)"
|
2020-10-03 20:13:19 +08:00
|
|
|
format="YYYY/MM/DD HH:mm A"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: [new Date(2000, 10, 8, 10, 10), new Date(2000, 10, 11, 10, 10)],
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
|
|
|
const pickers = document.querySelectorAll('.el-date-range-picker__content')
|
|
|
|
const leftCell = pickers[0].querySelector('td.available')
|
|
|
|
const rightCell = pickers[1].querySelector('td.available')
|
|
|
|
triggerEvent(leftCell, 'mousemove', true)
|
|
|
|
triggerEvent(leftCell, 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(rightCell, 'mousemove', true)
|
|
|
|
triggerEvent(rightCell, 'click', true)
|
2021-09-04 19:29:28 +08:00
|
|
|
await nextTick()
|
|
|
|
;(
|
2021-12-28 19:38:23 +08:00
|
|
|
document.querySelectorAll(
|
|
|
|
'.el-picker-panel__footer .el-button'
|
|
|
|
)[1] as HTMLElement
|
2021-09-04 19:29:28 +08:00
|
|
|
).click()
|
2020-10-03 20:13:19 +08:00
|
|
|
await nextTick()
|
|
|
|
const vm = wrapper.vm as any
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(vm.value.map((_) => dayjs(_).format(formatStr))).toStrictEqual([
|
|
|
|
'2000-11-01 01:01:01',
|
|
|
|
'2000-12-01 01:01:01',
|
|
|
|
])
|
|
|
|
const pickerss = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__time-header .el-date-range-picker__editors-wrap'
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const left = {
|
2021-09-04 19:29:28 +08:00
|
|
|
dateInput: pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(1) input'
|
|
|
|
),
|
|
|
|
timeInput: pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(2) input'
|
|
|
|
),
|
2020-10-03 20:13:19 +08:00
|
|
|
}
|
|
|
|
const right = {
|
2021-09-04 19:29:28 +08:00
|
|
|
dateInput: pickerss[1].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(1) input'
|
|
|
|
),
|
|
|
|
timeInput: pickerss[1].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(2) input'
|
|
|
|
),
|
2020-10-03 20:13:19 +08:00
|
|
|
}
|
|
|
|
await nextTick()
|
|
|
|
// both input shows correct value
|
|
|
|
expect((left.dateInput as HTMLInputElement).value).toBe('2000/11/01')
|
|
|
|
expect((left.timeInput as HTMLInputElement).value).toBe('01:01 AM')
|
|
|
|
expect((right.dateInput as HTMLInputElement).value).toBe('2000/12/01')
|
|
|
|
expect((right.timeInput as HTMLInputElement).value).toBe('01:01 AM')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('input date', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const pickerss = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__time-header .el-date-range-picker__editors-wrap'
|
|
|
|
)
|
|
|
|
const leftDateInput = pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(1) input'
|
|
|
|
) as HTMLInputElement
|
|
|
|
const rightDateInput = pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(1) input'
|
|
|
|
) as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
leftDateInput.value = '1999-03-04'
|
|
|
|
triggerEvent(leftDateInput, 'input', true)
|
|
|
|
triggerEvent(leftDateInput, 'change', true)
|
|
|
|
await nextTick()
|
|
|
|
const pickers = document.querySelectorAll('.el-date-range-picker__content')
|
|
|
|
const leftCell = pickers[0].querySelector('td.available')
|
|
|
|
const rightCell = pickers[1].querySelector('td.available')
|
|
|
|
triggerEvent(leftCell, 'mousemove', true)
|
|
|
|
triggerEvent(leftCell, 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(rightCell, 'mousemove', true)
|
|
|
|
triggerEvent(rightCell, 'click', true)
|
|
|
|
await nextTick()
|
2021-12-28 19:38:23 +08:00
|
|
|
const btn = document.querySelectorAll(
|
|
|
|
'.el-picker-panel__footer .el-button'
|
|
|
|
)[1] as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
const vm = wrapper.vm as any
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(vm.value.map((_) => dayjs(_).format(formatStr))).toStrictEqual([
|
|
|
|
'1999-03-01 00:00:00',
|
|
|
|
'1999-04-01 00:00:00',
|
|
|
|
])
|
2020-10-03 20:13:19 +08:00
|
|
|
// input date when minDate > maxDate
|
|
|
|
rightDateInput.value = '1998-01-01'
|
|
|
|
triggerEvent(rightDateInput, 'input', true)
|
|
|
|
triggerEvent(rightDateInput, 'change', true)
|
|
|
|
await nextTick()
|
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
expect(dayjs(vm.value[0]).isBefore(vm.value[1])).toBeTruthy()
|
|
|
|
})
|
|
|
|
|
|
|
|
it('select time', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const timeInput = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__editors-wrap input'
|
|
|
|
)[1] as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
timeInput.blur()
|
|
|
|
timeInput.focus()
|
|
|
|
timeInput.blur()
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const button = document.querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap .el-time-panel .confirm'
|
|
|
|
) as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
button.click()
|
|
|
|
await nextTick()
|
2021-12-28 19:38:23 +08:00
|
|
|
const btn = document.querySelectorAll(
|
|
|
|
'.el-picker-panel__footer .el-button'
|
|
|
|
)[1] as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
expect(vm.value).not.toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('confirm honors disabledDate', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
|
|
|
:disabledDate="disabledDate"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
disabledDate: (date) => {
|
|
|
|
return date.getTime() < new Date(2000, 9, 1) // 2000-10-01
|
|
|
|
},
|
|
|
|
})
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const vm = wrapper.vm as any
|
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
|
|
|
// simulate user input of invalid date
|
2021-09-04 19:29:28 +08:00
|
|
|
const pickerss = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__time-header .el-date-range-picker__editors-wrap'
|
|
|
|
)
|
|
|
|
const leftDateInput = pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(1) input'
|
|
|
|
) as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
leftDateInput.value = '2000-09-01'
|
|
|
|
triggerEvent(leftDateInput, 'input', true)
|
|
|
|
triggerEvent(leftDateInput, 'change', true)
|
|
|
|
await nextTick()
|
2021-12-28 19:38:23 +08:00
|
|
|
const btn = document.querySelectorAll(
|
|
|
|
'.el-picker-panel__footer .el-button'
|
|
|
|
)[1] as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(btn.getAttribute('disabled')).not.toBeUndefined() // invalid input disables button
|
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
const rangePanel = document.querySelector('.el-date-range-picker')
|
|
|
|
expect(rangePanel.getAttribute('visible')).toBe('true') // popper still open
|
|
|
|
expect(vm.value).toBe('')
|
|
|
|
leftDateInput.value = '2001-09-01'
|
|
|
|
triggerEvent(leftDateInput, 'input', true)
|
|
|
|
triggerEvent(leftDateInput, 'change', true)
|
|
|
|
await nextTick()
|
|
|
|
expect(btn.getAttribute('disabled')).not.toBeUndefined()
|
|
|
|
btn.click()
|
|
|
|
await nextTick()
|
|
|
|
expect(rangePanel.getAttribute('visible')).toBe('false') // popper dismiss
|
|
|
|
expect(vm.value).not.toBe('')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('selectableRange', async () => {
|
2021-09-04 19:29:28 +08:00
|
|
|
const disabledHoursArr = [
|
|
|
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 23,
|
|
|
|
]
|
|
|
|
const disabledHoursRightArr = [0, 1, 2]
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2020-10-03 20:13:19 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
|
|
|
:disabledHours="disabledHours"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
}),
|
|
|
|
{
|
|
|
|
methods: {
|
|
|
|
disabledHours(role) {
|
|
|
|
if (role === 'end') {
|
|
|
|
return disabledHoursRightArr
|
|
|
|
}
|
|
|
|
return disabledHoursArr
|
|
|
|
},
|
2020-10-03 20:13:19 +08:00
|
|
|
},
|
2021-09-04 19:29:28 +08:00
|
|
|
}
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const pickerss = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__time-header .el-date-range-picker__editors-wrap'
|
|
|
|
)
|
|
|
|
const leftDateInput = pickerss[0].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(2) input'
|
|
|
|
) as HTMLInputElement
|
|
|
|
const rightDateInput = pickerss[1].querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap:nth-child(2) input'
|
|
|
|
) as HTMLInputElement
|
2020-10-03 20:13:19 +08:00
|
|
|
leftDateInput.blur()
|
|
|
|
leftDateInput.focus()
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const listleft = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__editors-wrap .el-time-spinner__list'
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const hoursEl = listleft[0]
|
2022-03-23 22:58:43 +08:00
|
|
|
const disabledHours = Array.from(
|
|
|
|
hoursEl.querySelectorAll('.is-disabled')
|
|
|
|
).map((node) => Number(node.textContent))
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(disabledHours).toStrictEqual(disabledHoursArr)
|
2021-09-04 19:29:28 +08:00
|
|
|
const button = document.querySelector(
|
|
|
|
'.el-date-range-picker__time-picker-wrap .el-time-panel .confirm'
|
|
|
|
) as HTMLElement
|
2020-10-03 20:13:19 +08:00
|
|
|
button.click()
|
|
|
|
await nextTick()
|
|
|
|
rightDateInput.blur()
|
|
|
|
rightDateInput.focus()
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const listright = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__editors-wrap.is-right .el-time-spinner__list'
|
|
|
|
)
|
2020-10-03 20:13:19 +08:00
|
|
|
const hoursEl2 = listright[0]
|
2022-03-08 14:03:32 +08:00
|
|
|
const disabledHours2 = Array.from(
|
2022-03-23 22:58:43 +08:00
|
|
|
hoursEl2.querySelectorAll('.is-disabled')
|
2022-03-08 14:03:32 +08:00
|
|
|
).map((node) => Number(node.textContent))
|
2020-10-03 20:13:19 +08:00
|
|
|
expect(disabledHours2).toStrictEqual(disabledHoursRightArr)
|
|
|
|
})
|
2021-07-28 20:12:10 +08:00
|
|
|
|
|
|
|
it('select same date, different time', async () => {
|
|
|
|
const leftSelect = ['10', '59', '59']
|
2021-09-04 19:29:28 +08:00
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-date-picker
|
2021-07-28 20:12:10 +08:00
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
2021-09-04 19:29:28 +08:00
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: '',
|
|
|
|
})
|
|
|
|
)
|
2021-07-28 20:12:10 +08:00
|
|
|
const input = wrapper.find('input')
|
|
|
|
input.trigger('blur')
|
|
|
|
input.trigger('focus')
|
|
|
|
await nextTick()
|
|
|
|
const pickers = document.querySelectorAll('.el-date-range-picker__content')
|
|
|
|
const leftCell = pickers[0].querySelector('td.available')
|
|
|
|
triggerEvent(leftCell, 'mousemove', true)
|
|
|
|
triggerEvent(leftCell, 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(leftCell, 'mousemove', true)
|
|
|
|
triggerEvent(leftCell, 'click', true)
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const leftTimeInput = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__editors-wrap input'
|
|
|
|
)[1] as HTMLInputElement
|
2021-07-28 20:12:10 +08:00
|
|
|
leftTimeInput.blur()
|
|
|
|
leftTimeInput.focus()
|
|
|
|
await nextTick()
|
|
|
|
const leftList = document.querySelectorAll('.el-time-spinner__list')
|
|
|
|
triggerEvent(leftList[0].children[+leftSelect[0]], 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(leftList[1].children[+leftSelect[1]], 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(leftList[2].children[+leftSelect[2]], 'click', true)
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
;(
|
|
|
|
document.querySelector('.el-time-panel__btn.confirm') as HTMLElement
|
|
|
|
).click()
|
|
|
|
await nextTick()
|
|
|
|
const rightTimeInput = document.querySelectorAll(
|
|
|
|
'.el-date-range-picker__editors-wrap input'
|
|
|
|
)[3] as HTMLInputElement
|
2021-07-28 20:12:10 +08:00
|
|
|
rightTimeInput.blur()
|
|
|
|
rightTimeInput.focus()
|
|
|
|
await nextTick()
|
2021-09-04 19:29:28 +08:00
|
|
|
const rightList = document.querySelectorAll(
|
|
|
|
'.is-right .el-time-spinner__list'
|
|
|
|
)
|
2021-07-28 20:12:10 +08:00
|
|
|
// auto set left time to right time
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(
|
2022-03-23 22:58:43 +08:00
|
|
|
rightList[0].querySelector('.el-time-spinner__item.is-active').innerHTML
|
2021-09-04 19:29:28 +08:00
|
|
|
).toBe(leftSelect[0])
|
|
|
|
expect(
|
2022-03-23 22:58:43 +08:00
|
|
|
rightList[1].querySelector('.el-time-spinner__item.is-active').innerHTML
|
2021-09-04 19:29:28 +08:00
|
|
|
).toBe(leftSelect[1])
|
|
|
|
expect(
|
2022-03-23 22:58:43 +08:00
|
|
|
rightList[2].querySelector('.el-time-spinner__item.is-active').innerHTML
|
2021-09-04 19:29:28 +08:00
|
|
|
).toBe(leftSelect[2])
|
2021-07-28 20:12:10 +08:00
|
|
|
triggerEvent(rightList[0].children[12], 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(rightList[1].children[12], 'click', true)
|
|
|
|
await nextTick()
|
|
|
|
triggerEvent(rightList[2].children[12], 'click', true)
|
2021-09-04 19:29:28 +08:00
|
|
|
await nextTick()
|
|
|
|
;(
|
|
|
|
document.querySelector(
|
|
|
|
'.is-right .el-time-panel__btn.confirm'
|
|
|
|
) as HTMLElement
|
|
|
|
).click()
|
|
|
|
await nextTick()
|
|
|
|
;(
|
2021-12-28 19:38:23 +08:00
|
|
|
document.querySelectorAll(
|
|
|
|
'.el-picker-panel__footer .el-button'
|
|
|
|
)[1] as HTMLElement
|
2021-09-04 19:29:28 +08:00
|
|
|
).click()
|
2021-07-28 20:12:10 +08:00
|
|
|
await nextTick()
|
|
|
|
const vm = wrapper.vm as any
|
2021-09-04 19:29:28 +08:00
|
|
|
expect(vm.value.map((_) => dayjs(_).format('HH:mm:ss'))).toStrictEqual([
|
|
|
|
'10:59:59',
|
|
|
|
'12:12:12',
|
|
|
|
])
|
2021-07-28 20:12:10 +08:00
|
|
|
})
|
2022-05-05 22:04:32 +08:00
|
|
|
|
|
|
|
describe('form item accessibility integration', () => {
|
|
|
|
it('automatic id attachment', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-form-item label="Foobar" data-test-ref="item">
|
|
|
|
<el-date-picker type="datetime" />
|
|
|
|
</el-form-item>`,
|
|
|
|
() => ({})
|
|
|
|
)
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
const formItemLabel = formItem.find('.el-form-item__label')
|
|
|
|
const datePickerInput = wrapper.find('.el-input__inner')
|
|
|
|
expect(formItem.attributes().role).toBeFalsy()
|
|
|
|
expect(formItemLabel.attributes().for).toBe(
|
|
|
|
datePickerInput.attributes().id
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('specified id attachment', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-form-item label="Foobar" data-test-ref="item">
|
|
|
|
<el-date-picker type="datetime" id="foobar" />
|
|
|
|
</el-form-item>`,
|
|
|
|
() => ({})
|
|
|
|
)
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
const formItemLabel = formItem.find('.el-form-item__label')
|
|
|
|
const datePickerInput = wrapper.find('.el-input__inner')
|
|
|
|
expect(formItem.attributes().role).toBeFalsy()
|
|
|
|
expect(datePickerInput.attributes().id).toBe('foobar')
|
|
|
|
expect(formItemLabel.attributes().for).toBe(
|
|
|
|
datePickerInput.attributes().id
|
|
|
|
)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('form item role is group when multiple inputs', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`<el-form-item label="Foobar" data-test-ref="item">
|
|
|
|
<el-date-picker type="datetime" />
|
|
|
|
<el-date-picker type="datetime" />
|
|
|
|
</el-form-item>`,
|
|
|
|
() => ({})
|
|
|
|
)
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
const formItem = wrapper.find('[data-test-ref="item"]')
|
|
|
|
expect(formItem.attributes().role).toBe('group')
|
|
|
|
})
|
|
|
|
})
|
2022-06-08 11:16:44 +08:00
|
|
|
|
|
|
|
it('display value', async () => {
|
|
|
|
const wrapper = _mount(
|
|
|
|
`
|
|
|
|
<el-date-picker
|
|
|
|
v-model="value"
|
|
|
|
type="datetimerange"
|
|
|
|
/>`,
|
|
|
|
() => ({
|
|
|
|
value: [undefined, undefined],
|
|
|
|
})
|
|
|
|
)
|
|
|
|
|
|
|
|
await nextTick()
|
|
|
|
|
|
|
|
const [startInput, endInput] = wrapper.findAll('input')
|
|
|
|
expect(startInput.element.value).toBe('')
|
|
|
|
expect(endInput.element.value).toBe('')
|
|
|
|
})
|
2020-10-03 20:13:19 +08:00
|
|
|
})
|