mirror of
https://github.com/lana-k/sqliteviz.git
synced 2025-12-08 02:58:54 +08:00
format
This commit is contained in:
@@ -12,9 +12,9 @@ describe('DataView.vue', () => {
|
||||
})
|
||||
|
||||
it('emits update on mode changing', async () => {
|
||||
const wrapper = mount(DataView, {
|
||||
const wrapper = mount(DataView, {
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -26,24 +26,32 @@ describe('DataView.vue', () => {
|
||||
})
|
||||
|
||||
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
|
||||
sinon.stub(chart, 'getOptionsForSave').returns({ here_are: 'chart_settings' })
|
||||
sinon
|
||||
.stub(chart, 'getOptionsForSave')
|
||||
.returns({ here_are: 'chart_settings' })
|
||||
|
||||
expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'chart_settings' })
|
||||
expect(wrapper.vm.getOptionsForSave()).to.eql({
|
||||
here_are: 'chart_settings'
|
||||
})
|
||||
|
||||
const pivotBtn = wrapper.findComponent({ ref: 'pivotBtn' })
|
||||
await pivotBtn.trigger('click')
|
||||
|
||||
const pivot = wrapper.findComponent({ name: 'pivot' }).vm
|
||||
sinon.stub(pivot, 'getOptionsForSave').returns({ here_are: 'pivot_settings' })
|
||||
sinon
|
||||
.stub(pivot, 'getOptionsForSave')
|
||||
.returns({ here_are: 'pivot_settings' })
|
||||
|
||||
expect(wrapper.vm.getOptionsForSave()).to.eql({ here_are: 'pivot_settings' })
|
||||
expect(wrapper.vm.getOptionsForSave()).to.eql({
|
||||
here_are: 'pivot_settings'
|
||||
})
|
||||
wrapper.unmount()
|
||||
})
|
||||
|
||||
@@ -117,7 +125,7 @@ describe('DataView.vue', () => {
|
||||
sinon.spy(window, 'alert')
|
||||
const wrapper = mount(DataView, {
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -127,8 +135,8 @@ describe('DataView.vue', () => {
|
||||
expect(
|
||||
window.alert.calledOnceWith(
|
||||
"Your browser doesn't support copying images into the clipboard. " +
|
||||
'If you use Firefox you can enable it ' +
|
||||
'by setting dom.events.asyncClipboard.clipboardItem to true.'
|
||||
'If you use Firefox you can enable it ' +
|
||||
'by setting dom.events.asyncClipboard.clipboardItem to true.'
|
||||
)
|
||||
).to.equal(true)
|
||||
|
||||
@@ -146,9 +154,11 @@ describe('DataView.vue', () => {
|
||||
mocks: { $store }
|
||||
}
|
||||
})
|
||||
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
||||
await clock.tick(5000)
|
||||
})
|
||||
sinon
|
||||
.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy')
|
||||
.callsFake(async () => {
|
||||
await clock.tick(5000)
|
||||
})
|
||||
|
||||
// Click copy to clipboard
|
||||
const copyBtn = wrapper.findComponent({ ref: 'copyToClipboardBtn' })
|
||||
@@ -156,11 +166,14 @@ describe('DataView.vue', () => {
|
||||
|
||||
// The dialog is shown...
|
||||
expect(wrapper.find('.dialog.vfm').exists()).to.equal(true)
|
||||
expect(wrapper.find('.dialog.vfm .dialog-header').text())
|
||||
.to.contain('Copy to clipboard')
|
||||
expect(wrapper.find('.dialog.vfm .dialog-header').text()).to.contain(
|
||||
'Copy to clipboard'
|
||||
)
|
||||
|
||||
// ... with Rendering message...
|
||||
expect(wrapper.find('.dialog-body').text()).to.equal('Rendering the visualisation...')
|
||||
expect(wrapper.find('.dialog-body').text()).to.equal(
|
||||
'Rendering the visualisation...'
|
||||
)
|
||||
|
||||
// Switch to microtasks (let prepareCopy run)
|
||||
await clock.tick(0)
|
||||
@@ -177,7 +190,9 @@ describe('DataView.vue', () => {
|
||||
expect(wrapper.find('.dialog-body').text()).to.equal('Image is ready')
|
||||
|
||||
// Click copy
|
||||
await wrapper.find('.dialog-buttons-container button.primary').trigger('click')
|
||||
await wrapper
|
||||
.find('.dialog-buttons-container button.primary')
|
||||
.trigger('click')
|
||||
|
||||
// The dialog is not shown...
|
||||
await clock.tick(100)
|
||||
@@ -196,9 +211,11 @@ describe('DataView.vue', () => {
|
||||
}
|
||||
})
|
||||
sinon.spy(wrapper.vm, 'copyToClipboard')
|
||||
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
||||
await clock.tick(500)
|
||||
})
|
||||
sinon
|
||||
.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy')
|
||||
.callsFake(async () => {
|
||||
await clock.tick(500)
|
||||
})
|
||||
|
||||
// Click copy to clipboard
|
||||
const copyBtn = wrapper.findComponent({ ref: 'copyToClipboardBtn' })
|
||||
@@ -229,9 +246,11 @@ describe('DataView.vue', () => {
|
||||
}
|
||||
})
|
||||
sinon.spy(wrapper.vm, 'copyToClipboard')
|
||||
sinon.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy').callsFake(async () => {
|
||||
await clock.tick(5000)
|
||||
})
|
||||
sinon
|
||||
.stub(wrapper.vm.$refs.viewComponent, 'prepareCopy')
|
||||
.callsFake(async () => {
|
||||
await clock.tick(5000)
|
||||
})
|
||||
|
||||
// Click copy to clipboard
|
||||
const copyBtn = wrapper.findComponent({ ref: 'copyToClipboardBtn' })
|
||||
@@ -245,7 +264,9 @@ describe('DataView.vue', () => {
|
||||
await nextTick()
|
||||
|
||||
// Click cancel
|
||||
await wrapper.find('.dialog-buttons-container button.secondary').trigger('click')
|
||||
await wrapper
|
||||
.find('.dialog-buttons-container button.secondary')
|
||||
.trigger('click')
|
||||
|
||||
// The dialog is not shown...
|
||||
await clock.tick(100)
|
||||
|
||||
@@ -39,7 +39,7 @@ describe('Pivot.vue', () => {
|
||||
}
|
||||
},
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
const colLabels = wrapper.findAll('.pivot-output thead th.pvtColLabel')
|
||||
@@ -77,7 +77,7 @@ describe('Pivot.vue', () => {
|
||||
}
|
||||
},
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -144,7 +144,11 @@ describe('Pivot.vue', () => {
|
||||
rendererName: 'Table',
|
||||
vals: []
|
||||
})
|
||||
sinon.stub(wrapper.findComponent({ref: "customChart"}).vm, 'getOptionsForSave')
|
||||
sinon
|
||||
.stub(
|
||||
wrapper.findComponent({ ref: 'customChart' }).vm,
|
||||
'getOptionsForSave'
|
||||
)
|
||||
.returns({ here_are: 'custom chart settings' })
|
||||
|
||||
let optionsForSave = wrapper.vm.getOptionsForSave()
|
||||
@@ -208,7 +212,8 @@ describe('Pivot.vue', () => {
|
||||
|
||||
expect(await wrapper.vm.prepareCopy()).to.be.instanceof(HTMLCanvasElement)
|
||||
|
||||
sinon.stub(wrapper.findComponent({ref: "customChart"}).vm, 'prepareCopy')
|
||||
sinon
|
||||
.stub(wrapper.findComponent({ ref: 'customChart' }).vm, 'prepareCopy')
|
||||
.returns(URL.createObjectURL(new Blob()))
|
||||
|
||||
await wrapper.findComponent({ name: 'pivotUi' }).setValue({
|
||||
@@ -271,7 +276,7 @@ describe('Pivot.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||
const chartComponent = wrapper.findComponent({ ref: 'customChart' }).vm
|
||||
sinon.stub(chartComponent, 'saveAsSvg')
|
||||
|
||||
await wrapper.vm.saveAsSvg()
|
||||
@@ -309,7 +314,7 @@ describe('Pivot.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||
const chartComponent = wrapper.findComponent({ ref: 'customChart' }).vm
|
||||
sinon.stub(chartComponent, 'saveAsHtml')
|
||||
|
||||
await wrapper.vm.saveAsHtml()
|
||||
@@ -347,7 +352,7 @@ describe('Pivot.vue', () => {
|
||||
}
|
||||
})
|
||||
|
||||
const chartComponent = wrapper.findComponent({ref: "customChart"}).vm
|
||||
const chartComponent = wrapper.findComponent({ ref: 'customChart' }).vm
|
||||
sinon.stub(chartComponent, 'saveAsPng')
|
||||
|
||||
await wrapper.vm.saveAsPng()
|
||||
@@ -376,7 +381,7 @@ describe('Pivot.vue', () => {
|
||||
},
|
||||
attachTo: container,
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -407,7 +412,7 @@ describe('Pivot.vue', () => {
|
||||
},
|
||||
attachTo: container,
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -440,14 +445,16 @@ describe('Pivot.vue', () => {
|
||||
},
|
||||
attachTo: container,
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
await wrapper.vm.saveAsHtml()
|
||||
expect(pivotHelper.getPivotHtml.calledOnce).to.equal(true)
|
||||
const html = pivotHelper.getPivotHtml.returnValues[0]
|
||||
expect(fIo.exportToFile.calledOnceWith(html, 'pivot.html', 'text/html')).to.equal(true)
|
||||
expect(
|
||||
fIo.exportToFile.calledOnceWith(html, 'pivot.html', 'text/html')
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('saveAsPng - standart chart', async () => {
|
||||
@@ -473,7 +480,7 @@ describe('Pivot.vue', () => {
|
||||
},
|
||||
attachTo: container,
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -481,12 +488,18 @@ describe('Pivot.vue', () => {
|
||||
expect(chartHelper.getImageDataUrl.calledOnce).to.equal(true)
|
||||
await chartHelper.getImageDataUrl.returnValues[0]
|
||||
expect(wrapper.emitted().loadingImageCompleted.length).to.equal(1)
|
||||
expect(fIo.downloadFromUrl.calledOnceWith('standat chart data url', 'pivot')).to.equal(true)
|
||||
expect(
|
||||
fIo.downloadFromUrl.calledOnceWith('standat chart data url', 'pivot')
|
||||
).to.equal(true)
|
||||
})
|
||||
|
||||
it('saveAsPng - table', async () => {
|
||||
sinon.stub(pivotHelper, 'getPivotCanvas').returns(document.createElement('canvas'))
|
||||
sinon.stub(HTMLCanvasElement.prototype, 'toDataURL').returns('canvas data url')
|
||||
sinon
|
||||
.stub(pivotHelper, 'getPivotCanvas')
|
||||
.returns(document.createElement('canvas'))
|
||||
sinon
|
||||
.stub(HTMLCanvasElement.prototype, 'toDataURL')
|
||||
.returns('canvas data url')
|
||||
sinon.stub(fIo, 'downloadFromUrl')
|
||||
|
||||
const wrapper = mount(Pivot, {
|
||||
@@ -508,7 +521,7 @@ describe('Pivot.vue', () => {
|
||||
},
|
||||
attachTo: container,
|
||||
global: {
|
||||
stubs: { 'chart': true }
|
||||
stubs: { chart: true }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -516,6 +529,8 @@ describe('Pivot.vue', () => {
|
||||
expect(HTMLCanvasElement.prototype.toDataURL.calledOnce).to.equal(true)
|
||||
await HTMLCanvasElement.prototype.toDataURL.returnValues[0]
|
||||
expect(wrapper.emitted().loadingImageCompleted.length).to.equal(1)
|
||||
expect(fIo.downloadFromUrl.calledOnceWith('canvas data url', 'pivot')).to.equal(true)
|
||||
expect(
|
||||
fIo.downloadFromUrl.calledOnceWith('canvas data url', 'pivot')
|
||||
).to.equal(true)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,10 +4,10 @@ import PivotSortBtn from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/PivotUi
|
||||
|
||||
describe('PivotSortBtn.vue', () => {
|
||||
it('switches order', async () => {
|
||||
const wrapper = shallowMount(PivotSortBtn, {
|
||||
const wrapper = shallowMount(PivotSortBtn, {
|
||||
props: {
|
||||
modelValue: 'key_a_to_z',
|
||||
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e })
|
||||
'onUpdate:modelValue': e => wrapper.setProps({ modelValue: e })
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -7,16 +7,17 @@ describe('PivotUi.vue', () => {
|
||||
const wrapper = mount(PivotUi, {
|
||||
props: {
|
||||
keyNames: ['foo', 'bar'],
|
||||
'onUpdate:modelValue': (e) => wrapper.setProps({ modelValue: e })
|
||||
'onUpdate:modelValue': e => wrapper.setProps({ modelValue: e })
|
||||
}
|
||||
})
|
||||
|
||||
// choose columns
|
||||
await wrapper.findAll('.sqliteviz-select.cols .multiselect__element > span')[0]
|
||||
await wrapper
|
||||
.findAll('.sqliteviz-select.cols .multiselect__element > span')[0]
|
||||
.trigger('click')
|
||||
|
||||
expect(wrapper.emitted().update.length).to.equal(1)
|
||||
|
||||
|
||||
let value = wrapper.props('modelValue')
|
||||
expect(value.rows).to.eql([])
|
||||
expect(value.cols).to.eql(['foo'])
|
||||
@@ -28,7 +29,8 @@ describe('PivotUi.vue', () => {
|
||||
expect(value.vals).to.eql([])
|
||||
|
||||
// choose rows
|
||||
await wrapper.findAll('.sqliteviz-select.rows .multiselect__element > span')[0]
|
||||
await wrapper
|
||||
.findAll('.sqliteviz-select.rows .multiselect__element > span')[0]
|
||||
.trigger('click')
|
||||
|
||||
expect(wrapper.emitted().update.length).to.equal(2)
|
||||
@@ -71,7 +73,8 @@ describe('PivotUi.vue', () => {
|
||||
expect(value.vals).to.eql([])
|
||||
|
||||
// change aggregator
|
||||
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[12]
|
||||
await wrapper
|
||||
.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[12]
|
||||
.trigger('click')
|
||||
|
||||
expect(wrapper.emitted().update.length).to.equal(5)
|
||||
@@ -120,7 +123,8 @@ describe('PivotUi.vue', () => {
|
||||
expect(value.vals).to.eql(['foo', 'bar'])
|
||||
|
||||
// change renderer
|
||||
await wrapper.findAll('.sqliteviz-select.renderer .multiselect__element > span')[13]
|
||||
await wrapper
|
||||
.findAll('.sqliteviz-select.renderer .multiselect__element > span')[13]
|
||||
.trigger('click')
|
||||
|
||||
expect(wrapper.emitted().update.length).to.equal(8)
|
||||
@@ -134,7 +138,8 @@ describe('PivotUi.vue', () => {
|
||||
expect(value.vals).to.eql(['foo', 'bar'])
|
||||
|
||||
// change aggregator again
|
||||
await wrapper.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[3]
|
||||
await wrapper
|
||||
.findAll('.sqliteviz-select.aggregator .multiselect__element > span')[3]
|
||||
.trigger('click')
|
||||
|
||||
expect(wrapper.emitted().update.length).to.equal(9)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { expect } from 'chai'
|
||||
import { _getDataSources, getPivotCanvas, getPivotHtml }
|
||||
from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/pivotHelper'
|
||||
import {
|
||||
_getDataSources,
|
||||
getPivotCanvas,
|
||||
getPivotHtml
|
||||
} from '@/views/Main/Workspace/Tabs/Tab/DataView/Pivot/pivotHelper'
|
||||
|
||||
describe('pivotHelper.js', () => {
|
||||
it('_getDataSources returns data sources', () => {
|
||||
@@ -22,10 +25,10 @@ describe('pivotHelper.js', () => {
|
||||
const pivotData = {
|
||||
rowAttrs: ['y'],
|
||||
colAttrs: ['x', 'z'],
|
||||
getRowKeys () {
|
||||
getRowKeys() {
|
||||
return [[3], [6], [9]]
|
||||
},
|
||||
getColKeys () {
|
||||
getColKeys() {
|
||||
return [
|
||||
[5, 2],
|
||||
[5, 3],
|
||||
@@ -33,9 +36,9 @@ describe('pivotHelper.js', () => {
|
||||
[10, 6]
|
||||
]
|
||||
},
|
||||
getAggregator (row, col) {
|
||||
getAggregator(row, col) {
|
||||
return {
|
||||
value () {
|
||||
value() {
|
||||
return +row + +col[1]
|
||||
}
|
||||
}
|
||||
@@ -61,7 +64,9 @@ describe('pivotHelper.js', () => {
|
||||
child.classList.add('pvtTable')
|
||||
pivotOutput.append(child)
|
||||
|
||||
expect(await getPivotCanvas(pivotOutput)).to.be.instanceof(HTMLCanvasElement)
|
||||
expect(await getPivotCanvas(pivotOutput)).to.be.instanceof(
|
||||
HTMLCanvasElement
|
||||
)
|
||||
})
|
||||
|
||||
it('getPivotHtml returns html with styles', async () => {
|
||||
|
||||
Reference in New Issue
Block a user