1
0
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:
lana-k
2021-01-28 17:57:43 +01:00
parent 6cf22cef09
commit 82b80e4760
3 changed files with 52 additions and 8 deletions

View File

@@ -1,5 +1,4 @@
.icon-tooltip {
visibility: hidden;
background-color: rgba(80, 103, 132, 0.85);
color: #fff;
text-align: center;

View File

@@ -1,17 +1,16 @@
export default {
data () {
return {
tooltipStyle: {}
tooltipStyle: {
visibility: 'hidden'
}
}
},
methods: {
showTooltip (e) {
this.tooltipStyle = {
visibility: 'visible',
position: 'fixed',
top: e.clientY - 12 + 'px',
left: e.clientX + 12 + 'px'
}
this.$set(this.tooltipStyle, 'top', e.clientY - 12 + 'px')
this.$set(this.tooltipStyle, 'left', e.clientX + 12 + 'px')
this.$set(this.tooltipStyle, 'visibility', 'visible')
},
hideTooltip () {
this.$set(this.tooltipStyle, 'visibility', 'hidden')

View 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)
})
})