import {
createTest,
createVue,
destroyVM,
triggerEvent,
wait
} from '../util';
import DatePicker from 'packages/date-picker';
const DELAY = 50;
const LEFT = 37;
const ENTER = 13;
const TAB = 9;
const keyDown = (el, keyCode) => {
const evt = document.createEvent('Events');
evt.initEvent('keydown', true, true);
evt.keyCode = keyCode;
el.dispatchEvent(evt);
};
describe('DatePicker', () => {
let vm;
afterEach(() => { destroyVM(vm); });
it('create', () => {
vm = createTest(DatePicker, {
readonly: true,
placeholder: '23333',
format: 'HH-mm-ss'
}, true);
const input = vm.$el.querySelector('input');
expect(input.getAttribute('placeholder')).to.equal('23333');
expect(input.getAttribute('readonly')).to.equal('readonly');
});
it('select date', done => {
vm = createVue({
template: `
<el-date-picker ref="compo" v-model="value"></el-date-picker>
`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
const date = new Date();
input.blur();
input.focus();
setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el;
const spans = $el.querySelectorAll('.el-date-picker__header-label');
const arrowLeftElm = $el.querySelector('.el-date-picker__prev-btn.el-icon-arrow-left');
const arrowRightElm = $el.querySelector('.el-date-picker__next-btn.el-icon-arrow-right');
expect(spans[0].textContent).to.include(date.getFullYear());
expect(spans[1].textContent).to.include(date.getMonth() + 1);
$el.querySelector('.el-date-picker__prev-btn.el-icon-d-arrow-left').click();
let count = 20;
while (--count) {
arrowLeftElm.click();
}
count = 20;
while (--count) {
arrowRightElm.click();
}
setTimeout(_ => {
expect(spans[0].textContent).to.include(date.getFullYear() - 1);
expect(spans[1].textContent).to.include(date.getMonth() + 1);
$el.querySelector('td.available').click();
vm.$nextTick(_ => {
expect(vm.value).to.exist;
});
done();
}, DELAY);
}, DELAY);
});
it('clear value', done => {
vm = createVue({
template: `
<el-date-picker v-model="value" ref="compo"></el-date-picker>
`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.focus();
setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el;
$el.querySelector('td.available').click();
setTimeout(_ => {
vm.$refs.compo.showClose = true;
vm.$refs.compo.handleClickIcon({ stopPropagation: () => null });
setTimeout(_ => {
expect(vm.value).to.equal(null);
done();
}, DELAY);
}, DELAY);
}, DELAY);
});
it('disabled clear value', done => {
vm = createVue({
template: `
<el-date-picker v-model="value" ref="compo" :clearable="false"></el-date-picker>
`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.focus();
setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el;
$el.querySelector('td.available').click();
vm.$nextTick(_ => {
vm.$el.querySelector('.el-input__icon').click();
setTimeout(_ => {
expect(vm.value).to.be.exist;
done();
}, DELAY);
});
}, DELAY);
});
it('reset', done => {
vm = createVue({
template: `
<el-date-picker ref="compo" v-model="value"></el-date-picker>
`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(_ => {
const $el = vm.$refs.compo.picker.$el;
$el.querySelector('.el-date-picker__next-btn.el-icon-arrow-right').click();
setTimeout(_ => {
$el.querySelector('td.available').click();
vm.$nextTick(_ => {
vm.value = '';
setTimeout(_ => {
expect(vm.$refs.compo.picker.date.getDate()).to.equal(new Date().getDate());
done();
}, DELAY);
});
}, DELAY);
}, DELAY);
});
it('focus', done => {
vm = createVue({
template: `
<el-date-picker ref="picker"></el-date-picker>
`
}, true);
const spy = sinon.spy();
vm.$refs.picker.$on('focus', spy);
vm.$refs.picker.focus();
vm.$nextTick(_ => {
expect(spy.calledOnce).to.be.true;
done();
});
});
it('change event', done => {
let onChangeValue;
vm = createVue({
template: `
<el-date-picker
ref="compo"
v-model="value"
@change="handleChange" />`,
methods: {
handleChange(val) {
onChangeValue = val;
}
},
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(_ => {
const picker = vm.$refs.compo.picker;
// programatic modification of bound value does not emit cange
vm.value = new Date(2000, 9, 2);
setTimeout(_ => {
expect(onChangeValue).to.not.exist;
// user interaction does emit change
picker.$el.querySelector('td.available').click();
setTimeout(_ => {
expect(onChangeValue.getTime()).to.equal(vm.value.getTime());
done();
}, DELAY);
}, DELAY);
}, DELAY);
});
it('change event: when clear(), without opening picker', done => {
vm = createVue({
template: `
<el-date-picker
ref="compo"
v-model="value"
/>`,
data() {
return {
value: new Date()
};
}
}, true);
const spy = sinon.spy();
vm.$refs.compo.$on('change', spy);
setTimeout(_ => {
vm.$refs.compo.showClose = true;
vm.$refs.compo.handleClickIcon({ stopPropagation: () => null });
setTimeout(_ => {
expect(spy.calledOnce).to.equal(true);
expect(spy.calledWith(null)).to.equal(true);
done();
}, DELAY);
}, DELAY);
});
it('nuke invalid input on close', done => {
vm = createVue({
template: '<el-date-picker v-model="value" value-format="yyyy-MM-dd" ref="compo" />',
data() {
return {
value: '2010-10-01'
};
}
}, true);
const compo = vm.$refs.compo;
const input = compo.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(_ => {
compo.userInput = 'abc';
compo.handleChange(); // simplified test
compo.handleClose();
setTimeout(_ => {
expect(input.value).to.equal('2010-10-01');
expect(vm.value).to.equal('2010-10-01');
done();
}, DELAY);
}, DELAY);
});
it('select datetime with defaultTime', done => {
vm = createVue({
template: `
<el-date-picker ref="compo" type="datetime" v-model="value" default-time="12:00:00"></el-date-picker>
`,
data() {
return {
value: ''
};
}
}, true);
const input = vm.$el.querySelector('input');
input.blur();
input.focus();
setTimeout(_ => {
const picker = vm.$refs.compo.picker;
picker.$el.querySelector('td.available').click();
setTimeout(_ => {
const date = vm.$refs.compo.picker.date;
expect(date.getHours()).to.equal(12);
expect(date.getMinutes()).to.equal(0);
expect(date.getSeconds()).to.equal(0);
done();
}, DELAY);
}, DELAY);
});
describe('input event', () => {
// mimic standard <select>'s behavior
// emit input if and only if value changes
afterEach(() => { destroyVM(vm); });
没有合适的资源?快使用搜索试试~ 我知道了~
element-2.15.6.zip
共1122个文件
js:333个
md:274个
scss:162个
需积分: 0 0 下载量 140 浏览量
2024-08-24
09:39:52
上传
评论
收藏 2.64MB ZIP 举报
温馨提示
vue2 的 ui 框架 element-ui 源码
资源推荐
资源详情
资源评论
收起资源包目录
element-2.15.6.zip (1122个子文件)
.babelrc 790B
common.css 3KB
style.css 947B
icomoon.eot 2KB
.eslintignore 108B
.eslintrc 286B
.eslintrc 162B
.gitattributes 35B
.gitignore 357B
.gitignore 28B
.gitignore 4B
favicon.ico 17KB
element-demo.jpeg 363KB
date-picker.spec.js 88KB
table.spec.js 70KB
popper.js 49KB
form.spec.js 29KB
tree.spec.js 28KB
select.spec.js 24KB
autocomplete.spec.js 22KB
tabs.spec.js 19KB
table-body.js 16KB
table-header.js 15KB
menu.spec.js 15KB
cascader-panel.spec.js 14KB
checkbox.spec.js 14KB
input.spec.js 12KB
pagination.spec.js 12KB
radio.spec.js 11KB
node.js 11KB
watcher.js 11KB
cascader.spec.js 11KB
date.js 11KB
input-number.spec.js 11KB
slider.spec.js 11KB
dropdown.spec.js 11KB
pagination.js 10KB
color-picker.spec.js 10KB
drawer.spec.js 9KB
time-picker.spec.js 9KB
date-util.js 9KB
table-column.js 9KB
color.js 9KB
color.js 9KB
upload.spec.js 8KB
tree-store.js 8KB
popover.spec.js 8KB
table-layout.js 8KB
index.js 8KB
dialog.spec.js 8KB
message-box.spec.js 7KB
carousel.spec.js 7KB
loading.spec.js 7KB
tree.js 7KB
progress.spec.js 6KB
collapse.spec.js 6KB
timeline.spec.js 6KB
dom.js 6KB
util.js 6KB
main.js 6KB
util.js 5KB
transfer.spec.js 5KB
vue-popper.js 5KB
time-select.spec.js 5KB
rate.spec.js 5KB
index.js 5KB
main.js 5KB
switch.spec.js 5KB
descriptions.spec.js 5KB
popup-manager.js 5KB
util.vue-popper.spec.js 5KB
directive.js 5KB
index.js 4KB
ta.js 4KB
tooltip.spec.js 4KB
route.config.js 4KB
steps.spec.js 4KB
new.js 4KB
table-footer.js 4KB
node.js 4KB
th.js 4KB
webpack.demo.js 4KB
kg.js 4KB
km.js 4KB
main.js 4KB
util.clickoutside.spec.js 4KB
descriptions-row.js 4KB
result.spec.js 4KB
el.js 4KB
calendar.spec.js 4KB
index.js 4KB
ug-CN.js 4KB
hy-AM.js 4KB
notification.spec.js 3KB
kz.js 3KB
sr.js 3KB
fa.js 3KB
ua.js 3KB
config.js 3KB
ru-RU.js 3KB
共 1122 条
- 1
- 2
- 3
- 4
- 5
- 6
- 12
资源评论
a3737337
- 粉丝: 0
- 资源: 2869
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 弹窗保存成功! - 2秒后自动关闭
- WSL和Ubuntu_22.04和ROS2和TB3安装.md
- TA-Lib-0.4.17-cp27-cp27m-win-amd64.whl.rar
- (6)六轴机械臂的运动学正、逆解.html
- 数据中心建设标准国标与Uptime标准对标解释
- 基于ARIMA-LSTM-transformer等模型进行流感时间序列预测Python源码(高分项目)
- canvas实现的彩色纸屑组成文字3d动画特效源码.zip
- 基于景观生态风险评价的流域景观格局优化,教学视频和资料,喜欢的就下载吧,保证受用
- java设计模式-建造者模式(Builder Pattern)
- C语言刷题-lesson5_1731564764305.pdf
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功