mirror of
https://github.com/lana-k/sqliteviz.git
synced 2026-02-04 15:38:55 +08:00
tests
This commit is contained in:
@@ -338,11 +338,10 @@ export default {
|
|||||||
if (!this.dataSources) {
|
if (!this.dataSources) {
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
const firstColumnName = Object.keys(this.dataSources)[0]
|
||||||
try {
|
try {
|
||||||
return (
|
return (
|
||||||
this.dataSources[Object.keys(this.dataSources)[0] || 'doc'].map(
|
this.dataSources[firstColumnName].map(json => JSON.parse(json)) || []
|
||||||
json => JSON.parse(json)
|
|
||||||
) || []
|
|
||||||
)
|
)
|
||||||
} catch {
|
} catch {
|
||||||
return []
|
return []
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<side-tool-bar panel="dataView" @switch-to="$emit('switchTo', $event)">
|
<side-tool-bar panel="dataView" @switch-to="$emit('switchTo', $event)">
|
||||||
<icon-button
|
<icon-button
|
||||||
|
ref="chartBtn"
|
||||||
:active="mode === 'chart'"
|
:active="mode === 'chart'"
|
||||||
tooltip="Switch to chart"
|
tooltip="Switch to chart"
|
||||||
tooltipPosition="top-left"
|
tooltipPosition="top-left"
|
||||||
@@ -33,6 +34,7 @@
|
|||||||
<pivot-icon />
|
<pivot-icon />
|
||||||
</icon-button>
|
</icon-button>
|
||||||
<icon-button
|
<icon-button
|
||||||
|
ref="graphBtn"
|
||||||
:active="mode === 'graph'"
|
:active="mode === 'graph'"
|
||||||
tooltip="Switch to graph"
|
tooltip="Switch to graph"
|
||||||
tooltipPosition="top-left"
|
tooltipPosition="top-left"
|
||||||
@@ -56,6 +58,7 @@
|
|||||||
<div class="side-tool-bar-divider" />
|
<div class="side-tool-bar-divider" />
|
||||||
|
|
||||||
<icon-button
|
<icon-button
|
||||||
|
ref="pngExportBtn"
|
||||||
:disabled="!exportToPngEnabled || loadingImage"
|
:disabled="!exportToPngEnabled || loadingImage"
|
||||||
:loading="loadingImage"
|
:loading="loadingImage"
|
||||||
tooltip="Save as PNG image"
|
tooltip="Save as PNG image"
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { mount } from '@vue/test-utils'
|
import { mount } from '@vue/test-utils'
|
||||||
import DataView from '@/views/MainView/Workspace/Tabs/Tab/DataView'
|
import DataView from '@/views/MainView/Workspace/Tabs/Tab/DataView/index.vue'
|
||||||
import sinon from 'sinon'
|
import sinon from 'sinon'
|
||||||
import { nextTick } from 'vue'
|
import { nextTick } from 'vue'
|
||||||
import cIo from '@/lib/utils/clipboardIo'
|
import cIo from '@/lib/utils/clipboardIo'
|
||||||
@@ -29,7 +29,10 @@ 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: {
|
global: {
|
||||||
mocks: { $store }
|
mocks: { $store },
|
||||||
|
provide: {
|
||||||
|
tabLayout: { dataView: 'above' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -53,13 +56,28 @@ describe('DataView.vue', () => {
|
|||||||
expect(wrapper.vm.getOptionsForSave()).to.eql({
|
expect(wrapper.vm.getOptionsForSave()).to.eql({
|
||||||
here_are: 'pivot_settings'
|
here_are: 'pivot_settings'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
|
||||||
|
await graphBtn.trigger('click')
|
||||||
|
|
||||||
|
const graph = wrapper.findComponent({ name: 'graph' }).vm
|
||||||
|
sinon
|
||||||
|
.stub(graph, 'getOptionsForSave')
|
||||||
|
.returns({ here_are: 'graph_settings' })
|
||||||
|
|
||||||
|
expect(wrapper.vm.getOptionsForSave()).to.eql({
|
||||||
|
here_are: 'graph_settings'
|
||||||
|
})
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
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: {
|
global: {
|
||||||
mocks: { $store }
|
mocks: { $store },
|
||||||
|
provide: {
|
||||||
|
tabLayout: { dataView: 'above' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -87,13 +105,22 @@ describe('DataView.vue', () => {
|
|||||||
// Export to svg
|
// Export to svg
|
||||||
await svgBtn.trigger('click')
|
await svgBtn.trigger('click')
|
||||||
expect(pivot.saveAsSvg.calledOnce).to.equal(true)
|
expect(pivot.saveAsSvg.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
// Switch to graph - svg disabled
|
||||||
|
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
|
||||||
|
await graphBtn.trigger('click')
|
||||||
|
expect(svgBtn.attributes('disabled')).to.not.equal(undefined)
|
||||||
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
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: {
|
global: {
|
||||||
mocks: { $store }
|
mocks: { $store },
|
||||||
|
provide: {
|
||||||
|
tabLayout: { dataView: 'above' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -114,9 +141,71 @@ describe('DataView.vue', () => {
|
|||||||
const pivot = wrapper.findComponent({ name: 'pivot' }).vm
|
const pivot = wrapper.findComponent({ name: 'pivot' }).vm
|
||||||
sinon.spy(pivot, 'saveAsHtml')
|
sinon.spy(pivot, 'saveAsHtml')
|
||||||
|
|
||||||
// Export to svg
|
// Export to html
|
||||||
await htmlBtn.trigger('click')
|
await htmlBtn.trigger('click')
|
||||||
expect(pivot.saveAsHtml.calledOnce).to.equal(true)
|
expect(pivot.saveAsHtml.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
// Switch to graph - htmlBtn disabled
|
||||||
|
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
|
||||||
|
await graphBtn.trigger('click')
|
||||||
|
expect(htmlBtn.attributes('disabled')).to.not.equal(undefined)
|
||||||
|
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('method saveAsPng calls the same method of the current view component', async () => {
|
||||||
|
const clock = sinon.useFakeTimers()
|
||||||
|
const wrapper = mount(DataView, {
|
||||||
|
global: {
|
||||||
|
mocks: { $store },
|
||||||
|
provide: {
|
||||||
|
tabLayout: { dataView: 'above' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Find chart and stub the method
|
||||||
|
const chart = wrapper.findComponent({ name: 'Chart' }).vm
|
||||||
|
sinon.stub(chart, 'saveAsPng').callsFake(() => {
|
||||||
|
chart.$emit('loadingImageCompleted')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Export to png
|
||||||
|
const pngBtn = wrapper.findComponent({ ref: 'pngExportBtn' })
|
||||||
|
await pngBtn.trigger('click')
|
||||||
|
await clock.tick(0)
|
||||||
|
expect(chart.saveAsPng.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
// Switch to pivot
|
||||||
|
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
|
||||||
|
await pivotBtn.trigger('click')
|
||||||
|
|
||||||
|
// Find pivot and stub the method
|
||||||
|
const pivot = wrapper.findComponent({ name: 'pivot' }).vm
|
||||||
|
sinon.stub(pivot, 'saveAsPng').callsFake(() => {
|
||||||
|
pivot.$emit('loadingImageCompleted')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Export to png
|
||||||
|
await pngBtn.trigger('click')
|
||||||
|
await clock.tick(0)
|
||||||
|
expect(pivot.saveAsPng.calledOnce).to.equal(true)
|
||||||
|
|
||||||
|
// Switch to graph
|
||||||
|
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
|
||||||
|
await graphBtn.trigger('click')
|
||||||
|
|
||||||
|
// Find graph and stub the method
|
||||||
|
const graph = wrapper.findComponent({ name: 'graph' }).vm
|
||||||
|
sinon.stub(graph, 'saveAsPng').callsFake(() => {
|
||||||
|
graph.$emit('loadingImageCompleted')
|
||||||
|
})
|
||||||
|
|
||||||
|
// Export to png
|
||||||
|
await pngBtn.trigger('click')
|
||||||
|
await clock.tick(0)
|
||||||
|
expect(graph.saveAsPng.calledOnce).to.equal(true)
|
||||||
|
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -276,4 +365,52 @@ describe('DataView.vue', () => {
|
|||||||
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false)
|
expect(wrapper.vm.copyToClipboard.calledOnce).to.equal(false)
|
||||||
wrapper.unmount()
|
wrapper.unmount()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('saves visualisation options and restores them when switch between modes', async () => {
|
||||||
|
const wrapper = mount(DataView, {
|
||||||
|
props: {
|
||||||
|
initMode: 'graph',
|
||||||
|
initOptions: { test_options: 'graph_options_from_inquiery' }
|
||||||
|
},
|
||||||
|
global: {
|
||||||
|
mocks: { $store },
|
||||||
|
stubs: {
|
||||||
|
chart: true,
|
||||||
|
graph: true,
|
||||||
|
pivot: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const getOptionsForSaveStub = sinon.stub(wrapper.vm, 'getOptionsForSave')
|
||||||
|
|
||||||
|
expect(
|
||||||
|
wrapper.findComponent({ name: 'graph' }).props('initOptions')
|
||||||
|
).to.eql({ test_options: 'graph_options_from_inquiery' })
|
||||||
|
|
||||||
|
getOptionsForSaveStub.returns({ test_options: 'latest_graph_options' })
|
||||||
|
const chartBtn = wrapper.findComponent({ ref: 'chartBtn' })
|
||||||
|
await chartBtn.trigger('click')
|
||||||
|
|
||||||
|
getOptionsForSaveStub.returns({ test_options: 'chart_settings' })
|
||||||
|
|
||||||
|
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
|
||||||
|
await pivotBtn.trigger('click')
|
||||||
|
|
||||||
|
getOptionsForSaveStub.returns({ test_options: 'pivot_settings' })
|
||||||
|
await chartBtn.trigger('click')
|
||||||
|
expect(
|
||||||
|
wrapper.findComponent({ name: 'chart' }).props('initOptions')
|
||||||
|
).to.eql({ test_options: 'chart_settings' })
|
||||||
|
|
||||||
|
await pivotBtn.trigger('click')
|
||||||
|
expect(
|
||||||
|
wrapper.findComponent({ name: 'pivot' }).props('initOptions')
|
||||||
|
).to.eql({ test_options: 'pivot_settings' })
|
||||||
|
|
||||||
|
const graphBtn = wrapper.findComponent({ ref: 'graphBtn' })
|
||||||
|
await graphBtn.trigger('click')
|
||||||
|
expect(
|
||||||
|
wrapper.findComponent({ name: 'graph' }).props('initOptions')
|
||||||
|
).to.eql({ test_options: 'latest_graph_options' })
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { mount, flushPromises } from '@vue/test-utils'
|
import { mount, flushPromises } from '@vue/test-utils'
|
||||||
import Pivot from '@/views/MainView/Workspace/Tabs/Tab/DataView/Pivot'
|
import Pivot from '@/views/MainView/Workspace/Tabs/Tab/DataView/Pivot/index.vue'
|
||||||
import chartHelper from '@/lib/chartHelper'
|
import chartHelper from '@/lib/chartHelper'
|
||||||
import fIo from '@/lib/utils/fileIo'
|
import fIo from '@/lib/utils/fileIo'
|
||||||
import $ from 'jquery'
|
import $ from 'jquery'
|
||||||
|
|||||||
Reference in New Issue
Block a user