mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-06 18:18:53 +08:00
add test for mixins
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
.icon-tooltip {
|
.icon-tooltip {
|
||||||
visibility: hidden;
|
|
||||||
background-color: rgba(80, 103, 132, 0.85);
|
background-color: rgba(80, 103, 132, 0.85);
|
||||||
color: #fff;
|
color: #fff;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|||||||
@@ -1,17 +1,16 @@
|
|||||||
export default {
|
export default {
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
tooltipStyle: {}
|
tooltipStyle: {
|
||||||
|
visibility: 'hidden'
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
showTooltip (e) {
|
showTooltip (e) {
|
||||||
this.tooltipStyle = {
|
this.$set(this.tooltipStyle, 'top', e.clientY - 12 + 'px')
|
||||||
visibility: 'visible',
|
this.$set(this.tooltipStyle, 'left', e.clientX + 12 + 'px')
|
||||||
position: 'fixed',
|
this.$set(this.tooltipStyle, 'visibility', 'visible')
|
||||||
top: e.clientY - 12 + 'px',
|
|
||||||
left: e.clientX + 12 + 'px'
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
hideTooltip () {
|
hideTooltip () {
|
||||||
this.$set(this.tooltipStyle, 'visibility', 'hidden')
|
this.$set(this.tooltipStyle, 'visibility', 'hidden')
|
||||||
|
|||||||
46
tests/unit/tooltips.spec.js
Normal file
46
tests/unit/tooltips.spec.js
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
import { expect } from 'chai'
|
||||||
|
import { mount } from '@vue/test-utils'
|
||||||
|
import tooltipMixin from '@/mixins/tooltips.js'
|
||||||
|
|
||||||
|
describe('tooltips.js', () => {
|
||||||
|
it('tooltip is hidden in initial', () => {
|
||||||
|
const component = {
|
||||||
|
template: '<div :style="tooltipStyle"></div>',
|
||||||
|
mixins: [tooltipMixin]
|
||||||
|
}
|
||||||
|
const wrapper = mount(component)
|
||||||
|
expect(wrapper.find('div').isVisible()).to.equal(false)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('tooltipStyle is correct when showTooltip', async () => {
|
||||||
|
const component = {
|
||||||
|
template: '<div :style="tooltipStyle"></div>',
|
||||||
|
mixins: [tooltipMixin]
|
||||||
|
}
|
||||||
|
const wrapper = mount(component)
|
||||||
|
await wrapper.vm.showTooltip(new MouseEvent('mouseover', {
|
||||||
|
clientX: 10,
|
||||||
|
clientY: 20
|
||||||
|
}))
|
||||||
|
expect(wrapper.vm.tooltipStyle).to.eql({
|
||||||
|
visibility: 'visible',
|
||||||
|
top: '8px',
|
||||||
|
left: '22px'
|
||||||
|
})
|
||||||
|
expect(wrapper.find('div').isVisible()).to.equal(true)
|
||||||
|
})
|
||||||
|
|
||||||
|
it('tooltip is not visible after hideTooltip', async () => {
|
||||||
|
const component = {
|
||||||
|
template: '<div :style="tooltipStyle"></div>',
|
||||||
|
mixins: [tooltipMixin]
|
||||||
|
}
|
||||||
|
const wrapper = mount(component)
|
||||||
|
await wrapper.vm.showTooltip(new MouseEvent('mouseover', {
|
||||||
|
clientX: 10,
|
||||||
|
clientY: 20
|
||||||
|
}))
|
||||||
|
await wrapper.vm.hideTooltip()
|
||||||
|
expect(wrapper.find('div').isVisible()).to.equal(false)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user