diff --git a/packages/time-select/__tests__/time-select.spec.ts b/packages/time-select/__tests__/time-select.spec.ts new file mode 100644 index 0000000000..1340e8402d --- /dev/null +++ b/packages/time-select/__tests__/time-select.spec.ts @@ -0,0 +1,69 @@ +import { mount } from '@vue/test-utils' +import { nextTick } from 'vue' +import TimeSelect from '../src/time-select.vue' + +const _mount = (template: string, data, otherObj?) => mount({ + components: { + 'el-time-select': TimeSelect, + }, + template, + data, + ...otherObj, +},{ + attachTo: 'body', +}) + +afterEach(() => { + document.documentElement.innerHTML = '' +}) + +describe('TimeSelect', () => { + it('create', async () => { + const wrapper = _mount(``, () => ({ + readonly: true })) + const outterInput = wrapper.find('.el-select') + expect(outterInput.classes()).toContain('customClass') + expect(outterInput.attributes().style).toBeDefined() + }) + + it('set default value', async () => { + const wrapper = _mount(``, () => ({ value: '14:30' })) + const input = wrapper.find('input') + input.trigger('blur') + input.trigger('focus') + await nextTick() + expect(document.querySelector('.selected')).toBeDefined() + expect(document.querySelector('.selected').textContent).toBe('14:30') + }) + + it('set minTime', async () => { + const wrapper = _mount(``, () => ({})) + const input = wrapper.find('input') + input.trigger('blur') + input.trigger('focus') + await nextTick() + const elms = document.querySelectorAll('.is-disabled') + const elm = elms[elms.length - 1] + expect(elm.textContent).toBe('14:30') + }) + + it('set maxTime', async () => { + const wrapper = _mount(``, () => ({})) + const input = wrapper.find('input') + input.trigger('blur') + input.trigger('focus') + await nextTick() + const elm = document.querySelector('.is-disabled') + expect(elm.textContent).toBe('14:30') + }) +}) + diff --git a/packages/time-select/src/time-select.vue b/packages/time-select/src/time-select.vue index 996fa2a1f5..79c996426f 100644 --- a/packages/time-select/src/time-select.vue +++ b/packages/time-select/src/time-select.vue @@ -33,11 +33,12 @@