mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-07 02:28:54 +08:00
fix tests
This commit is contained in:
@@ -7,6 +7,9 @@ module.exports = function (config) {
|
|||||||
'vue': 'vue/dist/vue.esm-bundler.js'
|
'vue': 'vue/dist/vue.esm-bundler.js'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
server: {
|
||||||
|
preTransformRequests: false
|
||||||
|
}
|
||||||
},
|
},
|
||||||
coverage: {
|
coverage: {
|
||||||
enable: true,
|
enable: true,
|
||||||
|
|||||||
@@ -8,13 +8,19 @@ import fIo from '@/lib/utils/fileIo'
|
|||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
|
|
||||||
describe('Chart.vue', () => {
|
describe('Chart.vue', () => {
|
||||||
|
const $store = { state: { isWorkspaceVisible: true } }
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('getOptionsForSave called with proper arguments', () => {
|
it('getOptionsForSave called with proper arguments', () => {
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = shallowMount(Chart)
|
const wrapper = shallowMount(Chart, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
const vm = wrapper.vm
|
const vm = wrapper.vm
|
||||||
const stub = sinon.stub(chartHelper, 'getOptionsForSave').returns('result')
|
const stub = sinon.stub(chartHelper, 'getOptionsForSave').returns('result')
|
||||||
const chartData = vm.getOptionsForSave()
|
const chartData = vm.getOptionsForSave()
|
||||||
@@ -25,7 +31,11 @@ describe('Chart.vue', () => {
|
|||||||
|
|
||||||
it('emits update when plotly updates', async () => {
|
it('emits update when plotly updates', async () => {
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = mount(Chart)
|
const wrapper = mount(Chart, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
wrapper.findComponent({ ref: 'plotlyEditor' }).vm.$emit('update')
|
wrapper.findComponent({ ref: 'plotlyEditor' }).vm.$emit('update')
|
||||||
expect(wrapper.emitted('update')).to.have.lengthOf(1)
|
expect(wrapper.emitted('update')).to.have.lengthOf(1)
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
@@ -40,7 +50,10 @@ describe('Chart.vue', () => {
|
|||||||
|
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = shallowMount(Chart, {
|
const wrapper = shallowMount(Chart, {
|
||||||
props: { dataSources }
|
props: { dataSources },
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const newDataSources = {
|
const newDataSources = {
|
||||||
@@ -62,7 +75,10 @@ describe('Chart.vue', () => {
|
|||||||
|
|
||||||
// mount the component
|
// mount the component
|
||||||
const wrapper = shallowMount(Chart, {
|
const wrapper = shallowMount(Chart, {
|
||||||
props: { dataSources }
|
props: { dataSources },
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.setProps({ dataSources: null })
|
await wrapper.setProps({ dataSources: null })
|
||||||
@@ -78,7 +94,10 @@ describe('Chart.vue', () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const wrapper = mount(Chart, {
|
const wrapper = mount(Chart, {
|
||||||
props: { dataSources }
|
props: { dataSources },
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
sinon.spy(wrapper.vm, 'prepareCopy')
|
sinon.spy(wrapper.vm, 'prepareCopy')
|
||||||
|
|
||||||
|
|||||||
@@ -5,12 +5,18 @@ import sinon from 'sinon'
|
|||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
|
|
||||||
describe('DataView.vue', () => {
|
describe('DataView.vue', () => {
|
||||||
|
const $store = { state: { isWorkspaceVisible: true } }
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
sinon.restore()
|
sinon.restore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it('emits update on mode changing', async () => {
|
it('emits update on mode changing', async () => {
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
|
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
|
||||||
await pivotBtn.trigger('click')
|
await pivotBtn.trigger('click')
|
||||||
@@ -20,7 +26,11 @@ describe('DataView.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('method getOptionsForSave calls the same method of the current view component', async () => {
|
it('method getOptionsForSave calls the same method of the current view component', async () => {
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
||||||
sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' })
|
sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' })
|
||||||
@@ -38,7 +48,11 @@ describe('DataView.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('method saveAsSvg calls the same method of the current view component', async () => {
|
it('method saveAsSvg calls the same method of the current view component', async () => {
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Find chart and spy the method
|
// Find chart and spy the method
|
||||||
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
||||||
@@ -68,7 +82,11 @@ describe('DataView.vue', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('method saveAsHtml calls the same method of the current view component', async () => {
|
it('method saveAsHtml calls the same method of the current view component', async () => {
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
// Find chart and spy the method
|
// Find chart and spy the method
|
||||||
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
||||||
@@ -97,7 +115,11 @@ describe('DataView.vue', () => {
|
|||||||
const ClipboardItem = window.ClipboardItem
|
const ClipboardItem = window.ClipboardItem
|
||||||
delete window.ClipboardItem
|
delete window.ClipboardItem
|
||||||
sinon.spy(window, 'alert')
|
sinon.spy(window, 'alert')
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
const copyBtn = wrapper.findComponent({ ref: 'copyToClipboardBtn' })
|
const copyBtn = wrapper.findComponent({ ref: 'copyToClipboardBtn' })
|
||||||
await copyBtn.trigger('click')
|
await copyBtn.trigger('click')
|
||||||
@@ -120,7 +142,8 @@ describe('DataView.vue', () => {
|
|||||||
const wrapper = mount(DataView, {
|
const wrapper = mount(DataView, {
|
||||||
attachTo: document.body,
|
attachTo: document.body,
|
||||||
global: {
|
global: {
|
||||||
stubs: { teleport: true, transition: false }
|
stubs: { teleport: true, transition: false },
|
||||||
|
mocks: { $store }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
||||||
@@ -165,7 +188,13 @@ describe('DataView.vue', () => {
|
|||||||
it('copy to clipboard less than 1 sec', async () => {
|
it('copy to clipboard less than 1 sec', async () => {
|
||||||
sinon.stub(window.navigator.clipboard, 'write').resolves()
|
sinon.stub(window.navigator.clipboard, 'write').resolves()
|
||||||
const clock = sinon.useFakeTimers()
|
const clock = sinon.useFakeTimers()
|
||||||
const wrapper = mount(DataView)
|
const wrapper = mount(DataView, {
|
||||||
|
attachTo: document.body,
|
||||||
|
global: {
|
||||||
|
stubs: { teleport: true, transition: false },
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
|
})
|
||||||
sinon.spy(wrapper.vm, 'copyToClipboard')
|
sinon.spy(wrapper.vm, 'copyToClipboard')
|
||||||
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
||||||
await clock.tick(500)
|
await clock.tick(500)
|
||||||
@@ -182,7 +211,8 @@ describe('DataView.vue', () => {
|
|||||||
|
|
||||||
await nextTick()
|
await nextTick()
|
||||||
// The dialog is not shown...
|
// The dialog is not shown...
|
||||||
expect(wrapper.find('[data-modal="prepareCopy"]').exists()).to.equal(false)
|
await clock.tick(100)
|
||||||
|
expect(wrapper.find('.dialog.vfm').exists()).to.equal(false)
|
||||||
// copyToClipboard is called
|
// copyToClipboard is called
|
||||||
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true)
|
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(true)
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
@@ -194,7 +224,8 @@ describe('DataView.vue', () => {
|
|||||||
const wrapper = mount(DataView, {
|
const wrapper = mount(DataView, {
|
||||||
attachTo: document.body,
|
attachTo: document.body,
|
||||||
global: {
|
global: {
|
||||||
stubs: { teleport: true, transition: false }
|
stubs: { teleport: true, transition: false },
|
||||||
|
mocks: { $store }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
sinon.spy(wrapper.vm, 'copyToClipboard')
|
sinon.spy(wrapper.vm, 'copyToClipboard')
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import pivotHelper from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/pivotHel
|
|||||||
|
|
||||||
describe('Pivot.vue', () => {
|
describe('Pivot.vue', () => {
|
||||||
let container
|
let container
|
||||||
|
const $store = { state: { isWorkspaceVisible: true } }
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
container = document.createElement('div')
|
container = document.createElement('div')
|
||||||
@@ -36,6 +37,9 @@ describe('Pivot.vue', () => {
|
|||||||
vals: [],
|
vals: [],
|
||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
|
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
|
||||||
@@ -71,6 +75,9 @@ describe('Pivot.vue', () => {
|
|||||||
vals: [],
|
vals: [],
|
||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -120,6 +127,9 @@ describe('Pivot.vue', () => {
|
|||||||
vals: [],
|
vals: [],
|
||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -190,7 +200,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(await wrapper.vm.prepareCopy()).to.be.instanceof(HTMLCanvasElement)
|
expect(await wrapper.vm.prepareCopy()).to.be.instanceof(HTMLCanvasElement)
|
||||||
@@ -252,7 +265,10 @@ describe('Pivot.vue', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||||
@@ -287,7 +303,10 @@ describe('Pivot.vue', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||||
@@ -322,7 +341,10 @@ describe('Pivot.vue', () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
mocks: { $store }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||||
@@ -352,7 +374,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Bar Chart'
|
rendererName: 'Bar Chart'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.vm.saveAsSvg()
|
await wrapper.vm.saveAsSvg()
|
||||||
@@ -380,7 +405,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Bar Chart'
|
rendererName: 'Bar Chart'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.vm.saveAsHtml()
|
await wrapper.vm.saveAsHtml()
|
||||||
@@ -410,7 +438,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.vm.saveAsHtml()
|
await wrapper.vm.saveAsHtml()
|
||||||
@@ -440,7 +471,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Bar Chart'
|
rendererName: 'Bar Chart'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.vm.saveAsPng()
|
await wrapper.vm.saveAsPng()
|
||||||
@@ -472,7 +506,10 @@ describe('Pivot.vue', () => {
|
|||||||
rendererName: 'Table'
|
rendererName: 'Table'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
attachTo: container
|
attachTo: container,
|
||||||
|
global: {
|
||||||
|
stubs: { 'chart': true }
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
await wrapper.vm.saveAsPng()
|
await wrapper.vm.saveAsPng()
|
||||||
|
|||||||
Reference in New Issue
Block a user