提交 863fef4d 编写于 作者: D dolymood

more unit tests

上级 eb156647
......@@ -53,6 +53,28 @@ describe('Dialog', () => {
.to.equal(2)
})
it('should render correct contents - confirmBtn/cancelBtn', () => {
const href = 'https://didichuxing.com/'
vm = createDialog({
type: 'confirm',
content: 'dialog',
confirmBtn: '确定1',
cancelBtn: {
text: '取消1',
active: false,
disabled: false,
href: href
}
})
const btns = vm.$el.querySelector('.cube-dialog-btns').getElementsByTagName('a')
expect(btns.length)
.to.equal(2)
expect(btns[0].href).to.equal(href)
expect(btns[0].textContent).to.equal('取消1')
expect(btns[1].href).to.equal('javascript:;')
expect(btns[1].textContent).to.equal('确定1')
})
it('should trigger events', () => {
const confirmHandler = sinon.spy()
const cancelHandler = sinon.spy()
......@@ -87,6 +109,37 @@ describe('Dialog', () => {
.to.be.calledOnce
})
it('should not trigger events when btn is disabled', () => {
const confirmHandler = sinon.spy()
const cancelHandler = sinon.spy()
vm = createDialog({
type: 'confirm',
title: 'dialog title',
content: 'dialog',
confirmBtn: {
disabled: true
},
cancelBtn: {
disabled: true
}
}, {
confirm: confirmHandler,
cancel: cancelHandler
})
vm.show()
// confirm click
vm.$el.querySelector('.cube-dialog-btns a:last-child').click()
expect(vm.isVisible)
.to.be.true
expect(confirmHandler)
.to.have.callCount(0)
vm.$el.querySelector('.cube-dialog-btns a').click()
expect(vm.isVisible)
.to.be.true
expect(cancelHandler)
.to.have.callCount(0)
})
function createDialog (props = {}, events = {}) {
return instantiateComponent(Vue, Dialog, {
props: props,
......
......@@ -15,9 +15,20 @@ describe('Loading.vue', () => {
expect(Vue.component(Loading.name))
.to.be.a('function')
})
it('should render correct contents', () => {
it('should render correct contents - no size', () => {
vm = instantiateComponent(Vue, Loading, {})
expect(vm.$el.className)
.to.equal('cube-loading')
expect(vm.$el.querySelector('.cube-loading-spinners').style.width)
.to.equal('')
})
it('should render correct contents - with size', () => {
vm = instantiateComponent(Vue, Loading, {
props: {
size: 30
}
})
expect(vm.$el.querySelector('.cube-loading-spinners').style.width)
.to.equal('30px')
})
})
......@@ -58,6 +58,7 @@ describe('Picker', () => {
Vue.use(Picker)
expect(Vue.component(Picker.name))
.to.be.a('function')
expect(Vue.prototype.$createPicker).to.be.a('function')
})
it('should render correct contents', function () {
......@@ -155,6 +156,23 @@ describe('Picker', () => {
}, 150)
})
it('should add warn log when sigle is false', () => {
const app = new Vue()
const originWarn = console.warn
const msgs = []
console.warn = function (...args) {
msgs.push(args.join('#'))
}
vm = app.$createPicker({
title: '变化选择器',
data: [data1],
selectedIndex: [1]
}, true)
expect(msgs.length)
.to.equal(1)
console.warn = originWarn
})
function createPicker(props = {}, events = {}) {
return instantiateComponent(Vue, Picker, {
props: props,
......
......@@ -121,6 +121,19 @@ describe('TimePicker', () => {
}, 100)
})
})
it('should add warn log when sigle is false', () => {
const app = new Vue()
const originWarn = console.warn
const msgs = []
console.warn = function (...args) {
msgs.push(args.join('#'))
}
vm = app.$createTimePicker({}, true)
expect(msgs.length)
.to.equal(1)
console.warn = originWarn
})
})
function createPicker(props = {}, events = {}) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册