-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
280 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
.PHONY: dist | ||
.PHONY: dist test | ||
default: help | ||
|
||
# build all theme | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
const Popover = require('./src/main'); | ||
const directive = require('./src/directive').default; | ||
const Vue = require('vue'); | ||
|
||
Vue.directive('popover', directive); | ||
|
||
/* istanbul ignore next */ | ||
Popover.install = function(Vue) { | ||
Vue.directive('popover', directive); | ||
Vue.component(Popover.name, Popover); | ||
}; | ||
Popover.directive = directive; | ||
|
||
module.exports = Popover; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default { | ||
bind(el, binding, vnode) { | ||
vnode.context.$refs[binding.arg].$refs.reference = el; | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,196 @@ | ||
import { createVue, triggerEvent, createTest } from '../util'; | ||
import Popover, { directive } from 'packages/popover'; | ||
|
||
describe('Popover', () => { | ||
describe('trigger', () => { | ||
const createVM = (trigger) => { | ||
return createVue(` | ||
<div> | ||
<el-popover | ||
ref="popover" | ||
trigger="${trigger}" | ||
content="content"> | ||
<button slot="reference">trigger ${trigger}</button> | ||
</el-popover> | ||
</div> | ||
`, true); | ||
}; | ||
|
||
it('click', () => { | ||
const vm = createVM('click'); | ||
const compo = vm.$refs.popover; | ||
|
||
vm.$el.querySelector('button').click(); | ||
expect(compo.showPopper).to.true; | ||
document.body.click(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
|
||
it('hover', done => { | ||
const vm = createVM('hover'); | ||
const compo = vm.$refs.popover; | ||
const button = vm.$el.querySelector('button'); | ||
|
||
triggerEvent(button, 'mouseenter'); | ||
expect(compo.showPopper).to.true; | ||
triggerEvent(button, 'mouseleave'); | ||
setTimeout(_ => { | ||
expect(compo.showPopper).to.false; | ||
done(); | ||
}, 250); // 代码里是 200ms | ||
}); | ||
|
||
it('focus input in children node', () => { | ||
const vm = createVue(` | ||
<div> | ||
<el-popover | ||
ref="popover" | ||
trigger="focus" | ||
content="content"> | ||
<div slot="reference"> | ||
<input type="text" value="trigger focus" /> | ||
</div> | ||
</el-popover> | ||
</div> | ||
`, true); | ||
const compo = vm.$refs.popover; | ||
const input = vm.$el.querySelector('input'); | ||
|
||
input.focus(); | ||
expect(compo.showPopper).to.true; | ||
input.blur(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
|
||
it('focus textarea in children node', () => { | ||
const vm = createVue(` | ||
<div> | ||
<el-popover | ||
ref="popover" | ||
trigger="focus" | ||
content="content"> | ||
<div slot="reference"> | ||
<textarea></textarea> | ||
</div> | ||
</el-popover> | ||
</div> | ||
`, true); | ||
const compo = vm.$refs.popover; | ||
const textarea = vm.$el.querySelector('textarea'); | ||
|
||
textarea.focus(); | ||
expect(compo.showPopper).to.true; | ||
textarea.blur(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
|
||
it('focus input', () => { | ||
const vm = createVue(` | ||
<div> | ||
<el-popover | ||
ref="popover" | ||
trigger="focus" | ||
content="content"> | ||
<input type="text" slot="reference" value="trigger focus" /> | ||
</el-popover> | ||
</div> | ||
`, true); | ||
const compo = vm.$refs.popover; | ||
const input = vm.$el.querySelector('input'); | ||
|
||
input.focus(); | ||
expect(compo.showPopper).to.true; | ||
input.blur(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
|
||
it('focus button', () => { | ||
const vm = createVM('focus'); | ||
const compo = vm.$refs.popover; | ||
const button = vm.$el.querySelector('button'); | ||
|
||
triggerEvent(button, 'mousedown'); | ||
expect(compo.showPopper).to.true; | ||
triggerEvent(button, 'mouseup'); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
}); | ||
|
||
describe('create by directive', () => { | ||
const vm = createVue({ | ||
template: ` | ||
<div> | ||
<el-popover | ||
ref="popover1" | ||
trigger="click" | ||
content="content"> | ||
</el-popover> | ||
<button v-popover:popover1>create by directive</button> | ||
</div> | ||
`, | ||
|
||
directives: { | ||
Popover: directive | ||
} | ||
}, true); | ||
const compo = vm.$refs.popover1; | ||
|
||
it('render', () => { | ||
expect(vm.$el.querySelector('.el-popover')).to.have.deep.property('textContent').include('content'); | ||
}); | ||
|
||
it('triggering click', done => { | ||
vm.$el.querySelector('button').click(); | ||
expect(compo.popperElm).to.not.exist; | ||
vm.$nextTick(_ => { | ||
expect(compo).to.have.deep.property('popperElm.style.display').not.equal('none'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('click outside', () => { | ||
document.body.click(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
}); | ||
|
||
describe('create by slot', () => { | ||
const vm = createVue(` | ||
<div> | ||
<el-popover | ||
ref="popover" | ||
trigger="click" | ||
content="content"> | ||
<button slot="reference">create by slot</button> | ||
</el-popover> | ||
</div> | ||
`, true); | ||
const compo = vm.$refs.popover; | ||
|
||
it('render', () => { | ||
expect(vm.$el.querySelector('.el-popover')).to.have.deep.property('textContent').include('content'); | ||
}); | ||
|
||
it('triggering click', done => { | ||
vm.$el.querySelector('button').click(); | ||
expect(compo.popperElm).to.not.exist; | ||
vm.$nextTick(_ => { | ||
expect(compo).to.have.deep.property('popperElm.style.display').not.equal('none'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('click outside', () => { | ||
document.body.click(); | ||
expect(compo.showPopper).to.false; | ||
}); | ||
}); | ||
|
||
it('destroy event', () => { | ||
const vm = createTest(Popover, { | ||
reference: document.createElement('div'), | ||
popper: document.createElement('div') | ||
}); | ||
expect(() => vm.$destroy(true)).not.throw(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.