123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563 |
- // @ts-nocheck
- import { nextTick } from 'vue'
- import { mount } from '@vue/test-utils'
- import { afterEach, describe, expect, it, vi } from 'vitest'
- import dayjs from 'dayjs'
- import { rAF } from '@element-plus/test-utils/tick'
- import ConfigProvider from '@element-plus/components/config-provider'
- import { CommonPicker } from '@element-plus/components/time-picker'
- import Input from '@element-plus/components/input'
- import zhCn from '@element-plus/locale/lang/zh-cn'
- import enUs from '@element-plus/locale/lang/en'
- import 'dayjs/locale/zh-cn'
- import { EVENT_CODE } from '@element-plus/constants'
- import { ElFormItem } from '@element-plus/components/form'
- import DatePicker from '../src/date-picker'
- const _mount = (template: string, data = () => ({}), otherObj?) =>
- mount(
- {
- components: {
- 'el-date-picker': DatePicker,
- 'el-form-item': ElFormItem,
- },
- template,
- data,
- ...otherObj,
- },
- {
- attachTo: 'body',
- }
- )
- afterEach(() => {
- document.documentElement.innerHTML = ''
- })
- const testDatePickerPanelChange = async (type: 'date' | 'daterange') => {
- let mode
- const wrapper = _mount(
- `<el-date-picker
- type="${type}"
- v-model="value"
- @panel-change="onPanelChange"
- />`,
- () => ({ value: type === 'daterange' ? [] : '' }),
- {
- methods: {
- onPanelChange(value, _mode) {
- mode = _mode
- },
- },
- }
- )
- const reset = () => {
- mode = undefined
- }
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- const prevMonth = document.querySelector<HTMLElement>('button.arrow-left')
- const prevYear = document.querySelector<HTMLElement>('button.d-arrow-left')
- const nextMonth = document.querySelector<HTMLElement>('button.arrow-right')
- const nextYear = document.querySelector<HTMLElement>('button.d-arrow-right')
- prevMonth.click()
- await nextTick()
- expect(mode).toBe('month')
- reset()
- nextMonth.click()
- await nextTick()
- expect(mode).toBe('month')
- reset()
- prevYear.click()
- await nextTick()
- expect(mode).toBe('year')
- reset()
- nextYear.click()
- await nextTick()
- expect(mode).toBe('year')
- }
- describe('DatePicker', () => {
- it('create & custom class & style', async () => {
- const popperClassName = 'popper-class-test'
- const customClassName = 'custom-class-test'
- const wrapper = _mount(
- `<el-date-picker
- :readonly="true"
- placeholder='test_'
- format='HH-mm-ss'
- :style="{color:'red'}"
- :class="customClassName"
- :popperClass="popperClassName"
- />`,
- () => ({ popperClassName, customClassName })
- )
- const input = wrapper.find('input')
- expect(input.attributes('placeholder')).toBe('test_')
- expect(input.attributes('readonly')).not.toBeUndefined()
- const outterInput = wrapper.find('.el-input')
- expect(outterInput.classes()).toContain(customClassName)
- expect(outterInput.attributes().style).toBeDefined()
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(
- document
- .querySelector('.el-picker__popper')
- .classList.contains(popperClassName)
- ).toBe(true)
- })
- it('select date', async () => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const date = dayjs()
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- const spans = document.querySelectorAll('.el-date-picker__header-label')
- const arrowLeftElm = document.querySelector(
- '.el-date-picker__prev-btn .arrow-left'
- ) as HTMLElement
- const arrowRightElm = document.querySelector(
- '.el-date-picker__next-btn .arrow-right'
- ) as HTMLElement
- expect(spans[0].textContent).toContain(date.year())
- expect(spans[1].textContent).toContain(date.format('MMMM'))
- const arrowLeftYeayElm = document.querySelector(
- '.el-date-picker__prev-btn .d-arrow-left'
- ) as HTMLElement
- arrowLeftYeayElm.click()
- let count = 20
- while (--count) {
- arrowLeftElm.click()
- }
- count = 20
- while (--count) {
- arrowRightElm.click()
- }
- await nextTick()
- expect(spans[0].textContent).toContain(date.add(-1, 'year').year())
- expect(spans[1].textContent).toContain(date.format('MMMM'))
- ;(document.querySelector('td.available') as HTMLElement).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value).toBeDefined()
- })
- it('defaultTime and clear value', async () => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- :default-time="new Date(2011,1,1,12,0,1)"
- />`,
- () => ({ value: '' })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- ;(document.querySelector('td.available') as HTMLElement).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value).toBeDefined()
- expect(vm.value.getHours()).toBe(12)
- expect(vm.value.getMinutes()).toBe(0)
- expect(vm.value.getSeconds()).toBe(1)
- const picker = wrapper.findComponent(CommonPicker)
- ;(picker.vm as any).showClose = true
- await nextTick()
- ;(document.querySelector('.clear-icon') as HTMLElement).click()
- expect(vm.value).toBeNull()
- })
- it('defaultValue', async () => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- :default-value="defaultValue"
- />`,
- () => ({
- value: '',
- defaultValue: new Date(2011, 10, 1),
- })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- document.querySelector<HTMLElement>('td.available').click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value).toBeDefined()
- expect(vm.value.getFullYear()).toBe(2011)
- expect(vm.value.getMonth()).toBe(10)
- expect(vm.value.getDate()).toBe(1)
- const picker = wrapper.findComponent(CommonPicker)
- ;(picker.vm as any).showClose = true
- await nextTick()
- document.querySelector<HTMLElement>('.clear-icon').click()
- expect(vm.value).toBeNull()
- vm.defaultValue = new Date(2031, 5, 1)
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- document.querySelector<HTMLElement>('td.available').click()
- await nextTick()
- expect(vm.value).toBeDefined()
- expect(vm.value.getFullYear()).toBe(2031)
- expect(vm.value.getMonth()).toBe(5)
- expect(vm.value.getDate()).toBe(1)
- })
- it('event change, focus, blur, keydown', async () => {
- const changeHandler = vi.fn()
- const focusHandler = vi.fn()
- const blurHandler = vi.fn()
- const keydownHandler = vi.fn()
- let onChangeValue: Date | undefined
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- @change="onChange"
- @focus="onFocus"
- @blur="onBlur"
- @keydown="onKeydown"
- />`,
- () => ({ value: new Date(2016, 9, 10, 18, 40) }),
- {
- methods: {
- onChange(e) {
- onChangeValue = e
- return changeHandler(e)
- },
- onFocus(e) {
- return focusHandler(e)
- },
- onBlur(e) {
- return blurHandler(e)
- },
- onKeydown(e) {
- return keydownHandler(e)
- },
- },
- }
- )
- const input = wrapper.find('input')
- input.trigger('focus')
- input.trigger('blur')
- input.trigger('keydown')
- await nextTick()
- await rAF()
- expect(focusHandler).toHaveBeenCalledTimes(1)
- expect(blurHandler).toHaveBeenCalledTimes(1)
- expect(keydownHandler).toHaveBeenCalledTimes(1)
- input.trigger('focus')
- await nextTick()
- ;(document.querySelector('td.available') as HTMLElement).click()
- await nextTick()
- await rAF()
- expect(changeHandler).toHaveBeenCalledTimes(1)
- expect(onChangeValue?.getTime()).toBe(new Date(2016, 9, 1).getTime())
- })
- it('emits focus on click when not currently focused', async () => {
- const focusHandler = vi.fn()
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- @focus="onFocus"
- />`,
- () => ({ value: new Date(2016, 9, 10, 18, 40) }),
- {
- methods: {
- onFocus(e: Event) {
- return focusHandler(e)
- },
- },
- }
- )
- const input = wrapper.find('input')
- input.trigger('mousedown')
- input.trigger('focus')
- await nextTick()
- await rAF()
- expect(focusHandler).toHaveBeenCalledTimes(1)
- })
- it('opens popper on click when input is focused', async () => {
- const wrapper = _mount(`<el-date-picker v-model="value" />`, () => ({
- value: new Date(2016, 9, 10, 18, 40),
- }))
- const popperEl = document.querySelector('.el-picker__popper') as HTMLElement
- expect(popperEl.style.display).toBe('none')
- const input = wrapper.find('input')
- input.element.focus()
- input.trigger('mousedown')
- await nextTick()
- await rAF()
- expect(popperEl.style.display).not.toBe('none')
- })
- it('shortcuts', async () => {
- const text = 'Yesterday'
- const value = new Date(Date.now() - 86400000)
- value.setHours(0, 0, 0, 0)
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- :shortcuts="shortcuts"
- />`,
- () => ({
- value: '',
- shortcuts: [
- {
- text,
- value,
- },
- ],
- })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- const shortcut = document.querySelector('.el-picker-panel__shortcut')
- expect(shortcut.textContent).toBe(text)
- expect(document.querySelector('.el-picker-panel__sidebar')).not.toBeNull()
- ;(shortcut as HTMLElement).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value.valueOf()).toBe(value.valueOf())
- })
- it('disabledDate', async () => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- :disabledDate="disabledDate"
- />`,
- () => ({
- value: '',
- disabledDate(time) {
- return time.getTime() < Date.now() - 8.64e7
- },
- })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(document.querySelector('.disabled')).not.toBeNull()
- })
- it('ref focus', async () => {
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input"
- />`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.focus()
- },
- }
- )
- await nextTick()
- await rAF()
- const popperEl = document.querySelector('.el-picker__popper')
- const attr = popperEl.getAttribute('aria-hidden')
- expect(attr).toEqual('false')
- })
- it('ref handleOpen', async () => {
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input"
- />`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.handleOpen()
- },
- }
- )
- await nextTick()
- const popperEl = document.querySelector('.el-picker__popper')
- const attr = popperEl.getAttribute('aria-hidden')
- expect(attr).toEqual('false')
- })
- it('ref handleClose', async () => {
- vi.useFakeTimers()
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input"
- />`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.handleOpen()
- setTimeout(() => {
- this.$refs.input.handleClose()
- }, 1000000)
- },
- }
- )
- vi.runAllTimers()
- await nextTick()
- const popperEl = document.querySelector('.el-picker__popper')
- const attr = popperEl.getAttribute('aria-hidden')
- expect(attr).toEqual('true')
- vi.useRealTimers()
- })
- it('custom content', async () => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- ref="input">
- <template #default="{ isCurrent, text }">
- <div class="cell" :class="{ current: isCurrent }">
- <div>{{ text }}</div>
- </div>
- </template>
- </el-date-picker>`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.focus()
- },
- }
- )
- await nextTick()
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- {
- ;(document.querySelector('td.available .cell') as HTMLElement).click()
- }
- input.trigger('focus')
- await nextTick()
- expect(
- document.querySelector('td.available .cell').classList.contains('current')
- ).toBeTruthy()
- })
- it('custom content comment', async () => {
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input">
- <template #default="{ isCurrent, text }">
- <!-- <div class="cell" :class="{ current: isCurrent }">
- <div>{{ text + "csw" }}</div>
- </div> -->
- </template>
- </el-date-picker>`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.focus()
- },
- }
- )
- await nextTick()
- const el = document.querySelector('td.available .el-date-table-cell')
- const text = el.textContent
- expect(text.includes('csw')).toBeFalsy()
- })
- it('custom content value validate', async () => {
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input">
- <template #default="{ isCurrent, text }">
- <div class="cell" :class="{ current: isCurrent }">
- <div>{{ text + "csw" }}</div>
- </div>
- </template>
- </el-date-picker>`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.focus()
- },
- }
- )
- await nextTick()
- const el = document.querySelector('td.available .cell')
- const text = el.textContent
- expect(text.includes('csw')).toBeTruthy()
- })
- it('custom content bail out slot compoent', async () => {
- _mount(
- `<el-date-picker
- v-model="value"
- ref="input">
- <slot name="testest"></slot>
- </el-date-picker>`,
- () => ({ value: '' }),
- {
- mounted() {
- this.$refs.input.focus()
- },
- }
- )
- await nextTick()
- const el = document.querySelector<HTMLElement>('td.available')
- const text = el.textContent
- expect(!!text).toBeTruthy()
- })
- describe('value-format', () => {
- it('with literal string', async () => {
- const day = dayjs()
- const format = 'YYYY-MM-DD'
- const valueFormat = '[Element-Plus] DD/MM YYYY'
- const value = day.format(valueFormat)
- const wrapper = _mount(
- `
- <el-date-picker
- ref="compo"
- v-model="value"
- type="date"
- format="${format}"
- value-format="${valueFormat}" />
- <button @click="changeValue">click</button>
- `,
- () => {
- return {
- value,
- }
- },
- {
- methods: {
- changeValue() {
- this.value = '[Element-Plus] 31/05 2021'
- },
- },
- }
- )
- const vm = wrapper.vm as any
- const input = wrapper.find('input')
- await input.trigger('blur')
- await input.trigger('focus')
- await nextTick()
- {
- ;(document.querySelector('td.available') as HTMLElement).click()
- }
- await nextTick()
- expect(vm.value).toBe(
- dayjs(
- `[Element-Plus] 01/${`0${day.month() + 1}`.slice(-2)} ${day.year()}`,
- valueFormat
- ).format(valueFormat)
- )
- await wrapper.find('button').trigger('click')
- await nextTick()
- expect(wrapper.findComponent(Input).vm.modelValue).toBe('2021-05-31')
- })
- it('with "x"', async () => {
- const format = 'YYYY/MM/DD'
- const dateStr = '2021/05/31'
- const valueFormat = 'x'
- const value = Date.now()
- const wrapper = _mount(
- `
- <el-date-picker
- ref="compo"
- v-model="value"
- type="date"
- format="${format}"
- value-format="${valueFormat}" />
- <button @click="changeValue">click</button>
- `,
- () => {
- return {
- value,
- }
- },
- {
- methods: {
- changeValue() {
- this.value = +new Date(dateStr)
- },
- },
- }
- )
- const vm = wrapper.vm as any
- const input = wrapper.find('input')
- await input.trigger('blur')
- await input.trigger('focus')
- await nextTick()
- ;(document.querySelector('td.available') as HTMLElement).click()
- await nextTick()
- expect(vm.value).toBe(+dayjs().startOf('M'))
- await wrapper.find('button').trigger('click')
- await nextTick()
- expect(wrapper.findComponent(Input).vm.modelValue).toBe(dateStr)
- })
- })
- })
- describe('DatePicker Navigation', () => {
- let prevMonth, prevYear, nextMonth, nextYear, getYearLabel, getMonthLabel
- const initNavigationTest = async (value) => {
- const wrapper = _mount(
- `<el-date-picker
- v-model="value"
- />`,
- () => ({ value })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- prevMonth = document.querySelector('button.arrow-left')
- prevYear = document.querySelector('button.d-arrow-left')
- nextMonth = document.querySelector('button.arrow-right')
- nextYear = document.querySelector('button.d-arrow-right')
- getYearLabel = () =>
- document.querySelectorAll('.el-date-picker__header-label')[0].textContent
- getMonthLabel = () =>
- document.querySelectorAll('.el-date-picker__header-label')[1].textContent
- }
- it('month, year', async () => {
- await initNavigationTest(new Date(2000, 0, 1))
- expect(getYearLabel()).toContain('2000')
- expect(getMonthLabel()).toContain('January')
- prevMonth.click()
- await nextTick()
- expect(getYearLabel()).toContain('1999')
- expect(getMonthLabel()).toContain('December')
- prevYear.click()
- await nextTick()
- expect(getYearLabel()).toContain('1998')
- expect(getMonthLabel()).toContain('December')
- nextMonth.click()
- await nextTick()
- expect(getYearLabel()).toContain('1999')
- expect(getMonthLabel()).toContain('January')
- nextYear.click()
- await nextTick()
- expect(getYearLabel()).toContain('2000')
- expect(getMonthLabel()).toContain('January')
- })
- it('month with fewer dates', async () => {
- // July has 31 days, June has 30
- await initNavigationTest(new Date(2000, 6, 31))
- prevMonth.click()
- await nextTick()
- expect(getYearLabel()).toContain('2000')
- expect(getMonthLabel()).toContain('June')
- })
- it('year with fewer Feburary dates', async () => {
- // Feburary 2008 has 29 days, Feburary 2007 has 28
- await initNavigationTest(new Date(2008, 1, 29))
- prevYear.click()
- await nextTick()
- expect(getYearLabel()).toContain('2007')
- expect(getMonthLabel()).toContain('February')
- })
- it('month label with fewer dates', async () => {
- await initNavigationTest(new Date(2000, 6, 31))
- const yearLabel = document.querySelectorAll(
- '.el-date-picker__header-label'
- )[0]
- ;(yearLabel as HTMLElement).click()
- await nextTick()
- const year1999Label = document.querySelectorAll('.el-year-table td')[1]
- ;(year1999Label as HTMLElement).click()
- await nextTick()
- const juneLabel = document.querySelectorAll('.el-month-table td')[5]
- ;(juneLabel as HTMLElement).click()
- await nextTick()
- expect(getYearLabel()).toContain('2001')
- expect(getMonthLabel()).toContain('June')
- const monthLabel = document.querySelectorAll(
- '.el-date-picker__header-label'
- )[1]
- ;(monthLabel as HTMLElement).click()
- await nextTick()
- const janLabel = document.querySelectorAll('.el-month-table td')[0]
- ;(janLabel as HTMLElement).click()
- await nextTick()
- expect(getYearLabel()).toContain('2001')
- expect(getMonthLabel()).toContain('January')
- })
- it('panel change event', async () => {
- await testDatePickerPanelChange('date')
- })
- })
- describe('MonthPicker', () => {
- it('basic', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='month'
- v-model="value"
- />`,
- () => ({ value: new Date(2020, 7, 1) })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(
- (document.querySelector('.el-month-table') as HTMLElement).style.display
- ).toBe('')
- expect(document.querySelector('.el-year-table')).toBeNull()
- ;(document.querySelector('.el-month-table .cell') as HTMLElement).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value.getMonth()).toBe(0)
- })
- it('value-format', async () => {
- const valueFormat = '[Element-Plus] YYYY.MM'
- const wrapper = _mount(
- `
- <el-date-picker
- type="month"
- v-model="value"
- value-format="${valueFormat}"
- ></el-date-picker>
- `,
- () => ({ value: dayjs(new Date(2020, 7, 1)).format(valueFormat) })
- )
- await nextTick()
- expect(wrapper.findComponent(Input).vm.modelValue).toBe('2020-08')
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- {
- ;(document.querySelector('.el-month-table .cell') as HTMLElement).click()
- }
- await nextTick()
- expect(wrapper.findComponent(Input).vm.modelValue).toBe('2020-01')
- expect((wrapper.vm as any).value).toBe(
- dayjs(new Date(2020, 0, 1)).format(valueFormat)
- )
- })
- })
- describe('YearPicker', () => {
- it('basic', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='year'
- v-model="value"
- />`,
- () => ({ value: new Date(2020, 7, 1) })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(
- (document.querySelector('.el-year-table') as HTMLElement).style.display
- ).toBe('')
- expect(document.querySelector('.el-month-table')).toBeNull()
- const leftBtn = document.querySelector('.d-arrow-left') as HTMLElement
- const rightBtn = document.querySelector('.d-arrow-right') as HTMLElement
- let count = 2
- while (--count) {
- leftBtn.click()
- }
- count = 3
- while (--count) {
- rightBtn.click()
- }
- await nextTick()
- ;(document.querySelector('.el-year-table .cell') as HTMLElement).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value.getFullYear()).toBe(2030)
- })
- it('value-format', async () => {
- const valueFormat = '[Element-Plus] YYYY'
- const wrapper = _mount(
- `
- <el-date-picker
- type="year"
- v-model="value"
- value-format="${valueFormat}"
- ></el-date-picker>
- `,
- () => ({ value: dayjs(new Date(2005, 7, 1)).format(valueFormat) })
- )
- await nextTick()
- expect(wrapper.findComponent(Input).vm.modelValue).toBe('2005')
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- const cell = document.querySelector('.el-year-table .cell') as HTMLElement
- cell.click()
- await nextTick()
- expect((wrapper.vm as any).value).toBe(
- dayjs(new Date(Number.parseInt(cell.innerHTML.trim()), 0, 1)).format(
- valueFormat
- )
- )
- })
- })
- describe('WeekPicker', () => {
- it('create', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='week'
- v-model="value"
- />`,
- () => ({ value: new Date(2020, 7, 15) })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(document.querySelector('.is-week-mode')).not.toBeNull()
- // select month still is in week-mode
- ;(
- document.querySelectorAll(
- '.el-date-picker__header-label'
- )[1] as HTMLElement
- ).click()
- await nextTick()
- ;(
- document.querySelectorAll('.el-month-table .cell')[7] as HTMLElement
- ).click()
- await nextTick()
- expect(document.querySelector('.is-week-mode')).not.toBeNull()
- const numberOfHighlightRows = () =>
- document.querySelectorAll('.el-date-table__row.current').length
- ;(
- document.querySelector(
- '.el-date-table__row ~ .el-date-table__row td.available'
- ) as HTMLElement
- ).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value).not.toBeNull()
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- expect(numberOfHighlightRows()).toBe(1)
- // test: next month should not have highlight
- ;(document.querySelector('.arrow-right') as HTMLElement).click()
- await nextTick()
- expect(numberOfHighlightRows()).toBe(0)
- // test: next year should not have highlight
- ;(document.querySelector('.arrow-left') as HTMLElement).click()
- await nextTick()
- ;(document.querySelector('.d-arrow-right') as HTMLElement).click()
- await nextTick()
- expect(numberOfHighlightRows()).toBe(0)
- })
- ;[
- { locale: enUs, name: 'Sunday', value: 0 },
- { locale: zhCn, name: 'Monday', value: 1 },
- ].forEach((loObj) => {
- it(`emit first day of the week, ${loObj.locale.name} locale, ${loObj.name}`, async () => {
- const wrapper = mount(
- {
- components: {
- 'el-date-picker': DatePicker,
- 'el-config-provider': ConfigProvider,
- },
- template: `
- <el-config-provider :locale="locale">
- <el-date-picker
- type='week'
- v-model="value"
- />
- </el-config-provider>
- `,
- data() {
- return {
- locale: loObj.locale,
- value: '',
- }
- },
- },
- {
- attachTo: 'body',
- }
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- // click Wednesday
- ;(
- document.querySelectorAll(
- '.el-date-table__row ~ .el-date-table__row td'
- )[3] as HTMLElement
- ).click()
- await nextTick()
- const vm = wrapper.vm as any
- expect(vm.value).not.toBeNull()
- expect(+dayjs(vm.value).locale(loObj.locale.name)).toBe(
- +dayjs(vm.value).locale(loObj.locale.name).startOf('week')
- )
- expect(dayjs(vm.value).locale(loObj.locale.name).day()).toBe(loObj.value) // Sunday or Monday
- })
- })
- })
- describe('DatePicker dates', () => {
- it('create', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='dates'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const input = wrapper.find('input')
- input.trigger('blur')
- input.trigger('focus')
- await nextTick()
- const td = document.querySelectorAll(
- '.el-date-table__row .available'
- ) as NodeListOf<HTMLElement>
- const vm = wrapper.vm as any
- td[0].click()
- await nextTick()
- expect(vm.value.length).toBe(1)
- td[1].click()
- await nextTick()
- expect(vm.value.length).toBe(2)
- expect(
- document.querySelectorAll('.el-date-table__row .selected').length
- ).toBe(2)
- td[0].click()
- await nextTick()
- expect(vm.value.length).toBe(1)
- td[1].click()
- await nextTick()
- expect(vm.value.length).toBe(0)
- })
- })
- describe('DatePicker keyboard events', () => {
- it('enter', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='date'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const input = wrapper.find('.el-input__inner')
- await input.trigger('focus')
- await input.trigger('click')
- await nextTick()
- const popperEl = document.querySelectorAll('.el-picker__popper')[0]
- const attr = popperEl.getAttribute('aria-hidden')
- expect(attr).toEqual('false')
- await input.trigger('keydown', {
- code: EVENT_CODE.enter,
- })
- const popperEl2 = document.querySelectorAll('.el-picker__popper')[0]
- const attr2 = popperEl2.getAttribute('aria-hidden')
- expect(attr2).toEqual('true')
- })
- it('numpadEnter', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='date'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const input = wrapper.find('.el-input__inner')
- await input.trigger('focus')
- await input.trigger('click')
- await nextTick()
- const popperEl = document.querySelectorAll('.el-picker__popper')[0]
- const attr = popperEl.getAttribute('aria-hidden')
- expect(attr).toEqual('false')
- await input.trigger('keydown', {
- code: EVENT_CODE.numpadEnter,
- })
- const popperEl2 = document.querySelectorAll('.el-picker__popper')[0]
- const attr2 = popperEl2.getAttribute('aria-hidden')
- expect(attr2).toEqual('true')
- })
- })
- describe('DateRangePicker', () => {
- it('create & custom class & style', async () => {
- let calendarChangeValue = null
- const changeHandler = vi.fn()
- const popperClassName = 'popper-class-test'
- const customClassName = 'custom-class-test'
- const wrapper = _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- @calendarChange="onCalendarChange"
- :style="{color:'red'}"
- :class="customClassName"
- :popperClass="popperClassName"
- />`,
- () => ({ value: '', popperClassName, customClassName }),
- {
- methods: {
- onCalendarChange(e) {
- calendarChangeValue = e
- changeHandler(e)
- },
- },
- }
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const outterInput = wrapper.find('.el-range-editor.el-input__wrapper')
- expect(outterInput.classes()).toContain(customClassName)
- expect(outterInput.attributes().style).toBeDefined()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- expect(panels.length).toBe(2)
- ;(panels[0].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- ;(panels[1].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- // popperClassName
- expect(
- document
- .querySelector('.el-picker__popper')
- .classList.contains(popperClassName)
- ).toBe(true)
- // correct highlight
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- expect(inRangeDate.length).toBeGreaterThan(28)
- // value is array
- const vm = wrapper.vm as any
- expect(Array.isArray(vm.value)).toBeTruthy()
- // input text is something like date string
- expect(inputs[0].element.value.length).toBe(10)
- expect(inputs[1].element.value.length).toBe(10)
- // calendar-change event
- expect(changeHandler).toHaveBeenCalledTimes(2)
- expect(calendarChangeValue.length).toBe(2)
- expect(calendarChangeValue[0]).toBeInstanceOf(Date)
- expect(calendarChangeValue[1]).toBeInstanceOf(Date)
- })
- it('reverse selection', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- ;(panels[1].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- ;(panels[0].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- // correct highlight
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- expect(inRangeDate.length).toBeGreaterThan(28)
- const vm = wrapper.vm as any
- expect(vm.value[0].getTime() < vm.value[1].getTime()).toBeTruthy()
- })
- it('reset selection', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- ;(panels[1].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- ;(panels[0].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- ;(wrapper.vm as any).value = ''
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(inRangeDate.length).toBe(0)
- })
- it('range, start-date and end-date', async () => {
- _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const table = document.querySelector('.el-date-table')
- const availableTds = (table as HTMLTableElement).querySelectorAll(
- 'td.available'
- )
- ;(availableTds[0] as HTMLElement).click()
- await nextTick()
- ;(availableTds[1] as HTMLElement).click()
- await nextTick()
- expect(availableTds[0].classList.contains('in-range')).toBeTruthy()
- expect(availableTds[0].classList.contains('start-date')).toBeTruthy()
- expect(availableTds[1].classList.contains('in-range')).toBeTruthy()
- expect(availableTds[1].classList.contains('end-date')).toBeTruthy()
- ;(availableTds[1] as HTMLElement).click()
- await nextTick()
- ;(availableTds[0] as HTMLElement).click()
- await nextTick()
- expect(availableTds[0].classList.contains('in-range')).toBeTruthy()
- expect(availableTds[0].classList.contains('start-date')).toBeTruthy()
- expect(availableTds[1].classList.contains('in-range')).toBeTruthy()
- expect(availableTds[1].classList.contains('end-date')).toBeTruthy()
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- expect(inRangeDate.length).toBe(2)
- })
- it('unlink:true', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- unlink-panels
- />`,
- () => ({ value: [new Date(2000, 9, 1), new Date(2000, 11, 2)] })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- const left = panels[0].querySelector('.el-date-range-picker__header')
- const right = panels[1].querySelector(
- '.is-right .el-date-range-picker__header'
- )
- expect(left.textContent).toBe('2000 October')
- expect(right.textContent).toBe('2000 December')
- ;(panels[1].querySelector('.d-arrow-right') as HTMLElement).click()
- await nextTick()
- ;(panels[1].querySelector('.arrow-right') as HTMLElement).click()
- await nextTick()
- expect(left.textContent).toBe('2000 October')
- expect(right.textContent).toBe('2002 January')
- })
- it('daylight saving time highlight', async () => {
- // Run test with environment variable TZ=Australia/Sydney
- // The following test uses Australian Eastern Daylight Time (AEDT)
- // AEST -> AEDT shift happened on 2016-10-02 02:00:00
- const wrapper = _mount(
- `<el-date-picker
- type='daterange'
- v-model="value"
- unlink-panels
- />`,
- () => ({ value: [new Date(2016, 9, 1), new Date(2016, 9, 3)] })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- })
- it('value-format', async () => {
- const valueFormat = 'DD/MM YYYY'
- const wrapper = _mount(
- `
- <el-date-picker
- v-model="value"
- type="daterange"
- format="YYYY-MM-DD"
- value-format="${valueFormat}"
- />`,
- () => ({
- value: [
- dayjs(new Date(2021, 4, 2)).format(valueFormat),
- dayjs(new Date(2021, 4, 12)).format(valueFormat),
- ],
- })
- )
- await nextTick()
- const [startInput, endInput] = wrapper.findAll('input')
- expect(startInput.element.value).toBe('2021-05-02')
- expect(endInput.element.value).toBe('2021-05-12')
- startInput.trigger('blur')
- startInput.trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- expect(panels.length).toBe(2)
- ;(panels[0].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- ;(panels[1].querySelector('td.available') as HTMLElement).click()
- await nextTick()
- expect((wrapper.vm as any).value.toString()).toBe(
- ['01/05 2021', '01/06 2021'].toString()
- )
- })
- it('panel change event', async () => {
- await testDatePickerPanelChange('daterange')
- })
- it('display value', async () => {
- const wrapper = _mount(
- `
- <el-date-picker
- v-model="value"
- type="daterange"
- />`,
- () => ({
- value: [undefined, undefined],
- })
- )
- await nextTick()
- const [startInput, endInput] = wrapper.findAll('input')
- expect(startInput.element.value).toBe('')
- expect(endInput.element.value).toBe('')
- })
- })
- describe('MonthRange', () => {
- it('works', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='monthrange'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- expect(panels.length).toBe(2)
- const p0 = <HTMLElement>panels[0].querySelector('td:not(.disabled)')
- p0.click()
- await nextTick()
- const p1 = <HTMLElement>panels[1].querySelector('td:not(.disabled)')
- p1.click()
- await nextTick()
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- // correct highlight
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- expect(inRangeDate.length).toBeGreaterThan(0)
- // value is array
- const vm = wrapper.vm as any
- expect(Array.isArray(vm.value)).toBeTruthy()
- // input text is something like date string
- expect(inputs[0].element.value.length).toBe(7)
- expect(inputs[1].element.value.length).toBe(7)
- // reverse selection
- p1.click()
- await nextTick()
- p0.click()
- await nextTick()
- expect(vm.value[0].getTime() < vm.value[1].getTime()).toBeTruthy()
- })
- it('range, start-date and end-date', async () => {
- _mount(
- `<el-date-picker
- type='monthrange'
- v-model="value"
- />`,
- () => ({ value: '' })
- )
- const table = document.querySelector('.el-month-table')
- const tds = (table as HTMLTableElement).querySelectorAll('td')
- ;(tds[0] as HTMLElement).click()
- await nextTick()
- ;(tds[1] as HTMLElement).click()
- await nextTick()
- expect(tds[0].classList.contains('in-range')).toBeTruthy()
- expect(tds[0].classList.contains('start-date')).toBeTruthy()
- expect(tds[1].classList.contains('in-range')).toBeTruthy()
- expect(tds[1].classList.contains('end-date')).toBeTruthy()
- ;(tds[1] as HTMLElement).click()
- await nextTick()
- ;(tds[0] as HTMLElement).click()
- await nextTick()
- expect(tds[0].classList.contains('in-range')).toBeTruthy()
- expect(tds[0].classList.contains('start-date')).toBeTruthy()
- expect(tds[1].classList.contains('in-range')).toBeTruthy()
- expect(tds[1].classList.contains('end-date')).toBeTruthy()
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- const inRangeDate = document.querySelectorAll('.in-range')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- expect(inRangeDate.length).toBe(2)
- })
- it('type:monthrange unlink:true', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='monthrange'
- v-model="value"
- unlink-panels
- />`,
- () => ({ value: [new Date(2000, 9), new Date(2002, 11)] })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const panels = document.querySelectorAll('.el-date-range-picker__content')
- const left = panels[0].querySelector('.el-date-range-picker__header')
- const right = panels[1].querySelector(
- '.is-right .el-date-range-picker__header'
- )
- expect(left.textContent).toContain(2000)
- expect(right.textContent).toContain(2002)
- ;(panels[1].querySelector('.d-arrow-right') as HTMLElement).click()
- await nextTick()
- expect(left.textContent).toContain(2000)
- expect(right.textContent).toContain(2003)
- })
- it('daylight saving time highlight', async () => {
- const wrapper = _mount(
- `<el-date-picker
- type='monthrange'
- v-model="value"
- unlink-panels
- />`,
- () => ({ value: [new Date(2016, 6), new Date(2016, 12)] })
- )
- const inputs = wrapper.findAll('input')
- inputs[0].trigger('blur')
- inputs[0].trigger('focus')
- await nextTick()
- const startDate = document.querySelectorAll('.start-date')
- const endDate = document.querySelectorAll('.end-date')
- expect(startDate.length).toBe(1)
- expect(endDate.length).toBe(1)
- })
- it('should accept popper options and pass down', async () => {
- const ElPopperOptions = {
- strategy: 'fixed',
- }
- const wrapper = _mount(
- `<el-date-picker
- type='monthrange'
- v-model="value"
- :popper-options="options"
- unlink-panels
- />`,
- () => ({
- value: [new Date(2016, 6), new Date(2016, 12)],
- options: ElPopperOptions,
- }),
- {
- provide() {
- return {
- ElPopperOptions,
- }
- },
- }
- )
- await nextTick()
- expect(
- (wrapper.findComponent(CommonPicker).vm as any).elPopperOptions
- ).toEqual(ElPopperOptions)
- })
- 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 />
- </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 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 />
- <el-date-picker />
- </el-form-item>`,
- () => ({})
- )
- await nextTick()
- const formItem = wrapper.find('[data-test-ref="item"]')
- expect(formItem.attributes().role).toBe('group')
- })
- })
- it('The year which is disabled should not be selectable', async () => {
- const pickHandler = vi.fn()
- const wrapper = _mount(
- `<el-date-picker
- v-model="yearValue"
- type="year"
- :disabled-date="validateYear"
- @panel-change="onPick"
- />`,
- () => ({
- yearValue: '2022',
- validateYear: (date) => {
- if (date.getFullYear() > 2022) {
- return true
- } else {
- return false
- }
- },
- onPick(e) {
- return pickHandler(e)
- },
- })
- )
- const input = wrapper.find('input')
- input.trigger('focus')
- await nextTick()
- ;(document.querySelector('td.disabled') as HTMLElement).click()
- await nextTick()
- expect(pickHandler).toHaveBeenCalledTimes(0)
- ;(document.querySelector('td.available') as HTMLElement).click()
- await nextTick()
- expect(pickHandler).toHaveBeenCalledTimes(1)
- })
- })
|